comparison lisp/progmodes/bug-reference.el @ 96178:382d88eb4f25

(bug-reference-map): Bind down-mouse-1 rather than mouse-1. (bug-reference-url-format): Autoload safe if string. (bug-reference-bug-regexp): Make space after "bug" optional. (bug-reference-fontify): Save match data.
author Glenn Morris <rgm@gnu.org>
date Sat, 21 Jun 2008 20:13:48 +0000
parents 52b7a8c22af5
children 7734d90cd461
comparison
equal deleted inserted replaced
96177:68c23dc0c0cc 96178:382d88eb4f25
30 ;; Two minor modes are provided. One works on any text in the buffer; 30 ;; Two minor modes are provided. One works on any text in the buffer;
31 ;; the other operates only on comments and strings. 31 ;; the other operates only on comments and strings.
32 32
33 (defvar bug-reference-map 33 (defvar bug-reference-map
34 (let ((map (make-sparse-keymap))) 34 (let ((map (make-sparse-keymap)))
35 (define-key map [mouse-1] 'bug-reference-push-button) 35 (define-key map [down-mouse-1] 'bug-reference-push-button)
36 (define-key map (kbd "C-c RET") 'bug-reference-push-button) 36 (define-key map (kbd "C-c RET") 'bug-reference-push-button)
37 map) 37 map)
38 "Keymap used by bug reference buttons.") 38 "Keymap used by bug reference buttons.")
39 39
40 ;; E.g., "http://gcc.gnu.org/PR%s" 40 ;; E.g., "http://gcc.gnu.org/PR%s"
41 (defvar bug-reference-url-format nil 41 (defvar bug-reference-url-format nil
42 "Format used to turn a bug number into a URL. 42 "Format used to turn a bug number into a URL.
43 The bug number is supplied as a string, so this should have a single %s. 43 The bug number is supplied as a string, so this should have a single %s.
44 There is no default setting for this, it must be set per file.") 44 There is no default setting for this, it must be set per file.")
45 45
46 ;;;###autoload
47 (put 'bug-reference-url-format 'safe-local-variable 'stringp)
48
46 (defconst bug-reference-bug-regexp 49 (defconst bug-reference-bug-regexp
47 "\\(?:[Bb]ug #\\|PR [a-z-+]+/\\)\\([0-9]+\\)" 50 "\\(?:[Bb]ug ?#\\|PR [a-z-+]+/\\)\\([0-9]+\\)"
48 "Regular expression which matches bug references.") 51 "Regular expression which matches bug references.")
49 52
50 (defun bug-reference-set-overlay-properties () 53 (defun bug-reference-set-overlay-properties ()
51 "Set properties of bug reference overlays." 54 "Set properties of bug reference overlays."
52 (put 'bug-reference 'evaporate t) 55 (put 'bug-reference 'evaporate t)
72 (let ((beg-line (progn (goto-char start) (line-beginning-position))) 75 (let ((beg-line (progn (goto-char start) (line-beginning-position)))
73 (end-line (progn (goto-char end) (line-end-position)))) 76 (end-line (progn (goto-char end) (line-end-position))))
74 ;; Remove old overlays. 77 ;; Remove old overlays.
75 (bug-reference-unfontify beg-line end-line) 78 (bug-reference-unfontify beg-line end-line)
76 (goto-char beg-line) 79 (goto-char beg-line)
77 (while (and (< (point) end-line) 80 (save-match-data
78 (re-search-forward bug-reference-bug-regexp end-line 'move)) 81 (while (and (< (point) end-line)
79 (when (or (not bug-reference-prog-mode) 82 (re-search-forward bug-reference-bug-regexp end-line 'move))
80 ;; This tests for both comment and string syntax. 83 (when (or (not bug-reference-prog-mode)
81 (nth 8 (syntax-ppss))) 84 ;; This tests for both comment and string syntax.
82 (let ((overlay (make-overlay (match-beginning 0) (match-end 0) 85 (nth 8 (syntax-ppss)))
83 nil t nil))) 86 (let ((overlay (make-overlay (match-beginning 0) (match-end 0)
84 (overlay-put overlay 'category 'bug-reference) 87 nil t nil)))
85 (overlay-put overlay 'bug-reference-url 88 (overlay-put overlay 'category 'bug-reference)
86 (format bug-reference-url-format 89 (overlay-put overlay 'bug-reference-url
87 (match-string-no-properties 1))))))))) 90 (format bug-reference-url-format
91 (match-string-no-properties 1))))))))))
88 92
89 ;; Taken from button.el. 93 ;; Taken from button.el.
90 (defun bug-reference-push-button (&optional pos use-mouse-action) 94 (defun bug-reference-push-button (&optional pos use-mouse-action)
91 "Open URL corresponding to the bug reference at POS." 95 "Open URL corresponding to the bug reference at POS."
92 (interactive 96 (interactive