diff options
| author | Alan Mackenzie | 2012-02-26 13:02:52 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2012-02-26 13:02:52 +0000 |
| commit | 487915d7385aeef679d9a6f077f319540835da4c (patch) | |
| tree | e0b0d93fcf491e6e9e506a54aaeba7a4b5f22a81 | |
| parent | c2c792605f7ea40e5e9a02c1ee701bcc33db8bdf (diff) | |
| download | emacs-487915d7385aeef679d9a6f077f319540835da4c.tar.gz emacs-487915d7385aeef679d9a6f077f319540835da4c.zip | |
Check there is a font-lock specification before initial fontification.
| -rw-r--r-- | lisp/ChangeLog | 13 | ||||
| -rw-r--r-- | lisp/font-core.el | 10 | ||||
| -rw-r--r-- | lisp/font-lock.el | 28 |
3 files changed, 35 insertions, 16 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a6783b87baa..a79b6307d16 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,16 @@ | |||
| 1 | 2012-02-26 Alan Mackenzie <acm@muc.de> | ||
| 2 | |||
| 3 | Check there is a font-lock specification before doing initial | ||
| 4 | fontification. | ||
| 5 | |||
| 6 | * font-core.el (font-lock-mode): Move the conditional from | ||
| 7 | :after-hook to font-lock-initial-fontify. | ||
| 8 | (font-lock-default-function): Move the check for a specification | ||
| 9 | to font-lock-spec-present. | ||
| 10 | |||
| 11 | * font-lock.el (font-lock-initial-fontify): call ... | ||
| 12 | (font-lock-spec-present): New function. | ||
| 13 | |||
| 1 | 2012-02-26 Jim Blandy <jimb@red-bean.com> | 14 | 2012-02-26 Jim Blandy <jimb@red-bean.com> |
| 2 | 15 | ||
| 3 | * progmodes/gdb-mi.el (gdb-mi-quote): New function. | 16 | * 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 | |||
| 138 | your own function which is called when `font-lock-mode' is toggled via | 138 | your own function which is called when `font-lock-mode' is toggled via |
| 139 | `font-lock-function'. " | 139 | `font-lock-function'. " |
| 140 | nil nil nil | 140 | nil nil nil |
| 141 | :after-hook (if font-lock-mode (font-lock-initial-fontify)) | 141 | :after-hook (font-lock-initial-fontify) |
| 142 | ;; Don't turn on Font Lock mode if we don't have a display (we're running a | 142 | ;; Don't turn on Font Lock mode if we don't have a display (we're running a |
| 143 | ;; batch job) or if the buffer is invisible (the name starts with a space). | 143 | ;; batch job) or if the buffer is invisible (the name starts with a space). |
| 144 | (when (or noninteractive (eq (aref (buffer-name) 0) ?\s)) | 144 | (when (or noninteractive (eq (aref (buffer-name) 0) ?\s)) |
| @@ -192,13 +192,7 @@ this function onto `change-major-mode-hook'." | |||
| 192 | 192 | ||
| 193 | ;; Only do hard work if the mode has specified stuff in | 193 | ;; Only do hard work if the mode has specified stuff in |
| 194 | ;; `font-lock-defaults'. | 194 | ;; `font-lock-defaults'. |
| 195 | (when (or font-lock-defaults | 195 | (when (font-lock-spec-present mode) |
| 196 | (if (boundp 'font-lock-keywords) font-lock-keywords) | ||
| 197 | (and mode | ||
| 198 | (boundp 'font-lock-set-defaults) | ||
| 199 | font-lock-set-defaults | ||
| 200 | font-lock-major-mode | ||
| 201 | (not (eq font-lock-major-mode major-mode)))) | ||
| 202 | (font-lock-mode-internal mode))) | 196 | (font-lock-mode-internal mode))) |
| 203 | 197 | ||
| 204 | (defun turn-on-font-lock () | 198 | (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.") | |||
| 629 | ;; Shut up the byte compiler. | 629 | ;; Shut up the byte compiler. |
| 630 | (defvar font-lock-face-attributes)) ; Obsolete but respected if set. | 630 | (defvar font-lock-face-attributes)) ; Obsolete but respected if set. |
| 631 | 631 | ||
| 632 | (defun font-lock-spec-present (mode) | ||
| 633 | ;; Is there enough specification to do fontification at all? | ||
| 634 | (or font-lock-defaults | ||
| 635 | (if (boundp 'font-lock-keywords) font-lock-keywords) | ||
| 636 | (and mode | ||
| 637 | (boundp 'font-lock-set-defaults) | ||
| 638 | font-lock-set-defaults | ||
| 639 | font-lock-major-mode | ||
| 640 | (not (eq font-lock-major-mode major-mode))))) | ||
| 641 | |||
| 632 | (defun font-lock-initial-fontify () | 642 | (defun font-lock-initial-fontify () |
| 633 | ;; The first fontification after turning the mode on. This must | 643 | ;; The first fontification after turning the mode on. This must |
| 634 | ;; only be called after the mode hooks have been run. | 644 | ;; only be called after the mode hooks have been run. |
| 635 | (let ((max-size (font-lock-value-in-major-mode font-lock-maximum-size))) | 645 | (when (and font-lock-mode |
| 636 | (cond (font-lock-fontified | 646 | (font-lock-spec-present t)) |
| 637 | nil) | 647 | (let ((max-size (font-lock-value-in-major-mode font-lock-maximum-size))) |
| 638 | ((or (null max-size) (> max-size (buffer-size))) | 648 | (cond (font-lock-fontified |
| 639 | (font-lock-fontify-buffer)) | 649 | nil) |
| 640 | (font-lock-verbose | 650 | ((or (null max-size) (> max-size (buffer-size))) |
| 641 | (message "Fontifying %s...buffer size greater than font-lock-maximum-size" | 651 | (font-lock-fontify-buffer)) |
| 642 | (buffer-name)))))) | 652 | (font-lock-verbose |
| 653 | (message "Fontifying %s...buffer size greater than font-lock-maximum-size" | ||
| 654 | (buffer-name))))))) | ||
| 643 | 655 | ||
| 644 | (defun font-lock-mode-internal (arg) | 656 | (defun font-lock-mode-internal (arg) |
| 645 | ;; Turn on Font Lock mode. | 657 | ;; Turn on Font Lock mode. |