Subject: Re: bug#10063: 24.0.91; Making font-lock-mode-hook buffer-local while locally let-bound!

From: Wolfgang Jenkner <[email-masked]>
Date: Mon, 26 Dec 2011 21:02:52 +0100

Tags: patch

Stefan Monnier <[email-masked]> writes:

>> 601:	    ;; Disable support modes, e.g., jit-lock, lazy-lock, etc.
>> 602:	    (font-lock-mode-hook nil)
>> 603:	    (font-lock-support-mode nil)
>
> BTW, these should not be let-bindings but buffer-local bindings.

There's usually a major mode being called a few lines later, so
kill-all-local-variables has already undone those settings before
font-locking happens.

Here's more context from mm-view.el (mm-display-inline-fontify):

#+begin_src emacs-lisp
      (let ((font-lock-verbose nil))
	;; Disable support modes, e.g., jit-lock, lazy-lock, etc.
	(set (make-local-variable 'font-lock-mode-hook) nil)
	(set (make-local-variable 'font-lock-support-mode) nil)
        ...
	(with-demoted-errors
	  (if mode
	      (funcall mode)
            ...)
          ...))
#+end_src

By the way, if you were viewing this in a Gnus article buffer after
having set org-src-fontify-natively to t such a snippet used to be
font-locked like in emacs-lisp mode but now it isn't, for the reason
just given.

The first patch below is relative to emacs bzr trunk and the second
patch relative to gnus git master (No Gnus).

2011-12-26  Wolfgang Jenkner  <[email-masked]>

        * font-lock.el (font-lock-support-mode): Mark it permanent-local.
        (Bug#10063)

2011-12-26  Wolfgang Jenkner  <[email-masked]>

        * mm-view.el (mm-display-inline-fontify): Scrap `font-lock-mode-hook'.
        The 2005-09-06 entry gives disabling support modes as the only reason
        for caring about that variable, but already in NEWS.19 the advice is to
        use `font-lock-support-mode' instead as hook for support functions.

=== modified file 'lisp/font-lock.el'
--- lisp/font-lock.el	2011-11-20 07:30:16 +0000
+++ lisp/font-lock.el	2011-12-26 05:03:58 +0000
@@ -887,6 +887,8 @@
   :version "21.1"
   :group 'font-lock)
 
+(put 'font-lock-support-mode 'permanent-local t)
+
 (defvar fast-lock-mode)
 (defvar lazy-lock-mode)
 (defvar jit-lock-mode)

-- >8 --
Subject: [PATCH] Scrap font-lock-mode-hook.

---
 lisp/mm-view.el |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)

diff --git a/lisp/mm-view.el b/lisp/mm-view.el
index 854ca34..0b3db15 100644
--- a/lisp/mm-view.el
+++ b/lisp/mm-view.el
@@ -566,8 +566,6 @@
 		     (face-property 'default prop) (current-buffer))))
 	      (delete-region ,(point-min-marker) ,(point-max-marker)))))))))
 
-;; Shut up byte-compiler.
-(defvar font-lock-mode-hook)
 (defun mm-display-inline-fontify (handle &optional mode)
   "Insert HANDLE inline fontifying with MODE.
 If MODE is not set, try to find mode automatically."
@@ -602,7 +600,6 @@ If MODE is not set, try to find mode automatically."
       ;; I find font-lock a bit too verbose.
       (let ((font-lock-verbose nil))
 	;; Disable support modes, e.g., jit-lock, lazy-lock, etc.
-	(set (make-local-variable 'font-lock-mode-hook) nil)
 	(set (make-local-variable 'font-lock-support-mode) nil)
         (setq buffer-file-name (mm-handle-filename handle))
         (set (make-local-variable 'enable-local-variables) nil)
-- 
1.7.8