Subject: Re: bug#1744: bug-reference-mode doesn't fontify when called from mode hook

From: Juri Linkov <[email-masked]>
Date: Mon, 12 Jan 2009 02:57:09 +0200

> This reminds me a bit of bug#347. How about something like this:
>
> *** bug-reference.el	5 Jan 2009 03:23:16 -0000	1.6
> --- bug-reference.el	9 Jan 2009 01:47:30 -0000
> ***************
> *** 114,121 ****
>     ""
>     nil
>     (if bug-reference-mode
>         (when bug-reference-url-format
> ! 	(jit-lock-register #'bug-reference-fontify))
>       (jit-lock-unregister #'bug-reference-fontify)
>       (save-restriction
>         (widen)
> --- 114,125 ----
>     ""
>     nil
>     (if bug-reference-mode
> +       (progn
> + 	(let ((enable-local-variables :safe)
> + 	      (enable-local-eval nil))
> + 	  (hack-local-variables))

I think it's a fairly brittle solution to deal with direct hacking
of local variables.  I propose a simpler solution that postpones
checking for non-nil bug-reference-url-format in bug-reference-fontify
that gets called after bug-reference-url-format is set from the
local variables section.  A good side of it is that even when
bug-reference-url-format is still not specified for the moment
of font-locking, bug numbers are still highlighted.  I've verified
that the following patch works also when `mode: bug-reference' is
located before `bug-reference-url-format: "..."' in ChangeLog files:

Index: lisp/progmodes/bug-reference.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/progmodes/bug-reference.el,v
retrieving revision 1.6
diff -u -w -b -r1.6 bug-reference.el
--- lisp/progmodes/bug-reference.el	5 Jan 2009 03:23:16 -0000	1.6
+++ lisp/progmodes/bug-reference.el	12 Jan 2009 00:52:15 -0000
@@ -85,9 +85,11 @@
 	  (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
 			 (format bug-reference-url-format
-				 (match-string-no-properties 1)))))))))
+				   (match-string-no-properties 1))))))))))
 
 ;; Taken from button.el.
 (defun bug-reference-push-button (&optional pos use-mouse-action)
@@ -108,14 +110,12 @@
 
 ;;;###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)
@@ -128,8 +128,7 @@
   ""
   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)

-- 
Juri Linkov
http://www.jurta.org/emacs/