GNU bug report logs - #1744
bug-reference-mode doesn't fontify when called from mode hook

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> jurta.org>

Date: Tue, 30 Dec 2008 23:55:03 UTC

Severity: normal

Done: Juri Linkov <juri <at> jurta.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 1744 in the body.
You can then email your comments to 1744 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#1744; Package emacs. (Tue, 30 Dec 2008 23:55:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Juri Linkov <juri <at> jurta.org>:
New bug report received and forwarded. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Tue, 30 Dec 2008 23:55:04 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: emacs-pretest-bug <at> gnu.org
Subject: bug-reference-mode doesn't fontify when called from mode hook
Date: Wed, 31 Dec 2008 01:44:21 +0200
With the following mode hook:

  (add-hook 'change-log-mode-hook 'bug-reference-mode)

and a file local variable `bug-reference-url-format'
in the ChangeLog file:

;; Local Variables:
;; bug-reference-url-format: "http://debbugs.gnu.org/cgi/bugreport.cgi?bug=%s"
;; End:

bug references never get fontified because `bug-reference-mode' tests
whether a variable `bug-reference-url-format' is non-nil before calling
`(jit-lock-register #'bug-reference-fontify)' in `bug-reference-mode',
and this variable is not yet set because it gets initialized later
in `hack-local-variables' called after `set-auto-mode' in `normal-mode'.

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




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#1744; Package emacs. (Fri, 09 Jan 2009 01:55:04 GMT) Full text and rfc822 format available.

Message #8 received at 1744 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Juri Linkov <juri <at> jurta.org>
Cc: 1744 <at> debbugs.gnu.org
Subject: Re: bug#1744: bug-reference-mode doesn't fontify when called from mode hook
Date: Thu, 08 Jan 2009 20:48:28 -0500
Juri Linkov wrote:

>   (add-hook 'change-log-mode-hook 'bug-reference-mode)
>
> and a file local variable `bug-reference-url-format'
> in the ChangeLog file:
[...]
> bug references never get fontified because `bug-reference-mode' tests
> whether a variable `bug-reference-url-format' is non-nil before calling
> `(jit-lock-register #'bug-reference-fontify)' in `bug-reference-mode',
> and this variable is not yet set because it gets initialized later
> in `hack-local-variables' called after `set-auto-mode' in `normal-mode'.


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))
  	(when bug-reference-url-format
! 	  (jit-lock-register #'bug-reference-fontify)))
      (jit-lock-unregister #'bug-reference-fontify)
      (save-restriction
        (widen)




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#1744; Package emacs. (Mon, 12 Jan 2009 01:05:05 GMT) Full text and rfc822 format available.

Acknowledgement sent to Juri Linkov <juri <at> jurta.org>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Mon, 12 Jan 2009 01:05:05 GMT) Full text and rfc822 format available.

Message #13 received at 1744 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 1744 <at> debbugs.gnu.org
Subject: Re: bug#1744: bug-reference-mode doesn't fontify when called from mode hook
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/




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#1744; Package emacs. (Mon, 12 Jan 2009 01:45:02 GMT) Full text and rfc822 format available.

Message #16 received at 1744 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Juri Linkov <juri <at> jurta.org>
Cc: 1744 <at> debbugs.gnu.org
Subject: Re: bug#1744: bug-reference-mode doesn't fontify when called from mode hook
Date: Sun, 11 Jan 2009 20:36:15 -0500
Juri Linkov wrote:

> I propose a simpler solution

Fine by me.




Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#1744; Package emacs. (Mon, 12 Jan 2009 21:15:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Mon, 12 Jan 2009 21:15:02 GMT) Full text and rfc822 format available.

Message #21 received at 1744 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 1744 <at> debbugs.gnu.org, Juri Linkov <juri <at> jurta.org>
Subject: Re: bug#1744: bug-reference-mode doesn't fontify when called from mode hook
Date: Mon, 12 Jan 2009 16:06:51 -0500
> Juri Linkov wrote:
>> I propose a simpler solution

Yes, that's a good solution, thanks.


        Stefan





Reply sent to Juri Linkov <juri <at> jurta.org>:
You have taken responsibility. (Wed, 14 Jan 2009 00:50:03 GMT) Full text and rfc822 format available.

Notification sent to Juri Linkov <juri <at> jurta.org>:
bug acknowledged by developer. (Wed, 14 Jan 2009 00:50:04 GMT) Full text and rfc822 format available.

Message #26 received at 1744-done <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: 1744-done <at> debbugs.gnu.org
Subject: Re: bug#1744: bug-reference-mode doesn't fontify when called from mode hook
Date: Wed, 14 Jan 2009 02:44:32 +0200
Fixed.

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




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> emacsbugs.donarmstrong.com. (Wed, 11 Feb 2009 15:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 16 years and 189 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.