]> code.delx.au - gnu-emacs/commitdiff
Check there is a font-lock specification before initial fontification.
authorAlan Mackenzie <acm@muc.de>
Sun, 26 Feb 2012 13:02:52 +0000 (13:02 +0000)
committerAlan Mackenzie <acm@muc.de>
Sun, 26 Feb 2012 13:02:52 +0000 (13:02 +0000)
lisp/ChangeLog
lisp/font-core.el
lisp/font-lock.el

index a6783b87baa2048091ef0528303b41c7bd1c84a4..a79b6307d1678abe35fb19c518266dd1a2e33296 100644 (file)
@@ -1,3 +1,16 @@
+2012-02-26  Alan Mackenzie  <acm@muc.de>
+
+       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  <jimb@red-bean.com>
 
        * progmodes/gdb-mi.el (gdb-mi-quote): New function.
index 9b655319bc966f4c30d7ea193640a2ca102a5819..4a88d9739130d595b5ef0ceb6c6bb462dd538168 100644 (file)
@@ -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 ()
index a65a2c94c7dd6bad9439efc73d035b111b8ce88d..7750b30f09666e69f55f44d1493d3526ef6e7e8f 100644 (file)
@@ -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.