Mercurial > emacs
comparison lisp/font-lock.el @ 67738:f2537ba84319
(font-lock-default-fontify-buffer): Try and set-defaults even if font-lock-mode
is non-nil since it may be t without having turned on font-lock-mode-internal.
(font-lock-choose-keywords): Minor optimization.
(font-lock-add-keywords, font-lock-remove-keywords, font-lock-set-defaults):
Don't call make-local-variable on a variable that we know to already be local.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 22 Dec 2005 16:09:32 +0000 |
parents | bce97b32175b |
children | a57273fb71d3 d0eee3282e6b |
comparison
equal
deleted
inserted
replaced
67737:983f4d2eb6a3 | 67738:f2537ba84319 |
---|---|
151 ;; ("\\<\\(four\\|five\\|six\\)\\>" . font-lock-type-face)) | 151 ;; ("\\<\\(four\\|five\\|six\\)\\>" . font-lock-type-face)) |
152 ;; "Default expressions to highlight in Foo mode.") | 152 ;; "Default expressions to highlight in Foo mode.") |
153 ;; | 153 ;; |
154 ;; (add-hook 'foo-mode-hook | 154 ;; (add-hook 'foo-mode-hook |
155 ;; (lambda () | 155 ;; (lambda () |
156 ;; (make-local-variable 'font-lock-defaults) | 156 ;; (set (make-local-variable 'font-lock-defaults) |
157 ;; (setq font-lock-defaults '(foo-font-lock-keywords t)))) | 157 ;; '(foo-font-lock-keywords t)))) |
158 | 158 |
159 ;;; Adding Font Lock support for modes: | 159 ;;; Adding Font Lock support for modes: |
160 | 160 |
161 ;; Of course, it would be better that the mode already supports Font Lock mode. | 161 ;; Of course, it would be better that the mode already supports Font Lock mode. |
162 ;; The package author would do something similar to above. The mode must | 162 ;; The package author would do something similar to above. The mode must |
172 ;; ("\\<\\(quattro\\|cinque\\|sei\\)\\>" . font-lock-type-face)) | 172 ;; ("\\<\\(quattro\\|cinque\\|sei\\)\\>" . font-lock-type-face)) |
173 ;; "Default expressions to highlight in Bar mode.") | 173 ;; "Default expressions to highlight in Bar mode.") |
174 ;; | 174 ;; |
175 ;; and within `bar-mode' there could be: | 175 ;; and within `bar-mode' there could be: |
176 ;; | 176 ;; |
177 ;; (make-local-variable 'font-lock-defaults) | 177 ;; (set (make-local-variable 'font-lock-defaults) |
178 ;; (setq font-lock-defaults '(bar-font-lock-keywords nil t)) | 178 ;; '(bar-font-lock-keywords nil t)) |
179 | 179 |
180 ;; What is fontification for? You might say, "It's to make my code look nice." | 180 ;; What is fontification for? You might say, "It's to make my code look nice." |
181 ;; I think it should be for adding information in the form of cues. These cues | 181 ;; I think it should be for adding information in the form of cues. These cues |
182 ;; should provide you with enough information to both (a) distinguish between | 182 ;; should provide you with enough information to both (a) distinguish between |
183 ;; different items, and (b) identify the item meanings, without having to read | 183 ;; different items, and (b) identify the item meanings, without having to read |
721 (setq font-lock-keywords (if how | 721 (setq font-lock-keywords (if how |
722 (append old keywords) | 722 (append old keywords) |
723 (append keywords old))))) | 723 (append keywords old))))) |
724 ;; If the keywords were compiled before, compile them again. | 724 ;; If the keywords were compiled before, compile them again. |
725 (if was-compiled | 725 (if was-compiled |
726 (set (make-local-variable 'font-lock-keywords) | 726 (setq font-lock-keywords |
727 (font-lock-compile-keywords font-lock-keywords t))))))) | 727 (font-lock-compile-keywords font-lock-keywords t))))))) |
728 | 728 |
729 (defun font-lock-update-removed-keyword-alist (mode keywords how) | 729 (defun font-lock-update-removed-keyword-alist (mode keywords how) |
730 "Update `font-lock-removed-keywords-alist' when adding new KEYWORDS to MODE." | 730 "Update `font-lock-removed-keywords-alist' when adding new KEYWORDS to MODE." |
731 ;; When font-lock is enabled first all keywords in the list | 731 ;; When font-lock is enabled first all keywords in the list |
732 ;; `font-lock-keywords-alist' are added, then all keywords in the | 732 ;; `font-lock-keywords-alist' are added, then all keywords in the |
828 (setq font-lock-keywords | 828 (setq font-lock-keywords |
829 (delete keyword font-lock-keywords))) | 829 (delete keyword font-lock-keywords))) |
830 | 830 |
831 ;; If the keywords were compiled before, compile them again. | 831 ;; If the keywords were compiled before, compile them again. |
832 (if was-compiled | 832 (if was-compiled |
833 (set (make-local-variable 'font-lock-keywords) | 833 (setq font-lock-keywords |
834 (font-lock-compile-keywords font-lock-keywords t))))))) | 834 (font-lock-compile-keywords font-lock-keywords t))))))) |
835 | 835 |
836 ;;; Font Lock Support mode. | 836 ;;; Font Lock Support mode. |
837 | 837 |
838 ;; This is the code used to interface font-lock.el with any of its add-on | 838 ;; This is the code used to interface font-lock.el with any of its add-on |
839 ;; packages, and provide the user interface. Packages that have their own | 839 ;; packages, and provide the user interface. Packages that have their own |
999 font-lock-verbose))) | 999 font-lock-verbose))) |
1000 (with-temp-message | 1000 (with-temp-message |
1001 (when verbose | 1001 (when verbose |
1002 (format "Fontifying %s..." (buffer-name))) | 1002 (format "Fontifying %s..." (buffer-name))) |
1003 ;; Make sure we have the right `font-lock-keywords' etc. | 1003 ;; Make sure we have the right `font-lock-keywords' etc. |
1004 (unless font-lock-mode | 1004 (font-lock-set-defaults) |
1005 (font-lock-set-defaults)) | |
1006 ;; Make sure we fontify etc. in the whole buffer. | 1005 ;; Make sure we fontify etc. in the whole buffer. |
1007 (save-restriction | 1006 (save-restriction |
1008 (widen) | 1007 (widen) |
1009 (condition-case nil | 1008 (condition-case nil |
1010 (save-excursion | 1009 (save-excursion |
1572 A LEVEL of nil is equal to a LEVEL of 0, a LEVEL of t is equal to | 1571 A LEVEL of nil is equal to a LEVEL of 0, a LEVEL of t is equal to |
1573 \(1- (length KEYWORDS))." | 1572 \(1- (length KEYWORDS))." |
1574 (cond ((not (and (listp keywords) (symbolp (car keywords)))) | 1573 (cond ((not (and (listp keywords) (symbolp (car keywords)))) |
1575 keywords) | 1574 keywords) |
1576 ((numberp level) | 1575 ((numberp level) |
1577 (or (nth level keywords) (car (reverse keywords)))) | 1576 (or (nth level keywords) (car (last keywords)))) |
1578 ((eq level t) | 1577 ((eq level t) |
1579 (car (reverse keywords))) | 1578 (car (last keywords))) |
1580 (t | 1579 (t |
1581 (car keywords)))) | 1580 (car keywords)))) |
1582 | 1581 |
1583 (defvar font-lock-set-defaults nil) ; Whether we have set up defaults. | 1582 (defvar font-lock-set-defaults nil) ; Whether we have set up defaults. |
1584 | 1583 |
1640 (setq local (cdr local))) | 1639 (setq local (cdr local))) |
1641 (when removed-keywords | 1640 (when removed-keywords |
1642 (font-lock-remove-keywords nil removed-keywords)) | 1641 (font-lock-remove-keywords nil removed-keywords)) |
1643 ;; Now compile the keywords. | 1642 ;; Now compile the keywords. |
1644 (unless (eq (car font-lock-keywords) t) | 1643 (unless (eq (car font-lock-keywords) t) |
1645 (set (make-local-variable 'font-lock-keywords) | 1644 (setq font-lock-keywords |
1646 (font-lock-compile-keywords font-lock-keywords t)))))) | 1645 (font-lock-compile-keywords font-lock-keywords t)))))) |
1647 | 1646 |
1648 ;;; Colour etc. support. | 1647 ;;; Colour etc. support. |
1649 | 1648 |
1650 ;; Note that `defface' will not overwrite any faces declared above via | 1649 ;; Note that `defface' will not overwrite any faces declared above via |
1651 ;; `custom-declare-face'. | 1650 ;; `custom-declare-face'. |