From: Alan Mackenzie Date: Sun, 26 Feb 2012 13:02:52 +0000 (+0000) Subject: Check there is a font-lock specification before initial fontification. X-Git-Tag: emacs-pretest-24.0.94~4 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=487915d7385aeef679d9a6f077f319540835da4c;p=emacs.git Check there is a font-lock specification before initial fontification. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a6783b87baa..a79b6307d16 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,16 @@ +2012-02-26 Alan Mackenzie + + Check there is a font-lock specification before doing initial + fontification. + + * font-core.el (font-lock-mode): Move the conditional from + :after-hook to font-lock-initial-fontify. + (font-lock-default-function): Move the check for a specification + to font-lock-spec-present. + + * font-lock.el (font-lock-initial-fontify): call ... + (font-lock-spec-present): New function. + 2012-02-26 Jim Blandy * progmodes/gdb-mi.el (gdb-mi-quote): New function. diff --git a/lisp/font-core.el b/lisp/font-core.el index 9b655319bc9..4a88d973913 100644 --- a/lisp/font-core.el +++ b/lisp/font-core.el @@ -138,7 +138,7 @@ The above is the default behavior of `font-lock-mode'; you may specify your own function which is called when `font-lock-mode' is toggled via `font-lock-function'. " nil nil nil - :after-hook (if font-lock-mode (font-lock-initial-fontify)) + :after-hook (font-lock-initial-fontify) ;; Don't turn on Font Lock mode if we don't have a display (we're running a ;; batch job) or if the buffer is invisible (the name starts with a space). (when (or noninteractive (eq (aref (buffer-name) 0) ?\s)) @@ -192,13 +192,7 @@ this function onto `change-major-mode-hook'." ;; Only do hard work if the mode has specified stuff in ;; `font-lock-defaults'. - (when (or font-lock-defaults - (if (boundp 'font-lock-keywords) font-lock-keywords) - (and mode - (boundp 'font-lock-set-defaults) - font-lock-set-defaults - font-lock-major-mode - (not (eq font-lock-major-mode major-mode)))) + (when (font-lock-spec-present mode) (font-lock-mode-internal mode))) (defun turn-on-font-lock () diff --git a/lisp/font-lock.el b/lisp/font-lock.el index a65a2c94c7d..7750b30f096 100644 --- a/lisp/font-lock.el +++ b/lisp/font-lock.el @@ -629,17 +629,29 @@ Major/minor modes can set this variable if they know which option applies.") ;; Shut up the byte compiler. (defvar font-lock-face-attributes)) ; Obsolete but respected if set. +(defun font-lock-spec-present (mode) + ;; Is there enough specification to do fontification at all? + (or font-lock-defaults + (if (boundp 'font-lock-keywords) font-lock-keywords) + (and mode + (boundp 'font-lock-set-defaults) + font-lock-set-defaults + font-lock-major-mode + (not (eq font-lock-major-mode major-mode))))) + (defun font-lock-initial-fontify () ;; The first fontification after turning the mode on. This must ;; only be called after the mode hooks have been run. - (let ((max-size (font-lock-value-in-major-mode font-lock-maximum-size))) - (cond (font-lock-fontified - nil) - ((or (null max-size) (> max-size (buffer-size))) - (font-lock-fontify-buffer)) - (font-lock-verbose - (message "Fontifying %s...buffer size greater than font-lock-maximum-size" - (buffer-name)))))) + (when (and font-lock-mode + (font-lock-spec-present t)) + (let ((max-size (font-lock-value-in-major-mode font-lock-maximum-size))) + (cond (font-lock-fontified + nil) + ((or (null max-size) (> max-size (buffer-size))) + (font-lock-fontify-buffer)) + (font-lock-verbose + (message "Fontifying %s...buffer size greater than font-lock-maximum-size" + (buffer-name))))))) (defun font-lock-mode-internal (arg) ;; Turn on Font Lock mode.