Mercurial > hg > xemacs-beta
comparison lisp/font-lock.el @ 219:262b8bb4a523 r20-4b8
Import from CVS: tag r20-4b8
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:09:35 +0200 |
parents | d44af0c54775 |
children | 6c0ae1f9357f |
comparison
equal
deleted
inserted
replaced
218:c9f226976f56 | 219:262b8bb4a523 |
---|---|
8 ;; Minimally merged with FSF 19.34 by Barry Warsaw <bwarsaw@python.org> | 8 ;; Minimally merged with FSF 19.34 by Barry Warsaw <bwarsaw@python.org> |
9 ;; Then (partially) synched with FSF 19.30, leading to: | 9 ;; Then (partially) synched with FSF 19.30, leading to: |
10 ;; Next Author: RMS | 10 ;; Next Author: RMS |
11 ;; Next Author: Simon Marshall <simon@gnu.ai.mit.edu> | 11 ;; Next Author: Simon Marshall <simon@gnu.ai.mit.edu> |
12 ;; Latest XEmacs Author: Ben Wing | 12 ;; Latest XEmacs Author: Ben Wing |
13 ;; Maintainer: XEmacs Development Team (sigh :-( ) | 13 ;; Maintainer: XEmacs Development Team |
14 ;; Keywords: languages, faces | 14 ;; Keywords: languages, faces |
15 | 15 |
16 ;; This file is part of XEmacs. | 16 ;; This file is part of XEmacs. |
17 | 17 |
18 ;; XEmacs is free software; you can redistribute it and/or modify it | 18 ;; XEmacs is free software; you can redistribute it and/or modify it |
142 | 142 |
143 (require 'fontl-hooks) | 143 (require 'fontl-hooks) |
144 | 144 |
145 ;;;;;;;;;;;;;;;;;;;;;; user variables ;;;;;;;;;;;;;;;;;;;;;; | 145 ;;;;;;;;;;;;;;;;;;;;;; user variables ;;;;;;;;;;;;;;;;;;;;;; |
146 | 146 |
147 (defvar font-lock-verbose t | 147 (defgroup font-lock nil |
148 "Decorate source files with fonts/colors based on syntax. | |
149 Font-lock-mode is a minor mode that causes your comments to be | |
150 displayed in one face, strings in another, reserved words in another, | |
151 documentation strings in another, and so on. | |
152 | |
153 Comments will be displayed in `font-lock-comment-face'. | |
154 Strings will be displayed in `font-lock-string-face'. | |
155 Doc strings will be displayed in `font-lock-doc-string-face'. | |
156 Function and variable names (in their defining forms) will be | |
157 displayed in `font-lock-function-name-face'. | |
158 Reserved words will be displayed in `font-lock-keyword-face'." | |
159 :group 'languages) | |
160 | |
161 (defgroup font-lock-faces nil | |
162 "Faces used by the font-lock package." | |
163 :group 'font-lock | |
164 :group 'faces) | |
165 | |
166 | |
167 (defcustom font-lock-verbose t | |
148 "*If non-nil, means show status messages when fontifying. | 168 "*If non-nil, means show status messages when fontifying. |
149 See also `font-lock-message-threshold'.") | 169 See also `font-lock-message-threshold'." |
150 | 170 :type 'boolean |
151 (defvar font-lock-message-threshold 6000 | 171 :group 'font-lock) |
172 | |
173 (defcustom font-lock-message-threshold 6000 | |
152 "*Minimum size of region being fontified for status messages to appear. | 174 "*Minimum size of region being fontified for status messages to appear. |
153 | 175 |
154 The size is measured in characters. This affects `font-lock-fontify-region' | 176 The size is measured in characters. This affects `font-lock-fontify-region' |
155 but not `font-lock-fontify-buffer'. (In other words, when you first visit | 177 but not `font-lock-fontify-buffer'. (In other words, when you first visit |
156 a file and it gets fontified, you will see status messages no matter what | 178 a file and it gets fontified, you will see status messages no matter what |
157 size the file is. However, if you do something else like paste a | 179 size the file is. However, if you do something else like paste a |
158 chunk of text or revert a buffer, you will see status messages only if the | 180 chunk of text or revert a buffer, you will see status messages only if the |
159 changed region is large enough.) | 181 changed region is large enough.) |
160 | 182 |
161 Note that setting `font-lock-verbose' to nil disables the status | 183 Note that setting `font-lock-verbose' to nil disables the status |
162 messages entirely.") | 184 messages entirely." |
185 :type 'integer | |
186 :group 'font-lock) | |
163 | 187 |
164 ;;;###autoload | 188 ;;;###autoload |
165 (defvar font-lock-auto-fontify t | 189 (defcustom font-lock-auto-fontify t |
166 "*Whether font-lock should automatically fontify files as they're loaded. | 190 "*Whether font-lock should automatically fontify files as they're loaded. |
167 This will only happen if font-lock has fontifying keywords for the major | 191 This will only happen if font-lock has fontifying keywords for the major |
168 mode of the file. You can get finer-grained control over auto-fontification | 192 mode of the file. You can get finer-grained control over auto-fontification |
169 by using this variable in combination with `font-lock-mode-enable-list' or | 193 by using this variable in combination with `font-lock-mode-enable-list' or |
170 `font-lock-mode-disable-list'.") | 194 `font-lock-mode-disable-list'." |
195 :type 'boolean | |
196 :group 'font-lock) | |
171 | 197 |
172 ;;;###autoload | 198 ;;;###autoload |
173 (defvar font-lock-mode-enable-list nil | 199 (defcustom font-lock-mode-enable-list nil |
174 "*List of modes to auto-fontify, if `font-lock-auto-fontify' is nil.") | 200 "*List of modes to auto-fontify, if `font-lock-auto-fontify' is nil." |
201 :type '(repeat (symbol :tag "Mode")) | |
202 :group 'font-lock) | |
175 | 203 |
176 ;;;###autoload | 204 ;;;###autoload |
177 (defvar font-lock-mode-disable-list nil | 205 (defcustom font-lock-mode-disable-list nil |
178 "*List of modes not to auto-fontify, if `font-lock-auto-fontify' is t.") | 206 "*List of modes not to auto-fontify, if `font-lock-auto-fontify' is t." |
207 :type '(repeat (symbol :tag "Mode")) | |
208 :group 'font-lock) | |
179 | 209 |
180 ;;;###autoload | 210 ;;;###autoload |
181 (defvar font-lock-use-colors '(color) | 211 (defcustom font-lock-use-colors '(color) |
182 "*Specification for when Font Lock will set up color defaults. | 212 "*Specification for when Font Lock will set up color defaults. |
183 Normally this should be '(color), meaning that Font Lock will set up | 213 Normally this should be '(color), meaning that Font Lock will set up |
184 color defaults that are only used on color displays. Set this to nil | 214 color defaults that are only used on color displays. Set this to nil |
185 if you don't want Font Lock to set up color defaults at all. This | 215 if you don't want Font Lock to set up color defaults at all. This |
186 should be one of | 216 should be one of |
196 that Font Lock specifies, regardless of whether you specify the face | 226 that Font Lock specifies, regardless of whether you specify the face |
197 values before or after loading Font Lock.) | 227 values before or after loading Font Lock.) |
198 | 228 |
199 See also `font-lock-use-fonts'. If you want more control over the faces | 229 See also `font-lock-use-fonts'. If you want more control over the faces |
200 used for fontification, see the documentation of `font-lock-mode' for | 230 used for fontification, see the documentation of `font-lock-mode' for |
201 how to do it.") | 231 how to do it." |
232 ;; Hard to do right. | |
233 :type 'sexp | |
234 :group 'font-lock) | |
202 | 235 |
203 ;;;###autoload | 236 ;;;###autoload |
204 (defvar font-lock-use-fonts '(or (mono) (grayscale)) | 237 (defcustom font-lock-use-fonts '(or (mono) (grayscale)) |
205 "*Specification for when Font Lock will set up non-color defaults. | 238 "*Specification for when Font Lock will set up non-color defaults. |
206 | 239 |
207 Normally this should be '(or (mono) (grayscale)), meaning that Font | 240 Normally this should be '(or (mono) (grayscale)), meaning that Font |
208 Lock will set up non-color defaults that are only used on either mono | 241 Lock will set up non-color defaults that are only used on either mono |
209 or grayscale displays. Set this to nil if you don't want Font Lock to | 242 or grayscale displays. Set this to nil if you don't want Font Lock to |
220 that Font Lock specifies, regardless of whether you specify the face | 253 that Font Lock specifies, regardless of whether you specify the face |
221 values before or after loading Font Lock.) | 254 values before or after loading Font Lock.) |
222 | 255 |
223 See also `font-lock-use-colors'. If you want more control over the faces | 256 See also `font-lock-use-colors'. If you want more control over the faces |
224 used for fontification, see the documentation of `font-lock-mode' for | 257 used for fontification, see the documentation of `font-lock-mode' for |
225 how to do it.") | 258 how to do it." |
259 :type 'sexp | |
260 :group 'font-lock) | |
226 | 261 |
227 ;;;###autoload | 262 ;;;###autoload |
228 (defvar font-lock-maximum-decoration nil | 263 (defcustom font-lock-maximum-decoration t |
229 "*If non-nil, the maximum decoration level for fontifying. | 264 "*If non-nil, the maximum decoration level for fontifying. |
230 If nil, use the minimum decoration (equivalent to level 0). | 265 If nil, use the minimum decoration (equivalent to level 0). |
231 If t, use the maximum decoration available. | 266 If t, use the maximum decoration available. |
232 If a number, use that level of decoration (or if not available the maximum). | 267 If a number, use that level of decoration (or if not available the maximum). |
233 If a list, each element should be a cons pair of the form (MAJOR-MODE . LEVEL), | 268 If a list, each element should be a cons pair of the form (MAJOR-MODE . LEVEL), |
234 where MAJOR-MODE is a symbol or t (meaning the default). For example: | 269 where MAJOR-MODE is a symbol or t (meaning the default). For example: |
235 ((c++-mode . 2) (c-mode . t) (t . 1)) | 270 ((c++-mode . 2) (c-mode . t) (t . 1)) |
236 means use level 2 decoration for buffers in `c++-mode', the maximum decoration | 271 means use level 2 decoration for buffers in `c++-mode', the maximum decoration |
237 available for buffers in `c-mode', and level 1 decoration otherwise.") | 272 available for buffers in `c-mode', and level 1 decoration otherwise." |
273 :type '(choice (const :tag "default" nil) | |
274 (const :tag "maximum" t) | |
275 (integer :tag "level" 1) | |
276 (repeat :menu-tag "mode specific" :tag "mode specific" | |
277 :value ((t . t)) | |
278 (cons :tag "Instance" | |
279 (radio :tag "Mode" | |
280 (const :tag "all" t) | |
281 (symbol :tag "name")) | |
282 (radio :tag "Decoration" | |
283 (const :tag "default" nil) | |
284 (const :tag "maximum" t) | |
285 (integer :tag "level" 1))))) | |
286 :group 'font-lock) | |
238 | 287 |
239 ;;;###autoload | 288 ;;;###autoload |
240 (define-obsolete-variable-alias 'font-lock-use-maximal-decoration | 289 (define-obsolete-variable-alias 'font-lock-use-maximal-decoration |
241 'font-lock-maximum-decoration) | 290 'font-lock-maximum-decoration) |
242 | 291 |
243 ;;;###autoload | 292 ;;;###autoload |
244 (defvar font-lock-maximum-size (* 250 1024) | 293 (defcustom font-lock-maximum-size (* 250 1024) |
245 "*If non-nil, the maximum size for buffers for fontifying. | 294 "*If non-nil, the maximum size for buffers for fontifying. |
246 Only buffers less than this can be fontified when Font Lock mode is turned on. | 295 Only buffers less than this can be fontified when Font Lock mode is turned on. |
247 If nil, means size is irrelevant. | 296 If nil, means size is irrelevant. |
248 If a list, each element should be a cons pair of the form (MAJOR-MODE . SIZE), | 297 If a list, each element should be a cons pair of the form (MAJOR-MODE . SIZE), |
249 where MAJOR-MODE is a symbol or t (meaning the default). For example: | 298 where MAJOR-MODE is a symbol or t (meaning the default). For example: |
250 ((c++-mode . 256000) (c-mode . 256000) (rmail-mode . 1048576)) | 299 ((c++-mode . 256000) (c-mode . 256000) (rmail-mode . 1048576)) |
251 means that the maximum size is 250K for buffers in `c++-mode' or `c-mode', one | 300 means that the maximum size is 250K for buffers in `c++-mode' or `c-mode', one |
252 megabyte for buffers in `rmail-mode', and size is irrelevant otherwise.") | 301 megabyte for buffers in `rmail-mode', and size is irrelevant otherwise." |
302 :type '(choice (const :tag "none" nil) | |
303 (integer :tag "size") | |
304 (repeat :menu-tag "mode specific" :tag "mode specific" | |
305 :value ((t . nil)) | |
306 (cons :tag "Instance" | |
307 (radio :tag "Mode" | |
308 (const :tag "all" t) | |
309 (symbol :tag "name")) | |
310 (radio :tag "Size" | |
311 (const :tag "none" nil) | |
312 (integer :tag "size"))))) | |
313 :group 'font-lock) | |
314 | |
253 | 315 |
254 ;; Fontification variables: | 316 ;; Fontification variables: |
255 | 317 |
256 ;;;###autoload | 318 ;;;###autoload |
257 (defvar font-lock-keywords nil | 319 (defvar font-lock-keywords nil |
258 "*A list of the keywords to highlight. | 320 "A list of the keywords to highlight. |
259 Each element should be of the form: | 321 Each element should be of the form: |
260 | 322 |
261 MATCHER | 323 MATCHER |
262 (MATCHER . MATCH) | 324 (MATCHER . MATCH) |
263 (MATCHER . FACENAME) | 325 (MATCHER . FACENAME) |
448 "Function or functions to run on entry to font-lock-mode.") | 510 "Function or functions to run on entry to font-lock-mode.") |
449 | 511 |
450 ; whether font-lock-set-defaults has already been run. | 512 ; whether font-lock-set-defaults has already been run. |
451 (defvar font-lock-defaults-computed nil) | 513 (defvar font-lock-defaults-computed nil) |
452 (make-variable-buffer-local 'font-lock-defaults-computed) | 514 (make-variable-buffer-local 'font-lock-defaults-computed) |
515 | |
516 | |
517 ;;; Initialization of faces. | |
453 | 518 |
454 ;; #### barf gag retch. Horrid FSF lossage that we need to | 519 ;; #### barf gag retch. Horrid FSF lossage that we need to |
455 ;; keep around for compatibility with font-lock-keywords that | 520 ;; keep around for compatibility with font-lock-keywords that |
456 ;; forget to properly quote their faces. | 521 ;; forget to properly quote their faces. |
457 (defvar font-lock-comment-face 'font-lock-comment-face | 522 (defvar font-lock-comment-face 'font-lock-comment-face |
470 "Don't even think of using this.") | 535 "Don't even think of using this.") |
471 (defvar font-lock-reference-face 'font-lock-reference-face | 536 (defvar font-lock-reference-face 'font-lock-reference-face |
472 "Don't even think of using this.") | 537 "Don't even think of using this.") |
473 (defvar font-lock-preprocessor-face 'font-lock-preprocessor-face | 538 (defvar font-lock-preprocessor-face 'font-lock-preprocessor-face |
474 "Don't even think of using this.") | 539 "Don't even think of using this.") |
540 | |
541 (defconst font-lock-face-list | |
542 '(font-lock-comment-face | |
543 font-lock-string-face | |
544 font-lock-doc-string-face | |
545 font-lock-keyword-face | |
546 font-lock-function-name-face | |
547 font-lock-variable-name-face | |
548 font-lock-type-face | |
549 font-lock-reference-face | |
550 font-lock-preprocessor-face | |
551 font-lock-warning-face)) | |
552 | |
553 ;; #### There should be an emulation for the old font-lock-use-* | |
554 ;; settings! | |
555 | |
556 (defface font-lock-comment-face | |
557 '((((class color) (background dark)) (:foreground "gray80")) | |
558 (((class color) (background light)) (:foreground "blue4")) | |
559 (((class grayscale) (background light)) | |
560 (:foreground "DimGray" :bold t :italic t)) | |
561 (((class grayscale) (background dark)) | |
562 (:foreground "LightGray" :bold t :italic t)) | |
563 (t (:bold t))) | |
564 "Font Lock mode face used to highlight comments." | |
565 :group 'font-lock-faces) | |
566 | |
567 (defface font-lock-string-face | |
568 '((((class color) (background dark)) (:foreground "tan")) | |
569 (((class color) (background light)) (:foreground "green4")) | |
570 (((class grayscale) (background light)) (:foreground "DimGray" :italic t)) | |
571 (((class grayscale) (background dark)) (:foreground "LightGray" :italic t)) | |
572 (t (:bold t))) | |
573 "Font Lock mode face used to highlight strings." | |
574 :group 'font-lock-faces) | |
575 | |
576 (defface font-lock-doc-string-face | |
577 '((((class color) (background dark)) (:foreground "light coral")) | |
578 (((class color) (background light)) (:foreground "green4")) | |
579 (t (:bold t))) | |
580 "Font Lock mode face used to highlight documentation strings." | |
581 :group 'font-lock-faces) | |
582 | |
583 (defface font-lock-keyword-face | |
584 '((((class color) (background dark)) (:foreground "cyan")) | |
585 (((class color) (background light)) (:foreground "red4")) | |
586 (((class grayscale) (background light)) (:foreground "LightGray" :bold t)) | |
587 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t)) | |
588 (t (:bold t))) | |
589 "Font Lock mode face used to highlight keywords." | |
590 :group 'font-lock-faces) | |
591 | |
592 (defface font-lock-function-name-face | |
593 '((((class color) (background dark)) (:foreground "aquamarine")) | |
594 (((class color) (background light)) (:foreground "brown4")) | |
595 (t (:bold t :underline t))) | |
596 "Font Lock mode face used to highlight function names." | |
597 :group 'font-lock-faces) | |
598 | |
599 (defface font-lock-variable-name-face | |
600 '((((class color) (background dark)) (:foreground "cyan3")) | |
601 (((class color) (background light)) (:foreground "magenta4")) | |
602 (((class grayscale) (background light)) | |
603 (:foreground "Gray90" :bold t :italic t)) | |
604 (((class grayscale) (background dark)) | |
605 (:foreground "DimGray" :bold t :italic t)) | |
606 (t (:underline t))) | |
607 "Font Lock mode face used to highlight variable names." | |
608 :group 'font-lock-faces) | |
609 | |
610 (defface font-lock-type-face | |
611 '((((class color) (background dark)) (:foreground "wheat")) | |
612 (((class color) (background light)) (:foreground "steelblue")) | |
613 (((class grayscale) (background light)) (:foreground "Gray90" :bold t)) | |
614 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t)) | |
615 (t (:bold t))) | |
616 "Font Lock mode face used to highlight types." | |
617 :group 'font-lock-faces) | |
618 | |
619 (defface font-lock-reference-face | |
620 '((((class color) (background dark)) (:foreground "cadetblue2")) | |
621 (((class color) (background light)) (:foreground "red3")) | |
622 (((class grayscale) (background light)) | |
623 (:foreground "LightGray" :bold t :underline t)) | |
624 (((class grayscale) (background dark)) | |
625 (:foreground "Gray50" :bold t :underline t))) | |
626 "Font Lock mode face used to highlight references." | |
627 :group 'font-lock-faces) | |
628 | |
629 ;; #### FSF has font-lock-builtin-face. | |
630 | |
631 (defface font-lock-preprocessor-face | |
632 '((((class color) (background dark)) (:foreground "steelblue1")) | |
633 (((class color) (background black)) (:foreground "blue3")) | |
634 (t (:underline t))) | |
635 "Font Lock Mode face used to highlight preprocessor conditionals." | |
636 :group 'font-lock-faces) | |
637 | |
638 ;; #### Currently unused | |
639 (defface font-lock-warning-face | |
640 '((((class color) (background light)) (:foreground "Red" :bold t)) | |
641 (((class color) (background dark)) (:foreground "Pink" :bold t)) | |
642 (t (:inverse-video t :bold t))) | |
643 "Font Lock mode face used to highlight warnings." | |
644 :group 'font-lock-faces) | |
645 | |
646 (defun font-lock-recompute-variables () | |
647 ;; Is this a Draconian thing to do? | |
648 (mapc #'(lambda (buffer) | |
649 (with-current-buffer buffer | |
650 (font-lock-mode 0) | |
651 (font-lock-set-defaults t))) | |
652 (buffer-list))) | |
653 | |
654 ;; Backwards-compatible crud. | |
655 | |
656 (defun font-lock-reset-all-faces () | |
657 (dolist (face font-lock-face-list) | |
658 (face-spec-set face (get face 'face-defface-spec)))) | |
659 | |
660 (defun font-lock-use-default-fonts () | |
661 "Reset the font-lock faces to a default set of fonts." | |
662 (interactive) | |
663 ;; #### !!!! | |
664 (font-lock-reset-all-faces)) | |
665 | |
666 (defun font-lock-use-default-colors () | |
667 "Reset the font-lock faces to a default set of colors." | |
668 (interactive) | |
669 ;; #### !!!! | |
670 (font-lock-reset-all-faces)) | |
671 | |
672 (defun font-lock-use-default-minimal-decoration () | |
673 "Reset the font-lock patterns to a fast, minimal set of decorations." | |
674 (and font-lock-maximum-decoration | |
675 (setq font-lock-maximum-decoration nil) | |
676 (font-lock-recompute-variables))) | |
677 | |
678 (defun font-lock-use-default-maximal-decoration () | |
679 "Reset the font-lock patterns to a larger set of decorations." | |
680 (and (not (eq t font-lock-maximum-decoration)) | |
681 (setq font-lock-maximum-decoration t) | |
682 (font-lock-recompute-variables))) | |
475 | 683 |
476 | 684 |
477 ;;;;;;;;;;;;;;;;;;;;;; actual code ;;;;;;;;;;;;;;;;;;;;;; | 685 ;;;;;;;;;;;;;;;;;;;;;; actual code ;;;;;;;;;;;;;;;;;;;;;; |
478 | 686 |
479 ;;; To fontify the whole buffer by language syntax, we go through it a | 687 ;;; To fontify the whole buffer by language syntax, we go through it a |
586 (cond (font-lock-fontified | 794 (cond (font-lock-fontified |
587 nil) | 795 nil) |
588 ((or (null maximum-size) (<= (buffer-size) maximum-size)) | 796 ((or (null maximum-size) (<= (buffer-size) maximum-size)) |
589 (font-lock-fontify-buffer)) | 797 (font-lock-fontify-buffer)) |
590 (font-lock-verbose | 798 (font-lock-verbose |
591 (display-message | 799 (lmessage 'command "Fontifying %s... buffer too big." |
592 'command | 800 (buffer-name))))) |
593 (format "Fontifying %s... buffer too big." (buffer-name)))))) | |
594 (font-lock-fontified | 801 (font-lock-fontified |
595 (setq font-lock-fontified nil) | 802 (setq font-lock-fontified nil) |
596 (remove-hook 'before-revert-hook 'font-lock-revert-setup t) | 803 (remove-hook 'before-revert-hook 'font-lock-revert-setup t) |
597 (remove-hook 'after-revert-hook 'font-lock-revert-cleanup t) | 804 (remove-hook 'after-revert-hook 'font-lock-revert-cleanup t) |
598 (font-lock-unfontify-region (point-min) (point-max)) | 805 (font-lock-unfontify-region (point-min) (point-max)) |
649 | 856 |
650 (or was-on ; turn it off if it was off. | 857 (or was-on ; turn it off if it was off. |
651 (let ((font-lock-fontified nil)) ; kludge to prevent defontification | 858 (let ((font-lock-fontified nil)) ; kludge to prevent defontification |
652 (font-lock-mode 0))) | 859 (font-lock-mode 0))) |
653 (set (make-local-variable 'font-lock-fontified) t) | 860 (set (make-local-variable 'font-lock-fontified) t) |
654 (if (and aborted font-lock-verbose) | 861 (when (and aborted font-lock-verbose) |
655 (display-message 'command | 862 (lmessage 'command "Fontifying %s... aborted." (buffer-name)))) |
656 (format "Fontifying %s... aborted." (buffer-name)))) | |
657 ) | |
658 (run-hooks 'font-lock-after-fontify-buffer-hook)) | 863 (run-hooks 'font-lock-after-fontify-buffer-hook)) |
659 | 864 |
660 ;; Fontification functions. | 865 ;; Fontification functions. |
661 | 866 |
662 ;; We first define some defsubsts to encapsulate the way we add | 867 ;; We first define some defsubsts to encapsulate the way we add |
729 ; font-lock-cache-state))) | 934 ; font-lock-cache-state))) |
730 ; (or (nth 4 state) (nth 7 state)))) | 935 ; (or (nth 4 state) (nth 7 state)))) |
731 ; (font-lock-fontify-keywords-region beg end)) | 936 ; (font-lock-fontify-keywords-region beg end)) |
732 | 937 |
733 (defun font-lock-unfontify-region (beg end &optional maybe-loudly) | 938 (defun font-lock-unfontify-region (beg end &optional maybe-loudly) |
734 (if (and maybe-loudly font-lock-verbose | 939 (when (and maybe-loudly font-lock-verbose |
735 (>= (- end beg) font-lock-message-threshold)) | 940 (>= (- end beg) font-lock-message-threshold)) |
736 (display-message | 941 (lmessage 'progress "Fontifying %s..." (buffer-name))) |
737 'progress | |
738 (format "Fontifying %s..." (buffer-name)))) | |
739 (let ((modified (buffer-modified-p)) | 942 (let ((modified (buffer-modified-p)) |
740 (buffer-undo-list t) (inhibit-read-only t) | 943 (buffer-undo-list t) (inhibit-read-only t) |
741 buffer-file-name buffer-file-truename) | 944 buffer-file-name buffer-file-truename) |
742 (font-lock-remove-face beg end) | 945 (font-lock-remove-face beg end) |
743 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil)))) | 946 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil)))) |
982 (defun font-lock-fontify-syntactically-region (start end &optional loudly) | 1185 (defun font-lock-fontify-syntactically-region (start end &optional loudly) |
983 "Put proper face on each string and comment between START and END. | 1186 "Put proper face on each string and comment between START and END. |
984 START should be at the beginning of a line." | 1187 START should be at the beginning of a line." |
985 (if font-lock-keywords-only | 1188 (if font-lock-keywords-only |
986 nil | 1189 nil |
987 (if (and font-lock-verbose | 1190 (when (and font-lock-verbose |
988 (>= (- end start) font-lock-message-threshold)) | 1191 (>= (- end start) font-lock-message-threshold)) |
989 (display-message | 1192 (lmessage 'progress "Fontifying %s... (syntactically...)" |
990 'progress | 1193 (buffer-name))) |
991 (format "Fontifying %s... (syntactically...)" (buffer-name)))) | |
992 (font-lock-unfontify-region start end loudly) | 1194 (font-lock-unfontify-region start end loudly) |
993 (goto-char start) | 1195 (goto-char start) |
994 (if (> end (point-max)) (setq end (point-max))) | 1196 (if (> end (point-max)) (setq end (point-max))) |
995 (syntactically-sectionize | 1197 (syntactically-sectionize |
996 #'(lambda (s e context depth) | 1198 #'(lambda (s e context depth) |
1175 (bufname (buffer-name)) (count 0) | 1377 (bufname (buffer-name)) (count 0) |
1176 keyword matcher highlights) | 1378 keyword matcher highlights) |
1177 ;; | 1379 ;; |
1178 ;; Fontify each item in `font-lock-keywords' from `start' to `end'. | 1380 ;; Fontify each item in `font-lock-keywords' from `start' to `end'. |
1179 (while keywords | 1381 (while keywords |
1180 (if loudly (display-message | 1382 (when loudly (lmessage 'progress "Fontifying %s... (regexps..%s)" |
1181 'progress | 1383 bufname |
1182 (format "Fontifying %s... (regexps..%s)" bufname | 1384 (make-string (setq count (1+ count)) ?.))) |
1183 (make-string (setq count (1+ count)) ?.)))) | |
1184 ;; | 1385 ;; |
1185 ;; Find an occurrence of `matcher' from `start' to `end'. | 1386 ;; Find an occurrence of `matcher' from `start' to `end'. |
1186 (setq keyword (car keywords) matcher (car keyword)) | 1387 (setq keyword (car keywords) matcher (car keyword)) |
1187 (goto-char start) | 1388 (goto-char start) |
1188 (while (and (< (point) end) | 1389 (while (and (< (point) end) |
1201 ;; expressions. | 1402 ;; expressions. |
1202 (and end (goto-char end))) | 1403 (and end (goto-char end))) |
1203 (font-lock-fontify-anchored-keywords (car highlights) end)) | 1404 (font-lock-fontify-anchored-keywords (car highlights) end)) |
1204 (setq highlights (cdr highlights)))) | 1405 (setq highlights (cdr highlights)))) |
1205 (setq keywords (cdr keywords)))) | 1406 (setq keywords (cdr keywords)))) |
1206 (if loudly (display-message | 1407 (if loudly (lmessage 'progress "Fontifying %s... done." (buffer-name))))) |
1207 'progress | |
1208 (format "Fontifying %s... done." (buffer-name)))))) | |
1209 | 1408 |
1210 | 1409 |
1211 ;; Various functions. | 1410 ;; Various functions. |
1212 | 1411 |
1213 ;; Turn off other related packages if they're on. I prefer a hook. --sm. | 1412 ;; Turn off other related packages if they're on. I prefer a hook. --sm. |
1403 ;; defaults not specified at all, so use `beginning-of-defun'. | 1602 ;; defaults not specified at all, so use `beginning-of-defun'. |
1404 (setq font-lock-beginning-of-syntax-function | 1603 (setq font-lock-beginning-of-syntax-function |
1405 'beginning-of-defun))))) | 1604 'beginning-of-defun))))) |
1406 | 1605 |
1407 (setq font-lock-defaults-computed t))) | 1606 (setq font-lock-defaults-computed t))) |
1408 | |
1409 | |
1410 ;;; Initialization of faces. | |
1411 | |
1412 (defconst font-lock-face-list | |
1413 '(font-lock-comment-face | |
1414 font-lock-doc-string-face | |
1415 font-lock-string-face | |
1416 font-lock-keyword-face | |
1417 font-lock-function-name-face | |
1418 font-lock-variable-name-face | |
1419 font-lock-type-face | |
1420 font-lock-reference-face | |
1421 font-lock-preprocessor-face)) | |
1422 | |
1423 (defun font-lock-reset-face (face) | |
1424 "Reset FACE its default state (from the X resource database). | |
1425 Returns whether it is indistinguishable from the default face." | |
1426 (reset-face face) | |
1427 (init-face-from-resources face) | |
1428 (face-differs-from-default-p face)) | |
1429 | |
1430 (defun font-lock-reset-all-faces () | |
1431 (mapcar 'font-lock-reset-face font-lock-face-list)) | |
1432 | |
1433 (defun font-lock-add-fonts (tag-list) | |
1434 ;; Underling comments looks terrible on tty's | |
1435 (if (featurep 'tty) | |
1436 (progn | |
1437 (set-face-underline-p 'font-lock-comment-face nil 'global | |
1438 (append '(tty) tag-list) 'append) | |
1439 (set-face-highlight-p 'font-lock-comment-face t 'global | |
1440 (append '(tty) tag-list) 'append))) | |
1441 (set-face-font 'font-lock-comment-face [italic] 'global tag-list 'append) | |
1442 (set-face-font 'font-lock-string-face [italic] 'global tag-list 'append) | |
1443 (set-face-font 'font-lock-doc-string-face [italic] 'global tag-list 'append) | |
1444 (set-face-font 'font-lock-function-name-face [bold] 'global tag-list 'append) | |
1445 (set-face-font 'font-lock-variable-name-face [bold] 'global tag-list 'append) | |
1446 (set-face-font 'font-lock-keyword-face [bold] 'global tag-list 'append) | |
1447 (set-face-font 'font-lock-preprocessor-face [bold-italic] 'global tag-list | |
1448 'append) | |
1449 (set-face-font 'font-lock-type-face [italic] 'global tag-list 'append) | |
1450 (set-face-font 'font-lock-reference-face [bold] 'global tag-list 'append) | |
1451 nil) | |
1452 | |
1453 (defun font-lock-add-colors (tag-list) | |
1454 (set-face-foreground 'font-lock-comment-face "red" 'global tag-list 'append) | |
1455 ;(set-face-font 'font-lock-comment-face [italic] 'global tag-list 'append) | |
1456 (set-face-foreground 'font-lock-string-face "green4" 'global tag-list | |
1457 'append) | |
1458 (set-face-foreground 'font-lock-string-face "green" 'global tag-list | |
1459 'append) | |
1460 (set-face-foreground 'font-lock-doc-string-face "green4" 'global tag-list | |
1461 'append) | |
1462 (set-face-foreground 'font-lock-doc-string-face "green" 'global tag-list | |
1463 'append) | |
1464 (set-face-foreground 'font-lock-function-name-face "blue3" 'global tag-list | |
1465 'append) | |
1466 (set-face-foreground 'font-lock-function-name-face "blue" 'global tag-list | |
1467 'append) | |
1468 (set-face-foreground 'font-lock-variable-name-face "blue3" 'global tag-list | |
1469 'append) | |
1470 (set-face-foreground 'font-lock-variable-name-face "blue" 'global tag-list | |
1471 'append) | |
1472 (set-face-foreground 'font-lock-reference-face "red3" 'global | |
1473 tag-list 'append) | |
1474 (set-face-foreground 'font-lock-reference-face "red" 'global tag-list | |
1475 'append) | |
1476 (set-face-foreground 'font-lock-keyword-face "orange" 'global tag-list | |
1477 'append) | |
1478 ;(set-face-font 'font-lock-keyword-face [bold] 'global tag-list 'append) | |
1479 (set-face-foreground 'font-lock-preprocessor-face "blue3" 'global tag-list | |
1480 'append) | |
1481 (set-face-foreground 'font-lock-preprocessor-face "blue" 'global tag-list | |
1482 'append) | |
1483 ;(set-face-font 'font-lock-preprocessor-face [bold] 'global tag-list 'append) | |
1484 (set-face-foreground 'font-lock-type-face "#6920ac" 'global tag-list 'append) | |
1485 nil) | |
1486 | |
1487 (defun font-lock-apply-defaults (function tag-list) | |
1488 (if (and (listp tag-list) | |
1489 (eq 'or (car tag-list))) | |
1490 (mapcar #'(lambda (x) | |
1491 (font-lock-apply-defaults function x)) | |
1492 (cdr tag-list)) | |
1493 (if tag-list | |
1494 (if (not (valid-specifier-tag-set-p tag-list)) | |
1495 (warn "Invalid tag set found: %s" tag-list) | |
1496 (funcall function tag-list))))) | |
1497 | |
1498 (defun font-lock-recompute-variables () | |
1499 ;; Is this a Draconian thing to do? | |
1500 (mapcar #'(lambda (buffer) | |
1501 (save-excursion | |
1502 (set-buffer buffer) | |
1503 (font-lock-mode 0) | |
1504 (font-lock-set-defaults t))) | |
1505 (buffer-list))) | |
1506 | |
1507 ;; Backwards-compatible crud. | |
1508 | |
1509 (defun font-lock-use-default-fonts () | |
1510 "Reset the font-lock faces to a default set of fonts." | |
1511 (interactive) | |
1512 (font-lock-reset-all-faces) | |
1513 (font-lock-add-fonts nil)) | |
1514 | |
1515 (defun font-lock-use-default-colors () | |
1516 "Reset the font-lock faces to a default set of colors." | |
1517 (interactive) | |
1518 (font-lock-reset-all-faces) | |
1519 (font-lock-add-colors nil)) | |
1520 | |
1521 (defun font-lock-use-default-minimal-decoration () | |
1522 "Reset the font-lock patterns to a fast, minimal set of decorations." | |
1523 (and font-lock-maximum-decoration | |
1524 (setq font-lock-maximum-decoration nil) | |
1525 (font-lock-recompute-variables))) | |
1526 | |
1527 (defun font-lock-use-default-maximal-decoration () | |
1528 "Reset the font-lock patterns to a larger set of decorations." | |
1529 (and (not (eq t font-lock-maximum-decoration)) | |
1530 (setq font-lock-maximum-decoration t) | |
1531 (font-lock-recompute-variables))) | |
1532 | 1607 |
1533 | 1608 |
1534 ;;;;;;;;;;;;;;;;;;;;;; keywords ;;;;;;;;;;;;;;;;;;;;;; | 1609 ;;;;;;;;;;;;;;;;;;;;;; keywords ;;;;;;;;;;;;;;;;;;;;;; |
1535 | 1610 |
1536 ;;; Various major-mode interfaces. | 1611 ;;; Various major-mode interfaces. |
2586 | 2661 |
2587 ;; Install ourselves: | 2662 ;; Install ourselves: |
2588 | 2663 |
2589 (add-hook 'find-file-hooks 'font-lock-set-defaults t) | 2664 (add-hook 'find-file-hooks 'font-lock-set-defaults t) |
2590 | 2665 |
2591 (make-face 'font-lock-comment-face "Face to use for comments.") | |
2592 (make-face 'font-lock-doc-string-face "Face to use for documentation strings.") | |
2593 (make-face 'font-lock-string-face "Face to use for strings.") | |
2594 (make-face 'font-lock-keyword-face "Face to use for keywords.") | |
2595 (make-face 'font-lock-function-name-face "Face to use for function names.") | |
2596 (make-face 'font-lock-variable-name-face "Face to use for variable names.") | |
2597 (make-face 'font-lock-type-face "Face to use for type names.") | |
2598 (make-face 'font-lock-reference-face "Face to use for reference names.") | |
2599 (make-face 'font-lock-preprocessor-face | |
2600 "Face to use for preprocessor commands.") | |
2601 | |
2602 ;; Backwards compatibility? | |
2603 | |
2604 (if (eq t font-lock-use-colors) | |
2605 (setq font-lock-use-colors '(color))) | |
2606 | |
2607 (if (eq t font-lock-use-fonts) | |
2608 (setq font-lock-use-fonts '(or (mono) (grayscale)))) | |
2609 | |
2610 (font-lock-apply-defaults 'font-lock-add-fonts font-lock-use-fonts) | |
2611 (font-lock-apply-defaults 'font-lock-add-colors font-lock-use-colors) | |
2612 | |
2613 ;;;###autoload | 2666 ;;;###autoload |
2614 (add-minor-mode 'font-lock-mode " Font") | 2667 (add-minor-mode 'font-lock-mode " Font") |
2615 | 2668 |
2616 ;; Provide ourselves: | 2669 ;; Provide ourselves: |
2617 | 2670 |