1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-25 07:28:20 +00:00

Check there is a font-lock specification before initial fontification.

This commit is contained in:
Alan Mackenzie 2012-02-26 13:02:52 +00:00
parent c2c792605f
commit 487915d738
3 changed files with 35 additions and 16 deletions

View 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.

View 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 ()

View 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.