]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/bug-reference.el
Merge from mainline.
[gnu-emacs] / lisp / progmodes / bug-reference.el
index d98604a2afdfead0a581aa9ce462509e23a592ac..4d78047268fe3a2fefbc88322708ba24b3969666 100644 (file)
@@ -1,6 +1,6 @@
 ;; bug-reference.el --- buttonize bug references
 
-;; Copyright (C) 2008 Free Software Foundation, Inc.
+;; Copyright (C) 2008-2011 Free Software Foundation, Inc.
 
 ;; Author: Tom Tromey <tromey@redhat.com>
 ;; Created: 21 Mar 2007
@@ -32,7 +32,7 @@
 
 (defvar bug-reference-map
   (let ((map (make-sparse-keymap)))
-    (define-key map [down-mouse-1] 'bug-reference-push-button)
+    (define-key map [mouse-2] 'bug-reference-push-button)
     (define-key map (kbd "C-c RET") 'bug-reference-push-button)
     map)
   "Keymap used by bug reference buttons.")
 (defvar bug-reference-url-format nil
   "Format used to turn a bug number into a URL.
 The bug number is supplied as a string, so this should have a single %s.
-There is no default setting for this, it must be set per file.")
+This can also be a function designator; it is called without arguments
+ and should return a string.
+It can use `match-string' to get parts matched against
+`bug-reference-bug-regexp', specifically:
+ 1. issue kind (bug, patch, rfe &c)
+ 2. issue number.
+
+There is no default setting for this, it must be set per file.
+If you set it to a symbol in the file Local Variables section,
+you need to add a `bug-reference-url-format' property to it:
+\(put 'my-bug-reference-url-format 'bug-reference-url-format t)
+so that it is considered safe, see `enable-local-variables'.")
 
 ;;;###autoload
-(put 'bug-reference-url-format 'safe-local-variable 'stringp)
+(put 'bug-reference-url-format 'safe-local-variable
+     (lambda (s)
+       (or (stringp s)
+           (and (symbolp s)
+                (get s 'bug-reference-url-format)))))
 
 (defconst bug-reference-bug-regexp
-  "\\(?:[Bb]ug ?#\\|PR [a-z-+]+/\\)\\([0-9]+\\)"
+  "\\([Bb]ug ?#\\|[Pp]atch ?#\\|RFE ?#\\|PR [a-z-+]+/\\)\\([0-9]+\\)"
   "Regular expression which matches bug references.")
 
 (defun bug-reference-set-overlay-properties ()
@@ -77,18 +92,21 @@ There is no default setting for this, it must be set per file.")
       ;; Remove old overlays.
       (bug-reference-unfontify beg-line end-line)
       (goto-char beg-line)
-      (save-match-data
-       (while (and (< (point) end-line)
-                   (re-search-forward bug-reference-bug-regexp end-line 'move))
-         (when (or (not bug-reference-prog-mode)
-                   ;; This tests for both comment and string syntax.
-                   (nth 8 (syntax-ppss)))
-           (let ((overlay (make-overlay (match-beginning 0) (match-end 0)
-                                        nil t nil)))
-             (overlay-put overlay 'category 'bug-reference)
-             (overlay-put overlay 'bug-reference-url
-                          (format bug-reference-url-format
-                                  (match-string-no-properties 1))))))))))
+      (while (and (< (point) end-line)
+                 (re-search-forward bug-reference-bug-regexp end-line 'move))
+       (when (or (not bug-reference-prog-mode)
+                 ;; This tests for both comment and string syntax.
+                 (nth 8 (syntax-ppss)))
+         (let ((overlay (make-overlay (match-beginning 0) (match-end 0)
+                                      nil t nil)))
+           (overlay-put overlay 'category 'bug-reference)
+           ;; Don't put a link if format is undefined
+           (when bug-reference-url-format
+              (overlay-put overlay 'bug-reference-url
+                           (if (stringp bug-reference-url-format)
+                               (format bug-reference-url-format
+                                       (match-string-no-properties 2))
+                             (funcall bug-reference-url-format))))))))))
 
 ;; Taken from button.el.
 (defun bug-reference-push-button (&optional pos use-mouse-action)
@@ -109,14 +127,12 @@ There is no default setting for this, it must be set per file.")
 
 ;;;###autoload
 (define-minor-mode bug-reference-mode
-  "Minor mode to buttonize bugzilla references in the current buffer.
-Requires `bug-reference-url-format' to be set in the buffer."
+  "Minor mode to buttonize bugzilla references in the current buffer."
   nil
   ""
   nil
   (if bug-reference-mode
-      (when bug-reference-url-format
-       (jit-lock-register #'bug-reference-fontify))
+      (jit-lock-register #'bug-reference-fontify)
     (jit-lock-unregister #'bug-reference-fontify)
     (save-restriction
       (widen)
@@ -129,12 +145,10 @@ Requires `bug-reference-url-format' to be set in the buffer."
   ""
   nil
   (if bug-reference-prog-mode
-      (when bug-reference-url-format
-       (jit-lock-register #'bug-reference-fontify))
+      (jit-lock-register #'bug-reference-fontify)
     (jit-lock-unregister #'bug-reference-fontify)
     (save-restriction
       (widen)
       (bug-reference-unfontify (point-min) (point-max)))))
 
-;; arch-tag: b138abce-e5c3-475e-bd58-7afba40387ea
 ;;; bug-reference.el ends here