1 ;;; font-lock.el --- Electric font lock mode
3 ;; Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 1999, 2000
4 ;; Free Software Foundation, Inc.
6 ;; Author: jwz, then rms, then sm
8 ;; Keywords: languages, faces
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; Font Lock mode is a minor mode that causes your comments to be displayed in
30 ;; one face, strings in another, reserved words in another, and so on.
32 ;; Comments will be displayed in `font-lock-comment-face'.
33 ;; Strings will be displayed in `font-lock-string-face'.
34 ;; Regexps are used to display selected patterns in other faces.
36 ;; To make the text you type be fontified, use M-x font-lock-mode RET.
37 ;; When this minor mode is on, the faces of the current line are updated with
38 ;; every insertion or deletion.
40 ;; To turn Font Lock mode on automatically, add this to your ~/.emacs file:
42 ;; (add-hook 'emacs-lisp-mode-hook 'turn-on-font-lock)
44 ;; Or if you want to turn Font Lock mode on in many modes:
46 ;; (global-font-lock-mode t)
48 ;; Fontification for a particular mode may be available in a number of levels
49 ;; of decoration. The higher the level, the more decoration, but the more time
50 ;; it takes to fontify. See the variable `font-lock-maximum-decoration', and
51 ;; also the variable `font-lock-maximum-size'. Support modes for Font Lock
52 ;; mode can be used to speed up Font Lock mode. See `font-lock-support-mode'.
54 ;;; How Font Lock mode fontifies:
56 ;; When Font Lock mode is turned on in a buffer, it (a) fontifies the entire
57 ;; buffer and (b) installs one of its fontification functions on one of the
58 ;; hook variables that are run by Emacs after every buffer change (i.e., an
59 ;; insertion or deletion). Fontification means the replacement of `face' text
60 ;; properties in a given region; Emacs displays text with these `face' text
61 ;; properties appropriately.
63 ;; Fontification normally involves syntactic (i.e., strings and comments) and
64 ;; regexp (i.e., keywords and everything else) passes. There are actually
65 ;; three passes; (a) the syntactic keyword pass, (b) the syntactic pass and (c)
66 ;; the keyword pass. Confused?
68 ;; The syntactic keyword pass places `syntax-table' text properties in the
69 ;; buffer according to the variable `font-lock-syntactic-keywords'. It is
70 ;; necessary because Emacs' syntax table is not powerful enough to describe all
71 ;; the different syntactic constructs required by the sort of people who decide
72 ;; that a single quote can be syntactic or not depending on the time of day.
73 ;; (What sort of person could decide to overload the meaning of a quote?)
74 ;; Obviously the syntactic keyword pass must occur before the syntactic pass.
76 ;; The syntactic pass places `face' text properties in the buffer according to
77 ;; syntactic context, i.e., according to the buffer's syntax table and buffer
78 ;; text's `syntax-table' text properties. It involves using a syntax parsing
79 ;; function to determine the context of different parts of a region of text. A
80 ;; syntax parsing function is necessary because generally strings and/or
81 ;; comments can span lines, and so the context of a given region is not
82 ;; necessarily apparent from the content of that region. Because the keyword
83 ;; pass only works within a given region, it is not generally appropriate for
84 ;; syntactic fontification. This is the first fontification pass that makes
85 ;; changes visible to the user; it fontifies strings and comments.
87 ;; The keyword pass places `face' text properties in the buffer according to
88 ;; the variable `font-lock-keywords'. It involves searching for given regexps
89 ;; (or calling given search functions) within the given region. This is the
90 ;; second fontification pass that makes changes visible to the user; it
91 ;; fontifies language reserved words, etc.
93 ;; Oh, and the answer is, "Yes, obviously just about everything should be done
94 ;; in a single syntactic pass, but the only syntactic parser available
95 ;; understands only strings and comments." Perhaps one day someone will write
96 ;; some syntactic parsers for common languages and a son-of-font-lock.el could
97 ;; use them rather then relying so heavily on the keyword (regexp) pass.
99 ;;; How Font Lock mode supports modes or is supported by modes:
101 ;; Modes that support Font Lock mode do so by defining one or more variables
102 ;; whose values specify the fontification. Font Lock mode knows of these
103 ;; variable names from (a) the buffer local variable `font-lock-defaults', if
104 ;; non-nil, or (b) the global variable `font-lock-defaults-alist', if the major
105 ;; mode has an entry. (Font Lock mode is set up via (a) where a mode's
106 ;; patterns are distributed with the mode's package library, and (b) where a
107 ;; mode's patterns are distributed with font-lock.el itself. An example of (a)
108 ;; is Pascal mode, an example of (b) is Lisp mode. Normally, the mechanism is
109 ;; (a); (b) is used where it is not clear which package library should contain
110 ;; the pattern definitions.) Font Lock mode chooses which variable to use for
111 ;; fontification based on `font-lock-maximum-decoration'.
113 ;; Font Lock mode fontification behaviour can be modified in a number of ways.
114 ;; See the below comments and the comments distributed throughout this file.
116 ;;; Constructing patterns:
118 ;; See the documentation for the variable `font-lock-keywords'.
120 ;; Efficient regexps for use as MATCHERs for `font-lock-keywords' and
121 ;; `font-lock-syntactic-keywords' can be generated via the function
124 ;;; Adding patterns for modes that already support Font Lock:
126 ;; Though Font Lock highlighting patterns already exist for many modes, it's
127 ;; likely there's something that you want fontified that currently isn't, even
128 ;; at the maximum fontification level. You can add highlighting patterns via
129 ;; `font-lock-add-keywords'. For example, say in some C
130 ;; header file you #define the token `and' to expand to `&&', etc., to make
131 ;; your C code almost readable. In your ~/.emacs there could be:
133 ;; (font-lock-add-keywords 'c-mode '("\\<\\(and\\|or\\|not\\)\\>"))
135 ;; Some modes provide specific ways to modify patterns based on the values of
136 ;; other variables. For example, additional C types can be specified via the
137 ;; variable `c-font-lock-extra-types'.
139 ;;; Adding patterns for modes that do not support Font Lock:
141 ;; Not all modes support Font Lock mode. If you (as a user of the mode) add
142 ;; patterns for a new mode, you must define in your ~/.emacs a variable or
143 ;; variables that specify regexp fontification. Then, you should indicate to
144 ;; Font Lock mode, via the mode hook setting `font-lock-defaults', exactly what
145 ;; support is required. For example, say Foo mode should have the following
146 ;; regexps fontified case-sensitively, and comments and strings should not be
147 ;; fontified automagically. In your ~/.emacs there could be:
149 ;; (defvar foo-font-lock-keywords
150 ;; '(("\\<\\(one\\|two\\|three\\)\\>" . font-lock-keyword-face)
151 ;; ("\\<\\(four\\|five\\|six\\)\\>" . font-lock-type-face))
152 ;; "Default expressions to highlight in Foo mode.")
154 ;; (add-hook 'foo-mode-hook
155 ;; (function (lambda ()
156 ;; (make-local-variable 'font-lock-defaults)
157 ;; (setq font-lock-defaults '(foo-font-lock-keywords t)))))
159 ;;; Adding Font Lock support for modes:
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
163 ;; define at the top-level a variable or variables that specify regexp
164 ;; fontification. Then, the mode command should indicate to Font Lock mode,
165 ;; via `font-lock-defaults', exactly what support is required. For example,
166 ;; say Bar mode should have the following regexps fontified case-insensitively,
167 ;; and comments and strings should be fontified automagically. In bar.el there
170 ;; (defvar bar-font-lock-keywords
171 ;; '(("\\<\\(uno\\|due\\|tre\\)\\>" . font-lock-keyword-face)
172 ;; ("\\<\\(quattro\\|cinque\\|sei\\)\\>" . font-lock-type-face))
173 ;; "Default expressions to highlight in Bar mode.")
175 ;; and within `bar-mode' there could be:
177 ;; (make-local-variable 'font-lock-defaults)
178 ;; (setq font-lock-defaults '(bar-font-lock-keywords nil t))
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
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
184 ;; the items and think about it. Therefore, fontification allows you to think
185 ;; less about, say, the structure of code, and more about, say, why the code
186 ;; doesn't work. Or maybe it allows you to think less and drift off to sleep.
188 ;; So, here are my opinions/advice/guidelines:
190 ;; - Highlight conceptual objects, such as function and variable names, and
191 ;; different objects types differently, i.e., (a) and (b) above, highlight
192 ;; function names differently to variable names.
193 ;; - Keep the faces distinct from each other as far as possible.
195 ;; - Use the same face for the same conceptual object, across all modes.
196 ;; i.e., (b) above, all modes that have items that can be thought of as, say,
197 ;; keywords, should be highlighted with the same face, etc.
198 ;; - Make the face attributes fit the concept as far as possible.
199 ;; i.e., function names might be a bold colour such as blue, comments might
200 ;; be a bright colour such as red, character strings might be brown, because,
201 ;; err, strings are brown (that was not the reason, please believe me).
202 ;; - Don't use a non-nil OVERRIDE unless you have a good reason.
203 ;; Only use OVERRIDE for special things that are easy to define, such as the
204 ;; way `...' quotes are treated in strings and comments in Emacs Lisp mode.
205 ;; Don't use it to, say, highlight keywords in commented out code or strings.
210 ;; Define core `font-lock' group.
211 (defgroup font-lock nil
212 "Font Lock mode text highlighting package."
213 :link
'(custom-manual "(emacs)Font Lock")
214 :link
'(custom-manual "(elisp)Font Lock Mode")
217 (defgroup font-lock-highlighting-faces nil
218 "Faces for highlighting text."
222 (defgroup font-lock-extra-types nil
223 "Extra mode-specific type names for highlighting declarations."
226 ;; Define support mode groups here to impose `font-lock' group order.
227 (defgroup fast-lock nil
228 "Font Lock support mode to cache fontification."
229 :link
'(custom-manual "(emacs)Support Modes")
233 (defgroup lazy-lock nil
234 "Font Lock support mode to fontify lazily."
235 :link
'(custom-manual "(emacs)Support Modes")
239 (defgroup jit-lock nil
240 "Font Lock support mode to fontify just-in-time."
241 :link
'(custom-manual "(emacs)Support Modes")
248 (defcustom font-lock-maximum-size
256000
249 "*Maximum size of a buffer for buffer fontification.
250 Only buffers less than this can be fontified when Font Lock mode is turned on.
251 If nil, means size is irrelevant.
252 If a list, each element should be a cons pair of the form (MAJOR-MODE . SIZE),
253 where MAJOR-MODE is a symbol or t (meaning the default). For example:
254 ((c-mode . 256000) (c++-mode . 256000) (rmail-mode . 1048576))
255 means that the maximum size is 250K for buffers in C or C++ modes, one megabyte
256 for buffers in Rmail mode, and size is irrelevant otherwise."
257 :type
'(choice (const :tag
"none" nil
)
258 (integer :tag
"size")
259 (repeat :menu-tag
"mode specific" :tag
"mode specific"
261 (cons :tag
"Instance"
264 (symbol :tag
"name"))
266 (const :tag
"none" nil
)
267 (integer :tag
"size")))))
270 (defcustom font-lock-maximum-decoration t
271 "*Maximum decoration level for fontification.
272 If nil, use the default decoration (typically the minimum available).
273 If t, use the maximum decoration available.
274 If a number, use that level of decoration (or if not available the maximum).
275 If a list, each element should be a cons pair of the form (MAJOR-MODE . LEVEL),
276 where MAJOR-MODE is a symbol or t (meaning the default). For example:
277 ((c-mode . t) (c++-mode . 2) (t . 1))
278 means use the maximum decoration available for buffers in C mode, level 2
279 decoration for buffers in C++ mode, and level 1 decoration otherwise."
280 :type
'(choice (const :tag
"default" nil
)
281 (const :tag
"maximum" t
)
282 (integer :tag
"level" 1)
283 (repeat :menu-tag
"mode specific" :tag
"mode specific"
285 (cons :tag
"Instance"
288 (symbol :tag
"name"))
289 (radio :tag
"Decoration"
290 (const :tag
"default" nil
)
291 (const :tag
"maximum" t
)
292 (integer :tag
"level" 1)))))
295 (defcustom font-lock-verbose
0
296 "*If non-nil, means show status messages for buffer fontification.
297 If a number, only buffers greater than this size have fontification messages."
298 :type
'(choice (const :tag
"never" nil
)
299 (other :tag
"always" t
)
300 (integer :tag
"size"))
304 ;; Originally these variable values were face names such as `bold' etc.
305 ;; Now we create our own faces, but we keep these variables for compatibility
306 ;; and they give users another mechanism for changing face appearance.
307 ;; We now allow a FACENAME in `font-lock-keywords' to be any expression that
308 ;; returns a face. So the easiest thing is to continue using these variables,
309 ;; rather than sometimes evaling FACENAME and sometimes not. sm.
310 (defvar font-lock-comment-face
'font-lock-comment-face
311 "Face name to use for comments.")
313 (defvar font-lock-string-face
'font-lock-string-face
314 "Face name to use for strings.")
316 (defvar font-lock-doc-face
'font-lock-doc-face
317 "Face name to use for documentation.")
319 (defvar font-lock-keyword-face
'font-lock-keyword-face
320 "Face name to use for keywords.")
322 (defvar font-lock-builtin-face
'font-lock-builtin-face
323 "Face name to use for builtins.")
325 (defvar font-lock-function-name-face
'font-lock-function-name-face
326 "Face name to use for function names.")
328 (defvar font-lock-variable-name-face
'font-lock-variable-name-face
329 "Face name to use for variable names.")
331 (defvar font-lock-type-face
'font-lock-type-face
332 "Face name to use for type and class names.")
334 (defvar font-lock-constant-face
'font-lock-constant-face
335 "Face name to use for constant and label names.")
337 (defvar font-lock-warning-face
'font-lock-warning-face
338 "Face name to use for things that should stand out.")
340 (defvar font-lock-reference-face
'font-lock-constant-face
341 "This variable is obsolete. Use `font-lock-constant-face'.")
343 ;; Fontification variables:
345 (defvar font-lock-keywords nil
346 "A list of the keywords to highlight.
347 Each element should have one of these forms:
352 (MATCHER . HIGHLIGHT)
353 (MATCHER HIGHLIGHT ...)
356 where HIGHLIGHT should be either MATCH-HIGHLIGHT or MATCH-ANCHORED.
358 FORM is an expression, whose value should be a keyword element, evaluated when
359 the keyword is (first) used in a buffer. This feature can be used to provide a
360 keyword that can only be generated when Font Lock mode is actually turned on.
362 For highlighting single items, for example each instance of the word \"foo\",
363 typically only MATCH-HIGHLIGHT is required.
364 However, if an item or (typically) items are to be highlighted following the
365 instance of another item (the anchor), for example each instance of the
366 word \"bar\" following the word \"anchor\" then MATCH-ANCHORED may be required.
368 MATCH-HIGHLIGHT should be of the form:
370 (MATCH FACENAME OVERRIDE LAXMATCH)
372 where MATCHER can be either the regexp to search for, or the function name to
373 call to make the search (called with one argument, the limit of the search) and
374 return non-nil if it succeeds (and set `match-data' appropriately).
375 MATCHER regexps can be generated via the function `regexp-opt'. MATCH is
376 the subexpression of MATCHER to be highlighted. FACENAME is an expression
377 whose value is the face name to use. Face default attributes can be
378 modified via \\[customize].
380 OVERRIDE and LAXMATCH are flags. If OVERRIDE is t, existing fontification can
381 be overwritten. If `keep', only parts not already fontified are highlighted.
382 If `prepend' or `append', existing fontification is merged with the new, in
383 which the new or existing fontification, respectively, takes precedence.
384 If LAXMATCH is non-nil, no error is signaled if there is no MATCH in MATCHER.
386 For example, an element of the form highlights (if not already highlighted):
388 \"\\\\\\=<foo\\\\\\=>\" discrete occurrences of \"foo\" in the value of the
389 variable `font-lock-keyword-face'.
390 (\"fu\\\\(bar\\\\)\" . 1) substring \"bar\" within all occurrences of \"fubar\" in
391 the value of `font-lock-keyword-face'.
392 (\"fubar\" . fubar-face) Occurrences of \"fubar\" in the value of `fubar-face'.
393 (\"foo\\\\|bar\" 0 foo-bar-face t)
394 occurrences of either \"foo\" or \"bar\" in the value
395 of `foo-bar-face', even if already highlighted.
396 (fubar-match 1 fubar-face)
397 the first subexpression within all occurrences of
398 whatever the function `fubar-match' finds and matches
399 in the value of `fubar-face'.
401 MATCH-ANCHORED should be of the form:
403 (MATCHER PRE-MATCH-FORM POST-MATCH-FORM MATCH-HIGHLIGHT ...)
405 where MATCHER is a regexp to search for or the function name to call to make
406 the search, as for MATCH-HIGHLIGHT above, but with one exception; see below.
407 PRE-MATCH-FORM and POST-MATCH-FORM are evaluated before the first, and after
408 the last, instance MATCH-ANCHORED's MATCHER is used. Therefore they can be
409 used to initialise before, and cleanup after, MATCHER is used. Typically,
410 PRE-MATCH-FORM is used to move to some position relative to the original
411 MATCHER, before starting with MATCH-ANCHORED's MATCHER. POST-MATCH-FORM might
412 be used to move, before resuming with MATCH-ANCHORED's parent's MATCHER.
414 For example, an element of the form highlights (if not already highlighted):
416 (\"\\\\\\=<anchor\\\\\\=>\" (0 anchor-face) (\"\\\\\\=<item\\\\\\=>\" nil nil (0 item-face)))
418 discrete occurrences of \"anchor\" in the value of `anchor-face', and subsequent
419 discrete occurrences of \"item\" (on the same line) in the value of `item-face'.
420 (Here PRE-MATCH-FORM and POST-MATCH-FORM are nil. Therefore \"item\" is
421 initially searched for starting from the end of the match of \"anchor\", and
422 searching for subsequent instance of \"anchor\" resumes from where searching
423 for \"item\" concluded.)
425 The above-mentioned exception is as follows. The limit of the MATCHER search
426 defaults to the end of the line after PRE-MATCH-FORM is evaluated.
427 However, if PRE-MATCH-FORM returns a position greater than the position after
428 PRE-MATCH-FORM is evaluated, that position is used as the limit of the search.
429 It is generally a bad idea to return a position greater than the end of the
430 line, i.e., cause the MATCHER search to span lines.
432 These regular expressions can match text which spans lines, although
433 it is better to avoid it if possible since updating them while editing
434 text is slower, and it is not guaranteed to be always correct when using
435 support modes like jit-lock or lazy-lock.
437 This variable is set by major modes via the variable `font-lock-defaults'.
438 Be careful when composing regexps for this list; a poorly written pattern can
439 dramatically slow things down!")
441 ;; This variable is used by mode packages that support Font Lock mode by
442 ;; defining their own keywords to use for `font-lock-keywords'. (The mode
443 ;; command should make it buffer-local and set it to provide the set up.)
444 (defvar font-lock-defaults nil
445 "Defaults for Font Lock mode specified by the major mode.
446 Defaults should be of the form:
448 (KEYWORDS KEYWORDS-ONLY CASE-FOLD SYNTAX-ALIST SYNTAX-BEGIN ...)
450 KEYWORDS may be a symbol (a variable or function whose value is the keywords to
451 use for fontification) or a list of symbols. If KEYWORDS-ONLY is non-nil,
452 syntactic fontification (strings and comments) is not performed.
453 If CASE-FOLD is non-nil, the case of the keywords is ignored when fontifying.
454 If SYNTAX-ALIST is non-nil, it should be a list of cons pairs of the form
455 \(CHAR-OR-STRING . STRING) used to set the local Font Lock syntax table, for
456 keyword and syntactic fontification (see `modify-syntax-entry').
458 If SYNTAX-BEGIN is non-nil, it should be a function with no args used to move
459 backwards outside any enclosing syntactic block, for syntactic fontification.
460 Typical values are `beginning-of-line' (i.e., the start of the line is known to
461 be outside a syntactic block), or `beginning-of-defun' for programming modes or
462 `backward-paragraph' for textual modes (i.e., the mode-dependent function is
463 known to move outside a syntactic block). If nil, the beginning of the buffer
464 is used as a position outside of a syntactic block, in the worst case.
466 These item elements are used by Font Lock mode to set the variables
467 `font-lock-keywords', `font-lock-keywords-only',
468 `font-lock-keywords-case-fold-search', `font-lock-syntax-table' and
469 `font-lock-beginning-of-syntax-function', respectively.
471 Further item elements are alists of the form (VARIABLE . VALUE) and are in no
472 particular order. Each VARIABLE is made buffer-local before set to VALUE.
474 Currently, appropriate variables include `font-lock-mark-block-function'.
475 If this is non-nil, it should be a function with no args used to mark any
476 enclosing block of text, for fontification via \\[font-lock-fontify-block].
477 Typical values are `mark-defun' for programming modes or `mark-paragraph' for
478 textual modes (i.e., the mode-dependent function is known to put point and mark
479 around a text block relevant to that mode).
481 Other variables include that for syntactic keyword fontification,
482 `font-lock-syntactic-keywords'
483 and those for buffer-specialised fontification functions,
484 `font-lock-fontify-buffer-function', `font-lock-unfontify-buffer-function',
485 `font-lock-fontify-region-function', `font-lock-unfontify-region-function',
486 `font-lock-inhibit-thing-lock' and `font-lock-maximum-size'.")
488 (make-variable-buffer-local 'font-lock-defaults
)
490 ;; This variable is used where font-lock.el itself supplies the keywords.
491 (defvar font-lock-defaults-alist
492 (let (;; We use `beginning-of-defun', rather than nil, for SYNTAX-BEGIN.
493 ;; Thus the calculation of the cache is usually faster but not
494 ;; infallible, so we risk mis-fontification. sm.
496 '((c-font-lock-keywords c-font-lock-keywords-1
497 c-font-lock-keywords-2 c-font-lock-keywords-3
)
498 nil nil
((?_ .
"w")) beginning-of-defun
499 (font-lock-mark-block-function . mark-defun
)))
501 '((c++-font-lock-keywords c
++-font-lock-keywords-1
502 c
++-font-lock-keywords-2 c
++-font-lock-keywords-3
)
503 nil nil
((?_ .
"w")) beginning-of-defun
504 (font-lock-mark-block-function . mark-defun
)))
506 '((objc-font-lock-keywords objc-font-lock-keywords-1
507 objc-font-lock-keywords-2 objc-font-lock-keywords-3
)
508 nil nil
((?_ .
"w") (?$ .
"w")) nil
509 (font-lock-mark-block-function . mark-defun
)))
511 '((java-font-lock-keywords java-font-lock-keywords-1
512 java-font-lock-keywords-2 java-font-lock-keywords-3
)
513 nil nil
((?_ .
"w") (?$ .
"w")) nil
514 (font-lock-mark-block-function . mark-defun
)))
516 '((lisp-font-lock-keywords
517 lisp-font-lock-keywords-1 lisp-font-lock-keywords-2
)
518 nil nil
(("+-*/.<>=!?$%_&~^:" .
"w")) beginning-of-defun
519 (font-lock-mark-block-function . mark-defun
))))
521 (cons 'c-mode c-mode-defaults
)
522 (cons 'c
++-mode c
++-mode-defaults
)
523 (cons 'objc-mode objc-mode-defaults
)
524 (cons 'java-mode java-mode-defaults
)
525 (cons 'emacs-lisp-mode lisp-mode-defaults
)
526 (cons 'lisp-mode lisp-mode-defaults
)
527 (cons 'lisp-interaction-mode lisp-mode-defaults
)))
528 "Alist of fall-back Font Lock defaults for major modes.
530 This variable should not be used any more.
531 Set the buffer-local `font-lock-keywords' in the major mode instead.
533 Each item should be a list of the form:
535 (MAJOR-MODE . FONT-LOCK-DEFAULTS)
537 where MAJOR-MODE is a symbol and FONT-LOCK-DEFAULTS is a list of default
538 settings. See the variable `font-lock-defaults', which takes precedence.")
539 (make-obsolete-variable 'font-lock-defaults-alist
'font-lock-defaults
)
541 (defvar font-lock-keywords-alist nil
542 "*Alist of `font-lock-keywords' local to a `major-mode'.
543 This is normally set via `font-lock-add-keywords' and
544 `font-lock-remove-keywords'.")
546 (defvar font-lock-removed-keywords-alist nil
547 "*Alist of `font-lock-keywords' removed from `major-mode'.
548 This is normally set via `font-lock-add-keywords' and
549 `font-lock-remove-keywords'.")
551 (defvar font-lock-keywords-only nil
552 "*Non-nil means Font Lock should not fontify comments or strings.
553 This is normally set via `font-lock-defaults'.")
555 (defvar font-lock-keywords-case-fold-search nil
556 "*Non-nil means the patterns in `font-lock-keywords' are case-insensitive.
557 This is normally set via `font-lock-defaults'.")
559 (defvar font-lock-syntactically-fontified
0
560 "Point up to which `font-lock-syntactic-keywords' has been applied.
561 If nil, this is ignored, in which case the syntactic fontification may
562 sometimes be slightly incorrect.")
563 (make-variable-buffer-local 'font-lock-syntactically-fontified
)
565 (defvar font-lock-syntactic-face-function
567 (if (nth 3 state
) font-lock-string-face font-lock-comment-face
))
568 "Function to determine which face to use when fontifying syntactically.
569 The function is called with a single parameter (the state as returned by
570 `parse-partial-sexp' at the beginning of the region to highlight) and
571 should return a face.")
573 (defvar font-lock-syntactic-keywords nil
574 "A list of the syntactic keywords to highlight.
575 Can be the list or the name of a function or variable whose value is the list.
576 See `font-lock-keywords' for a description of the form of this list;
577 the differences are listed below. MATCH-HIGHLIGHT should be of the form:
579 (MATCH SYNTAX OVERRIDE LAXMATCH)
581 where SYNTAX can be a string (as taken by `modify-syntax-entry'), a syntax
582 table, a cons cell (as returned by `string-to-syntax') or an expression whose
583 value is such a form. OVERRIDE cannot be `prepend' or `append'.
585 For example, an element of the form highlights syntactically:
587 (\"\\\\$\\\\(#\\\\)\" 1 \".\")
589 a hash character when following a dollar character, with a SYNTAX of
590 \".\" (meaning punctuation syntax). Assuming that the buffer syntax table does
591 specify hash characters to have comment start syntax, the element will only
592 highlight hash characters that do not follow dollar characters as comments
595 (\"\\\\('\\\\).\\\\('\\\\)\"
599 both single quotes which surround a single character, with a SYNTAX of
600 \"\\\"\" (meaning string quote syntax). Assuming that the buffer syntax table
601 does not specify single quotes to have quote syntax, the element will only
602 highlight single quotes of the form 'c' as strings syntactically.
603 Other forms, such as foo'bar or 'fubar', will not be highlighted as strings.
605 This is normally set via `font-lock-defaults'.")
607 (defvar font-lock-syntax-table nil
608 "Non-nil means use this syntax table for fontifying.
609 If this is nil, the major mode's syntax table is used.
610 This is normally set via `font-lock-defaults'.")
612 ;; If this is nil, we only use the beginning of the buffer if we can't use
613 ;; `font-lock-cache-position' and `font-lock-cache-state'.
614 (defvar font-lock-beginning-of-syntax-function nil
615 "*Non-nil means use this function to move back outside of a syntactic block.
616 When called with no args it should leave point at the beginning of any
617 enclosing syntactic block.
618 If this is nil, the beginning of the buffer is used (in the worst case).
619 This is normally set via `font-lock-defaults'.")
621 (defvar font-lock-mark-block-function nil
622 "*Non-nil means use this function to mark a block of text.
623 When called with no args it should leave point at the beginning of any
624 enclosing textual block and mark at the end.
625 This is normally set via `font-lock-defaults'.")
627 (defvar font-lock-fontify-buffer-function
'font-lock-default-fontify-buffer
628 "Function to use for fontifying the buffer.
629 This is normally set via `font-lock-defaults'.")
631 (defvar font-lock-unfontify-buffer-function
'font-lock-default-unfontify-buffer
632 "Function to use for unfontifying the buffer.
633 This is used when turning off Font Lock mode.
634 This is normally set via `font-lock-defaults'.")
636 (defvar font-lock-fontify-region-function
'font-lock-default-fontify-region
637 "Function to use for fontifying a region.
638 It should take two args, the beginning and end of the region, and an optional
639 third arg VERBOSE. If non-nil, the function should print status messages.
640 This is normally set via `font-lock-defaults'.")
642 (defvar font-lock-unfontify-region-function
'font-lock-default-unfontify-region
643 "Function to use for unfontifying a region.
644 It should take two args, the beginning and end of the region.
645 This is normally set via `font-lock-defaults'.")
647 (defvar font-lock-inhibit-thing-lock nil
648 "List of Font Lock mode related modes that should not be turned on.
649 Currently, valid mode names are `fast-lock-mode', `jit-lock-mode' and
650 `lazy-lock-mode'. This is normally set via `font-lock-defaults'.")
652 (defvar font-lock-multiline
'undecided
653 "Whether font-lock should cater to multiline keywords.
654 If nil, don't try to handle multiline patterns.
655 If t, always handle multiline patterns.
656 If `undecided', don't try to handle multiline patterns until you see one.
657 Major/minor modes can set this variable if they know which option applies.")
659 (defvar font-lock-fontified nil
) ; Whether we have fontified the buffer.
665 ;; We don't do this at the top-level as we only use non-autoloaded macros.
668 ;; Borrowed from lazy-lock.el.
669 ;; We use this to preserve or protect things when modifying text properties.
670 (defmacro save-buffer-state
(varlist &rest body
)
671 "Bind variables according to VARLIST and eval BODY restoring buffer state."
672 `(let* ,(append varlist
673 '((modified (buffer-modified-p)) (buffer-undo-list t
)
674 (inhibit-read-only t
) (inhibit-point-motion-hooks t
)
675 before-change-functions after-change-functions
676 deactivate-mark buffer-file-name buffer-file-truename
))
678 (when (and (not modified
) (buffer-modified-p))
679 (set-buffer-modified-p nil
))))
680 (put 'save-buffer-state
'lisp-indent-function
1)
681 (def-edebug-spec save-buffer-state let
)
683 ;; Shut up the byte compiler.
684 (defvar font-lock-face-attributes
)) ; Obsolete but respected if set.
687 (define-minor-mode font-lock-mode
688 "Toggle Font Lock mode.
689 With arg, turn Font Lock mode on if and only if arg is positive.
690 \(Font Lock is also known as \"syntax highlighting\".)
692 When Font Lock mode is enabled, text is fontified as you type it:
694 - Comments are displayed in `font-lock-comment-face';
695 - Strings are displayed in `font-lock-string-face';
696 - Certain other expressions are displayed in other faces according to the
697 value of the variable `font-lock-keywords'.
699 To customize the faces (colors, fonts, etc.) used by Font Lock for
700 fontifying different parts of buffer text, use \\[customize-face].
702 You can enable Font Lock mode in any major mode automatically by turning on in
703 the major mode's hook. For example, put in your ~/.emacs:
705 (add-hook 'c-mode-hook 'turn-on-font-lock)
707 Alternatively, you can use Global Font Lock mode to automagically turn on Font
708 Lock mode in buffers whose major mode supports it and whose major mode is one
709 of `font-lock-global-modes'. For example, put in your ~/.emacs:
711 (global-font-lock-mode t)
713 There are a number of support modes that may be used to speed up Font Lock mode
714 in various ways, specified via the variable `font-lock-support-mode'. Where
715 major modes support different levels of fontification, you can use the variable
716 `font-lock-maximum-decoration' to specify which level you generally prefer.
717 When you turn Font Lock mode on/off the buffer is fontified/defontified, though
718 fontification occurs only if the buffer is less than `font-lock-maximum-size'.
720 For example, to specify that Font Lock mode use use Lazy Lock mode as a support
721 mode and use maximum levels of fontification, put in your ~/.emacs:
723 (setq font-lock-support-mode 'lazy-lock-mode)
724 (setq font-lock-maximum-decoration t)
726 To add your own highlighting for some major mode, and modify the highlighting
727 selected automatically via the variable `font-lock-maximum-decoration', you can
728 use `font-lock-add-keywords'.
730 To fontify a buffer, without turning on Font Lock mode and regardless of buffer
731 size, you can use \\[font-lock-fontify-buffer].
733 To fontify a block (the function or paragraph containing point, or a number of
734 lines around point), perhaps because modification on the current line caused
735 syntactic change on other lines, you can use \\[font-lock-fontify-block].
737 See the variable `font-lock-defaults-alist' for the Font Lock mode default
738 settings. You can set your own default settings for some mode, by setting a
739 buffer local value for `font-lock-defaults', via its mode hook."
741 ;; Don't turn on Font Lock mode if we don't have a display (we're running a
742 ;; batch job) or if the buffer is invisible (the name starts with a space).
743 (when (or noninteractive
(eq (aref (buffer-name) 0) ?\
))
744 (setq font-lock-mode nil
))
746 ;; Turn on Font Lock mode.
748 (add-hook 'after-change-functions
'font-lock-after-change-function nil t
)
749 (font-lock-set-defaults)
750 (font-lock-turn-on-thing-lock)
751 ;; Fontify the buffer if we have to.
752 (let ((max-size (font-lock-value-in-major-mode font-lock-maximum-size
)))
753 (cond (font-lock-fontified
755 ((or (null max-size
) (> max-size
(buffer-size)))
756 (font-lock-fontify-buffer))
758 (message "Fontifying %s...buffer size greater than font-lock-maximum-size"
760 ;; Turn off Font Lock mode.
761 (unless font-lock-mode
762 (remove-hook 'after-change-functions
'font-lock-after-change-function t
)
763 (font-lock-unfontify-buffer)
764 (font-lock-turn-off-thing-lock)
765 (font-lock-unset-defaults)))
768 (defun turn-on-font-lock ()
769 "Turn on Font Lock mode (only if the terminal can display it)."
770 (unless font-lock-mode
774 (defun font-lock-add-keywords (mode keywords
&optional append
)
775 "Add highlighting KEYWORDS for MODE.
776 MODE should be a symbol, the major mode command name, such as `c-mode'
777 or nil. If nil, highlighting keywords are added for the current buffer.
778 KEYWORDS should be a list; see the variable `font-lock-keywords'.
779 By default they are added at the beginning of the current highlighting list.
780 If optional argument APPEND is `set', they are used to replace the current
781 highlighting list. If APPEND is any other non-nil value, they are added at the
782 end of the current highlighting list.
786 (font-lock-add-keywords 'c-mode
787 '((\"\\\\\\=<\\\\(FIXME\\\\):\" 1 font-lock-warning-face prepend)
788 (\"\\\\\\=<\\\\(and\\\\|or\\\\|not\\\\)\\\\\\=>\" . font-lock-keyword-face)))
790 adds two fontification patterns for C mode, to fontify `FIXME:' words, even in
791 comments, and to fontify `and', `or' and `not' words as keywords.
793 Note that some modes have specialised support for additional patterns, e.g.,
794 see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
795 `objc-font-lock-extra-types' and `java-font-lock-extra-types'."
797 ;; If MODE is non-nil, add the KEYWORDS and APPEND spec to
798 ;; `font-lock-keywords-alist' so `font-lock-set-defaults' uses them.
799 (let ((spec (cons keywords append
)) cell
)
800 (if (setq cell
(assq mode font-lock-keywords-alist
))
802 (setcdr cell
(list spec
))
803 (setcdr cell
(append (cdr cell
) (list spec
))))
804 (push (list mode spec
) font-lock-keywords-alist
)))
805 ;; Make sure that `font-lock-removed-keywords-alist' does not
806 ;; contain the new keywords.
807 (font-lock-update-removed-keyword-alist mode keywords append
))
809 ;; Otherwise set or add the keywords now.
810 (font-lock-set-defaults)
812 (setq font-lock-keywords keywords
)
813 (font-lock-remove-keywords nil keywords
) ;to avoid duplicates
814 (let ((old (if (eq (car-safe font-lock-keywords
) t
)
815 (cdr font-lock-keywords
)
816 font-lock-keywords
)))
817 (setq font-lock-keywords
(if append
818 (append old keywords
)
819 (append keywords old
))))))))
821 (defun font-lock-update-removed-keyword-alist (mode keywords append
)
822 ;; Update `font-lock-removed-keywords-alist' when adding new
825 ;; When font-lock is enabled first all keywords in the list
826 ;; `font-lock-keywords-alist' are added, then all keywords in the
827 ;; list `font-lock-removed-keywords-alist' are removed. If a
828 ;; keyword was once added, removed, and then added again it must be
829 ;; removed from the removed-keywords list. Otherwise the second add
830 ;; will not take effect.
831 (let ((cell (assq mode font-lock-removed-keywords-alist
)))
834 ;; A new set of keywords is defined. Forget all about
835 ;; our old keywords that should be removed.
836 (setq font-lock-removed-keywords-alist
837 (delq cell font-lock-removed-keywords-alist
))
838 ;; Delete all previously removed keywords.
839 (dolist (kword keywords
)
840 (setcdr cell
(delete kword
(cdr cell
))))
841 ;; Delete the mode cell if empty.
842 (if (null (cdr cell
))
843 (setq font-lock-removed-keywords-alist
844 (delq cell font-lock-removed-keywords-alist
)))))))
846 ;; Written by Anders Lindgren <andersl@andersl.com>.
849 ;; (I) The keywords are removed from a major mode.
850 ;; In this case the keyword could be local (i.e. added earlier by
851 ;; `font-lock-add-keywords'), global, or both.
853 ;; (a) In the local case we remove the keywords from the variable
854 ;; `font-lock-keywords-alist'.
856 ;; (b) The actual global keywords are not known at this time.
857 ;; All keywords are added to `font-lock-removed-keywords-alist',
858 ;; when font-lock is enabled those keywords are removed.
860 ;; Note that added keywords are taken out of the list of removed
861 ;; keywords. This ensure correct operation when the same keyword
862 ;; is added and removed several times.
864 ;; (II) The keywords are removed from the current buffer.
866 (defun font-lock-remove-keywords (mode keywords
)
867 "Remove highlighting KEYWORDS for MODE.
869 MODE should be a symbol, the major mode command name, such as `c-mode'
870 or nil. If nil, highlighting keywords are removed for the current buffer."
872 ;; Remove one keyword at the time.
873 (dolist (keyword keywords
)
874 (let ((top-cell (assq mode font-lock-keywords-alist
)))
875 ;; If MODE is non-nil, remove the KEYWORD from
876 ;; `font-lock-keywords-alist'.
878 (dolist (keyword-list-append-pair (cdr top-cell
))
879 ;; `keywords-list-append-pair' is a cons with a list of
880 ;; keywords in the car top-cell and the original append
881 ;; argument in the cdr top-cell.
882 (setcar keyword-list-append-pair
883 (delete keyword
(car keyword-list-append-pair
))))
884 ;; Remove keyword list/append pair when the keyword list
885 ;; is empty and append doesn't specify `set'. (If it
886 ;; should be deleted then previously deleted keywords
887 ;; would appear again.)
888 (let ((cell top-cell
))
890 (if (and (null (car (car (cdr cell
))))
891 (not (eq (cdr (car (cdr cell
))) 'set
)))
892 (setcdr cell
(cdr (cdr cell
)))
893 (setq cell
(cdr cell
)))))
894 ;; Final cleanup, remove major mode cell if last keyword
896 (if (null (cdr top-cell
))
897 (setq font-lock-keywords-alist
898 (delq top-cell font-lock-keywords-alist
))))
899 ;; Remember the keyword in case it is not local.
900 (let ((cell (assq mode font-lock-removed-keywords-alist
)))
902 (unless (member keyword
(cdr cell
))
903 (nconc cell
(list keyword
)))
904 (push (cons mode
(list keyword
))
905 font-lock-removed-keywords-alist
))))))
907 ;; Otherwise remove it immediately.
908 (font-lock-set-defaults)
909 (setq font-lock-keywords
(copy-sequence font-lock-keywords
))
910 (dolist (keyword keywords
)
911 (setq font-lock-keywords
913 ;; The keywords might be compiled.
914 (delete (font-lock-compile-keyword keyword
)
915 font-lock-keywords
)))))))
917 ;;; Global Font Lock mode.
919 ;; A few people have hassled in the past for a way to make it easier to turn on
920 ;; Font Lock mode, without the user needing to know for which modes s/he has to
921 ;; turn it on, perhaps the same way hilit19.el/hl319.el does. I've always
922 ;; balked at that way, as I see it as just re-moulding the same problem in
923 ;; another form. That is; some person would still have to keep track of which
924 ;; modes (which may not even be distributed with Emacs) support Font Lock mode.
925 ;; The list would always be out of date. And that person might have to be me.
929 ;; In a previous discussion the following hack came to mind. It is a gross
930 ;; hack, but it generally works. We use the convention that major modes start
931 ;; by calling the function `kill-all-local-variables', which in turn runs
932 ;; functions on the hook variable `change-major-mode-hook'. We attach our
933 ;; function `font-lock-change-major-mode' to that hook. Of course, when this
934 ;; hook is run, the major mode is in the process of being changed and we do not
935 ;; know what the final major mode will be. So, `font-lock-change-major-mode'
936 ;; only (a) notes the name of the current buffer, and (b) adds our function
937 ;; `turn-on-font-lock-if-enabled' to the hook variables `find-file-hooks' and
938 ;; `post-command-hook' (for buffers that are not visiting files). By the time
939 ;; the functions on the first of these hooks to be run are run, the new major
940 ;; mode is assumed to be in place. This way we get a Font Lock function run
941 ;; when a major mode is turned on, without knowing major modes or their hooks.
943 ;; Naturally this requires that (a) major modes run `kill-all-local-variables',
944 ;; as they are supposed to do, and (b) the major mode is in place after the
945 ;; file is visited or the command that ran `kill-all-local-variables' has
946 ;; finished, whichever the sooner. Arguably, any major mode that does not
947 ;; follow the convension (a) is broken, and I can't think of any reason why (b)
948 ;; would not be met (except `gnudoit' on non-files). However, it is not clean.
950 ;; Probably the cleanest solution is to have each major mode function run some
951 ;; hook, e.g., `major-mode-hook', but maybe implementing that change is
952 ;; impractical. I am personally against making `setq' a macro or be advised,
953 ;; or have a special function such as `set-major-mode', but maybe someone can
954 ;; come up with another solution?
958 ;; Although Global Font Lock mode is a pseudo-mode, I think that the user
959 ;; interface should conform to the usual Emacs convention for modes, i.e., a
960 ;; command to toggle the feature (`global-font-lock-mode') with a variable for
961 ;; finer control of the mode's behaviour (`font-lock-global-modes').
963 ;; The feature should not be enabled by loading font-lock.el, since other
964 ;; mechanisms for turning on Font Lock mode, such as M-x font-lock-mode RET or
965 ;; (add-hook 'c-mode-hook 'turn-on-font-lock), would cause Font Lock mode to be
966 ;; turned on everywhere. That would not be intuitive or informative because
967 ;; loading a file tells you nothing about the feature or how to control it. It
968 ;; would also be contrary to the Principle of Least Surprise. sm.
970 (defcustom font-lock-global-modes t
971 "*Modes for which Font Lock mode is automagically turned on.
972 Global Font Lock mode is controlled by the command `global-font-lock-mode'.
973 If nil, means no modes have Font Lock mode automatically turned on.
974 If t, all modes that support Font Lock mode have it automatically turned on.
975 If a list, it should be a list of `major-mode' symbol names for which Font Lock
976 mode should be automatically turned on. The sense of the list is negated if it
977 begins with `not'. For example:
979 means that Font Lock mode is turned on for buffers in C and C++ modes only."
980 :type
'(choice (const :tag
"none" nil
)
982 (set :menu-tag
"mode specific" :tag
"modes"
984 (const :tag
"Except" not
)
985 (repeat :inline t
(symbol :tag
"mode"))))
988 (defun turn-on-font-lock-if-enabled ()
989 (when (and (or font-lock-defaults
990 (assq major-mode font-lock-defaults-alist
))
991 (or (eq font-lock-global-modes t
)
992 (if (eq (car-safe font-lock-global-modes
) 'not
)
993 (not (memq major-mode
(cdr font-lock-global-modes
)))
994 (memq major-mode font-lock-global-modes
))))
996 (turn-on-font-lock))))
999 (easy-mmode-define-global-mode
1000 global-font-lock-mode font-lock-mode turn-on-font-lock-if-enabled
1001 :extra-args
(dummy))
1003 ;;; End of Global Font Lock mode.
1005 ;;; Font Lock Support mode.
1007 ;; This is the code used to interface font-lock.el with any of its add-on
1008 ;; packages, and provide the user interface. Packages that have their own
1009 ;; local buffer fontification functions (see below) may have to call
1010 ;; `font-lock-after-fontify-buffer' and/or `font-lock-after-unfontify-buffer'
1013 (defcustom font-lock-support-mode
'jit-lock-mode
1014 "*Support mode for Font Lock mode.
1015 Support modes speed up Font Lock mode by being choosy about when fontification
1016 occurs. Known support modes are Fast Lock mode (symbol `fast-lock-mode'),
1017 Lazy Lock mode (symbol `lazy-lock-mode'), and Just-in-time Lock mode (symbol
1018 `jit-lock-mode'. See those modes for more info.
1019 If nil, means support for Font Lock mode is never performed.
1020 If a symbol, use that support mode.
1021 If a list, each element should be of the form (MAJOR-MODE . SUPPORT-MODE),
1022 where MAJOR-MODE is a symbol or t (meaning the default). For example:
1023 ((c-mode . fast-lock-mode) (c++-mode . fast-lock-mode) (t . lazy-lock-mode))
1024 means that Fast Lock mode is used to support Font Lock mode for buffers in C or
1025 C++ modes, and Lazy Lock mode is used to support Font Lock mode otherwise.
1027 The value of this variable is used when Font Lock mode is turned on."
1028 :type
'(choice (const :tag
"none" nil
)
1029 (const :tag
"fast lock" fast-lock-mode
)
1030 (const :tag
"lazy lock" lazy-lock-mode
)
1031 (const :tag
"jit lock" jit-lock-mode
)
1032 (repeat :menu-tag
"mode specific" :tag
"mode specific"
1033 :value
((t . jit-lock-mode
))
1034 (cons :tag
"Instance"
1036 (const :tag
"all" t
)
1037 (symbol :tag
"name"))
1038 (radio :tag
"Support"
1039 (const :tag
"none" nil
)
1040 (const :tag
"fast lock" fast-lock-mode
)
1041 (const :tag
"lazy lock" lazy-lock-mode
)
1042 (const :tag
"JIT lock" jit-lock-mode
)))
1047 (defvar fast-lock-mode nil
)
1048 (defvar lazy-lock-mode nil
)
1049 (defvar jit-lock-mode nil
)
1051 (defun font-lock-turn-on-thing-lock ()
1052 (let ((thing-mode (font-lock-value-in-major-mode font-lock-support-mode
)))
1053 (cond ((eq thing-mode
'fast-lock-mode
)
1055 ((eq thing-mode
'lazy-lock-mode
)
1057 ((eq thing-mode
'jit-lock-mode
)
1058 ;; Prepare for jit-lock
1059 (remove-hook 'after-change-functions
1060 'font-lock-after-change-function t
)
1061 (set (make-local-variable 'font-lock-fontify-buffer-function
)
1062 'jit-lock-refontify
)
1063 ;; Don't fontify eagerly (and don't abort is the buffer is large).
1064 (set (make-local-variable 'font-lock-fontified
) t
)
1066 (jit-lock-register 'font-lock-fontify-region
1067 (not font-lock-keywords-only
))))))
1069 (defun font-lock-turn-off-thing-lock ()
1070 (cond (fast-lock-mode
1071 (fast-lock-mode -
1))
1073 (jit-lock-unregister 'font-lock-fontify-region
)
1074 ;; Reset local vars to the non-jit-lock case.
1075 (kill-local-variable 'font-lock-fontify-buffer-function
))
1077 (lazy-lock-mode -
1))))
1079 (defun font-lock-after-fontify-buffer ()
1080 (cond (fast-lock-mode
1081 (fast-lock-after-fontify-buffer))
1082 ;; Useless now that jit-lock intercepts font-lock-fontify-buffer. -sm
1084 ;; (jit-lock-after-fontify-buffer))
1086 (lazy-lock-after-fontify-buffer))))
1088 (defun font-lock-after-unfontify-buffer ()
1089 (cond (fast-lock-mode
1090 (fast-lock-after-unfontify-buffer))
1091 ;; Useless as well. It's only called when:
1092 ;; - turning off font-lock: it does not matter if we leave spurious
1093 ;; `fontified' text props around since jit-lock-mode is also off.
1094 ;; - font-lock-default-fontify-buffer fails: this is not run
1095 ;; any more anyway. -sm
1098 ;; (jit-lock-after-unfontify-buffer))
1100 (lazy-lock-after-unfontify-buffer))))
1102 ;;; End of Font Lock Support mode.
1104 ;;; Fontification functions.
1106 ;; Rather than the function, e.g., `font-lock-fontify-region' containing the
1107 ;; code to fontify a region, the function runs the function whose name is the
1108 ;; value of the variable, e.g., `font-lock-fontify-region-function'. Normally,
1109 ;; the value of this variable is, e.g., `font-lock-default-fontify-region'
1110 ;; which does contain the code to fontify a region. However, the value of the
1111 ;; variable could be anything and thus, e.g., `font-lock-fontify-region' could
1112 ;; do anything. The indirection of the fontification functions gives major
1113 ;; modes the capability of modifying the way font-lock.el fontifies. Major
1114 ;; modes can modify the values of, e.g., `font-lock-fontify-region-function',
1115 ;; via the variable `font-lock-defaults'.
1117 ;; For example, Rmail mode sets the variable `font-lock-defaults' so that
1118 ;; font-lock.el uses its own function for buffer fontification. This function
1119 ;; makes fontification be on a message-by-message basis and so visiting an
1120 ;; RMAIL file is much faster. A clever implementation of the function might
1121 ;; fontify the headers differently than the message body. (It should, and
1122 ;; correspondingly for Mail mode, but I can't be bothered to do the work. Can
1123 ;; you?) This hints at a more interesting use...
1125 ;; Languages that contain text normally contained in different major modes
1126 ;; could define their own fontification functions that treat text differently
1127 ;; depending on its context. For example, Perl mode could arrange that here
1128 ;; docs are fontified differently than Perl code. Or Yacc mode could fontify
1129 ;; rules one way and C code another. Neat!
1131 ;; A further reason to use the fontification indirection feature is when the
1132 ;; default syntactual fontification, or the default fontification in general,
1133 ;; is not flexible enough for a particular major mode. For example, perhaps
1134 ;; comments are just too hairy for `font-lock-fontify-syntactically-region' to
1135 ;; cope with. You need to write your own version of that function, e.g.,
1136 ;; `hairy-fontify-syntactically-region', and make your own version of
1137 ;; `hairy-fontify-region' call that function before calling
1138 ;; `font-lock-fontify-keywords-region' for the normal regexp fontification
1139 ;; pass. And Hairy mode would set `font-lock-defaults' so that font-lock.el
1140 ;; would call your region fontification function instead of its own. For
1141 ;; example, TeX modes could fontify {\foo ...} and \bar{...} etc. multi-line
1142 ;; directives correctly and cleanly. (It is the same problem as fontifying
1143 ;; multi-line strings and comments; regexps are not appropriate for the job.)
1146 (defun font-lock-fontify-buffer ()
1147 "Fontify the current buffer the way the function `font-lock-mode' would."
1149 (let ((font-lock-verbose (or font-lock-verbose
(interactive-p))))
1150 (funcall font-lock-fontify-buffer-function
)))
1152 (defun font-lock-unfontify-buffer ()
1153 (funcall font-lock-unfontify-buffer-function
))
1155 (defun font-lock-fontify-region (beg end
&optional loudly
)
1156 (funcall font-lock-fontify-region-function beg end loudly
))
1158 (defun font-lock-unfontify-region (beg end
)
1159 (funcall font-lock-unfontify-region-function beg end
))
1161 (defun font-lock-default-fontify-buffer ()
1162 (let ((verbose (if (numberp font-lock-verbose
)
1163 (> (buffer-size) font-lock-verbose
)
1164 font-lock-verbose
)))
1167 (format "Fontifying %s..." (buffer-name)))
1168 ;; Make sure we have the right `font-lock-keywords' etc.
1169 (unless font-lock-mode
1170 (font-lock-set-defaults))
1171 ;; Make sure we fontify etc. in the whole buffer.
1177 (font-lock-fontify-region (point-min) (point-max) verbose
)
1178 (font-lock-after-fontify-buffer)
1179 (setq font-lock-fontified t
)))
1180 ;; We don't restore the old fontification, so it's best to unfontify.
1181 (quit (font-lock-unfontify-buffer))))
1182 ;; Make sure we undo `font-lock-keywords' etc.
1183 (unless font-lock-mode
1184 (font-lock-unset-defaults)))))
1186 (defun font-lock-default-unfontify-buffer ()
1187 ;; Make sure we unfontify etc. in the whole buffer.
1190 (font-lock-unfontify-region (point-min) (point-max))
1191 (font-lock-after-unfontify-buffer)
1192 (setq font-lock-fontified nil
)))
1194 (defun font-lock-default-fontify-region (beg end loudly
)
1196 ((parse-sexp-lookup-properties font-lock-syntactic-keywords
)
1197 (old-syntax-table (syntax-table)))
1201 ;; Use the fontification syntax table, if any.
1202 (when font-lock-syntax-table
1203 (set-syntax-table font-lock-syntax-table
))
1204 ;; check to see if we should expand the beg/end area for
1205 ;; proper multiline matches
1206 (when (and (> beg
(point-min))
1207 (get-text-property (1- beg
) 'font-lock-multiline
))
1208 ;; We are just after or in a multiline match.
1209 (setq beg
(or (previous-single-property-change
1210 beg
'font-lock-multiline
)
1213 (setq beg
(line-beginning-position)))
1214 (setq end
(or (text-property-any end
(point-max)
1215 'font-lock-multiline nil
)
1218 (setq end
(line-end-position))
1219 ;; Now do the fontification.
1220 (font-lock-unfontify-region beg end
)
1221 (when font-lock-syntactic-keywords
1222 (font-lock-fontify-syntactic-keywords-region beg end
))
1223 (unless font-lock-keywords-only
1224 (font-lock-fontify-syntactically-region beg end loudly
))
1225 (font-lock-fontify-keywords-region beg end loudly
))
1227 (set-syntax-table old-syntax-table
))))
1229 ;; The following must be rethought, since keywords can override fontification.
1230 ; ;; Now scan for keywords, but not if we are inside a comment now.
1231 ; (or (and (not font-lock-keywords-only)
1232 ; (let ((state (parse-partial-sexp beg end nil nil
1233 ; font-lock-cache-state)))
1234 ; (or (nth 4 state) (nth 7 state))))
1235 ; (font-lock-fontify-keywords-region beg end))
1237 (defun font-lock-default-unfontify-region (beg end
)
1238 (save-buffer-state nil
1239 (remove-text-properties beg end
1240 (if font-lock-syntactic-keywords
1241 '(face nil syntax-table nil font-lock-multiline nil
)
1242 '(face nil font-lock-multiline nil
)))))
1244 ;; Called when any modification is made to buffer text.
1245 (defun font-lock-after-change-function (beg end old-len
)
1246 (let ((inhibit-point-motion-hooks t
))
1249 ;; Rescan between start of lines enclosing the region.
1250 (font-lock-fontify-region
1251 (progn (goto-char beg
) (beginning-of-line) (point))
1252 (progn (goto-char end
) (forward-line 1) (point)))))))
1254 (defun font-lock-fontify-block (&optional arg
)
1255 "Fontify some lines the way `font-lock-fontify-buffer' would.
1256 The lines could be a function or paragraph, or a specified number of lines.
1257 If ARG is given, fontify that many lines before and after point, or 16 lines if
1258 no ARG is given and `font-lock-mark-block-function' is nil.
1259 If `font-lock-mark-block-function' non-nil and no ARG is given, it is used to
1260 delimit the region to fontify."
1262 (let ((inhibit-point-motion-hooks t
) font-lock-beginning-of-syntax-function
1264 ;; Make sure we have the right `font-lock-keywords' etc.
1265 (if (not font-lock-mode
) (font-lock-set-defaults))
1268 (condition-case error-data
1269 (if (or arg
(not font-lock-mark-block-function
))
1270 (let ((lines (if arg
(prefix-numeric-value arg
) 16)))
1271 (font-lock-fontify-region
1272 (save-excursion (forward-line (- lines
)) (point))
1273 (save-excursion (forward-line lines
) (point))))
1274 (funcall font-lock-mark-block-function
)
1275 (font-lock-fontify-region (point) (mark)))
1276 ((error quit
) (message "Fontifying block...%s" error-data
)))))))
1278 (define-key facemenu-keymap
"\M-g" 'font-lock-fontify-block
)
1280 ;;; End of Fontification functions.
1282 ;;; Additional text property functions.
1284 ;; The following text property functions should be builtins. This means they
1285 ;; should be written in C and put with all the other text property functions.
1286 ;; In the meantime, those that are used by font-lock.el are defined in Lisp
1287 ;; below and given a `font-lock-' prefix. Those that are not used are defined
1288 ;; in Lisp below and commented out. sm.
1290 (defun font-lock-prepend-text-property (start end prop value
&optional object
)
1291 "Prepend to one property of the text from START to END.
1292 Arguments PROP and VALUE specify the property and value to prepend to the value
1293 already in place. The resulting property values are always lists.
1294 Optional argument OBJECT is the string or buffer containing the text."
1295 (let ((val (if (listp value
) value
(list value
))) next prev
)
1296 (while (/= start end
)
1297 (setq next
(next-single-property-change start prop object end
)
1298 prev
(get-text-property start prop object
))
1299 (put-text-property start next prop
1300 (append val
(if (listp prev
) prev
(list prev
)))
1302 (setq start next
))))
1304 (defun font-lock-append-text-property (start end prop value
&optional object
)
1305 "Append to one property of the text from START to END.
1306 Arguments PROP and VALUE specify the property and value to append to the value
1307 already in place. The resulting property values are always lists.
1308 Optional argument OBJECT is the string or buffer containing the text."
1309 (let ((val (if (listp value
) value
(list value
))) next prev
)
1310 (while (/= start end
)
1311 (setq next
(next-single-property-change start prop object end
)
1312 prev
(get-text-property start prop object
))
1313 (put-text-property start next prop
1314 (append (if (listp prev
) prev
(list prev
)) val
)
1316 (setq start next
))))
1318 (defun font-lock-fillin-text-property (start end prop value
&optional object
)
1319 "Fill in one property of the text from START to END.
1320 Arguments PROP and VALUE specify the property and value to put where none are
1321 already in place. Therefore existing property values are not overwritten.
1322 Optional argument OBJECT is the string or buffer containing the text."
1323 (let ((start (text-property-any start end prop nil object
)) next
)
1325 (setq next
(next-single-property-change start prop object end
))
1326 (put-text-property start next prop value object
)
1327 (setq start
(text-property-any next end prop nil object
)))))
1329 ;; For completeness: this is to `remove-text-properties' as `put-text-property'
1330 ;; is to `add-text-properties', etc.
1331 ;(defun remove-text-property (start end property &optional object)
1332 ; "Remove a property from text from START to END.
1333 ;Argument PROPERTY is the property to remove.
1334 ;Optional argument OBJECT is the string or buffer containing the text.
1335 ;Return t if the property was actually removed, nil otherwise."
1336 ; (remove-text-properties start end (list property) object))
1338 ;; For consistency: maybe this should be called `remove-single-property' like
1339 ;; `next-single-property-change' (not `next-single-text-property-change'), etc.
1340 ;(defun remove-single-text-property (start end prop value &optional object)
1341 ; "Remove a specific property value from text from START to END.
1342 ;Arguments PROP and VALUE specify the property and value to remove. The
1343 ;resulting property values are not equal to VALUE nor lists containing VALUE.
1344 ;Optional argument OBJECT is the string or buffer containing the text."
1345 ; (let ((start (text-property-not-all start end prop nil object)) next prev)
1347 ; (setq next (next-single-property-change start prop object end)
1348 ; prev (get-text-property start prop object))
1349 ; (cond ((and (symbolp prev) (eq value prev))
1350 ; (remove-text-property start next prop object))
1351 ; ((and (listp prev) (memq value prev))
1352 ; (let ((new (delq value prev)))
1354 ; (remove-text-property start next prop object))
1355 ; ((= (length new) 1)
1356 ; (put-text-property start next prop (car new) object))
1358 ; (put-text-property start next prop new object))))))
1359 ; (setq start (text-property-not-all next end prop nil object)))))
1361 ;;; End of Additional text property functions.
1363 ;;; Syntactic regexp fontification functions.
1365 ;; These syntactic keyword pass functions are identical to those keyword pass
1366 ;; functions below, with the following exceptions; (a) they operate on
1367 ;; `font-lock-syntactic-keywords' of course, (b) they are all `defun' as speed
1368 ;; is less of an issue, (c) eval of property value does not occur JIT as speed
1369 ;; is less of an issue, (d) OVERRIDE cannot be `prepend' or `append' as it
1370 ;; makes no sense for `syntax-table' property values, (e) they do not do it
1371 ;; LOUDLY as it is not likely to be intensive.
1373 (defun font-lock-apply-syntactic-highlight (highlight)
1374 "Apply HIGHLIGHT following a match.
1375 HIGHLIGHT should be of the form MATCH-HIGHLIGHT,
1376 see `font-lock-syntactic-keywords'."
1377 (let* ((match (nth 0 highlight
))
1378 (start (match-beginning match
)) (end (match-end match
))
1379 (value (nth 1 highlight
))
1380 (override (nth 2 highlight
)))
1381 (when (and (consp value
) (not (numberp (car value
))))
1382 (setq value
(eval value
)))
1383 (when (stringp value
) (setq value
(string-to-syntax value
)))
1385 ;; No match but we might not signal an error.
1386 (or (nth 3 highlight
)
1387 (error "No match %d in highlight %S" match highlight
)))
1389 ;; Cannot override existing fontification.
1390 (or (text-property-not-all start end
'syntax-table nil
)
1391 (put-text-property start end
'syntax-table value
)))
1393 ;; Override existing fontification.
1394 (put-text-property start end
'syntax-table value
))
1395 ((eq override
'keep
)
1396 ;; Keep existing fontification.
1397 (font-lock-fillin-text-property start end
'syntax-table value
)))))
1399 (defun font-lock-fontify-syntactic-anchored-keywords (keywords limit
)
1400 "Fontify according to KEYWORDS until LIMIT.
1401 KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords',
1402 LIMIT can be modified by the value of its PRE-MATCH-FORM."
1403 (let ((matcher (nth 0 keywords
)) (lowdarks (nthcdr 3 keywords
)) highlights
1404 ;; Evaluate PRE-MATCH-FORM.
1405 (pre-match-value (eval (nth 1 keywords
))))
1406 ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line.
1407 (if (and (numberp pre-match-value
) (> pre-match-value
(point)))
1408 (setq limit pre-match-value
)
1409 (setq limit
(line-end-position)))
1411 ;; Find an occurrence of `matcher' before `limit'.
1412 (while (if (stringp matcher
)
1413 (re-search-forward matcher limit t
)
1414 (funcall matcher limit
))
1415 ;; Apply each highlight to this instance of `matcher'.
1416 (setq highlights lowdarks
)
1418 (font-lock-apply-syntactic-highlight (car highlights
))
1419 (setq highlights
(cdr highlights
)))))
1420 ;; Evaluate POST-MATCH-FORM.
1421 (eval (nth 2 keywords
))))
1423 (defun font-lock-fontify-syntactic-keywords-region (start end
)
1424 "Fontify according to `font-lock-syntactic-keywords' between START and END.
1425 START should be at the beginning of a line."
1426 ;; Ensure the beginning of the file is properly syntactic-fontified.
1427 (when (and font-lock-syntactically-fontified
1428 (< font-lock-syntactically-fontified start
))
1429 (setq start
(max font-lock-syntactically-fontified
(point-min)))
1430 (setq font-lock-syntactically-fontified end
))
1431 ;; If `font-lock-syntactic-keywords' is a symbol, get the real keywords.
1432 (when (symbolp font-lock-syntactic-keywords
)
1433 (setq font-lock-syntactic-keywords
(font-lock-eval-keywords
1434 font-lock-syntactic-keywords
)))
1435 ;; If `font-lock-syntactic-keywords' is not compiled, compile it.
1436 (unless (eq (car font-lock-syntactic-keywords
) t
)
1437 (setq font-lock-syntactic-keywords
(font-lock-compile-keywords
1438 font-lock-syntactic-keywords
)))
1439 ;; Get down to business.
1440 (let ((case-fold-search font-lock-keywords-case-fold-search
)
1441 (keywords (cdr font-lock-syntactic-keywords
))
1442 keyword matcher highlights
)
1444 ;; Find an occurrence of `matcher' from `start' to `end'.
1445 (setq keyword
(car keywords
) matcher
(car keyword
))
1447 (while (if (stringp matcher
)
1448 (re-search-forward matcher end t
)
1449 (funcall matcher end
))
1450 ;; Apply each highlight to this instance of `matcher', which may be
1451 ;; specific highlights or more keywords anchored to `matcher'.
1452 (setq highlights
(cdr keyword
))
1454 (if (numberp (car (car highlights
)))
1455 (font-lock-apply-syntactic-highlight (car highlights
))
1456 (font-lock-fontify-syntactic-anchored-keywords (car highlights
)
1458 (setq highlights
(cdr highlights
))))
1459 (setq keywords
(cdr keywords
)))))
1461 ;;; End of Syntactic regexp fontification functions.
1463 ;;; Syntactic fontification functions.
1465 ;; These record the parse state at a particular position, always the start of a
1466 ;; line. Used to make `font-lock-fontify-syntactically-region' faster.
1467 ;; Previously, `font-lock-cache-position' was just a buffer position. However,
1468 ;; under certain situations, this occasionally resulted in mis-fontification.
1469 ;; I think the "situations" were deletion with Lazy Lock mode's deferral. sm.
1470 (defvar font-lock-cache-state nil
)
1471 (defvar font-lock-cache-position nil
)
1473 (defun font-lock-fontify-syntactically-region (start end
&optional loudly
)
1474 "Put proper face on each string and comment between START and END.
1475 START should be at the beginning of a line."
1476 (let ((cache (marker-position font-lock-cache-position
))
1478 (if loudly
(message "Fontifying %s... (syntactically...)" (buffer-name)))
1481 ;; Find the state at the `beginning-of-line' before `start'.
1482 (if (eq start cache
)
1483 ;; Use the cache for the state of `start'.
1484 (setq state font-lock-cache-state
)
1485 ;; Find the state of `start'.
1486 (if (null font-lock-beginning-of-syntax-function
)
1487 ;; Use the state at the previous cache position, if any, or
1488 ;; otherwise calculate from `point-min'.
1489 (if (or (null cache
) (< start cache
))
1490 (setq state
(parse-partial-sexp (point-min) start
))
1491 (setq state
(parse-partial-sexp cache start nil nil
1492 font-lock-cache-state
)))
1493 ;; Call the function to move outside any syntactic block.
1494 (funcall font-lock-beginning-of-syntax-function
)
1495 (setq state
(parse-partial-sexp (point) start
)))
1496 ;; Cache the state and position of `start'.
1497 (setq font-lock-cache-state state
)
1498 (set-marker font-lock-cache-position start
))
1500 ;; If the region starts inside a string or comment, show the extent of it.
1501 (when (or (nth 3 state
) (nth 4 state
))
1502 (setq face
(funcall font-lock-syntactic-face-function state
) beg
(point))
1503 (setq state
(parse-partial-sexp (point) end nil nil state
'syntax-table
))
1504 (put-text-property beg
(point) 'face face
))
1506 ;; Find each interesting place between here and `end'.
1507 (while (and (< (point) end
)
1509 (setq state
(parse-partial-sexp (point) end nil nil state
1511 (or (nth 3 state
) (nth 4 state
))))
1512 (setq face
(funcall font-lock-syntactic-face-function state
)
1514 (setq state
(parse-partial-sexp (point) end nil nil state
'syntax-table
))
1515 (put-text-property beg
(point) 'face face
))))
1517 ;;; End of Syntactic fontification functions.
1519 ;;; Keyword regexp fontification functions.
1521 (defsubst font-lock-apply-highlight
(highlight)
1522 "Apply HIGHLIGHT following a match.
1523 HIGHLIGHT should be of the form MATCH-HIGHLIGHT, see `font-lock-keywords'."
1524 (let* ((match (nth 0 highlight
))
1525 (start (match-beginning match
)) (end (match-end match
))
1526 (override (nth 2 highlight
)))
1528 ;; No match but we might not signal an error.
1529 (or (nth 3 highlight
)
1530 (error "No match %d in highlight %S" match highlight
)))
1532 ;; Cannot override existing fontification.
1533 (or (text-property-not-all start end
'face nil
)
1534 (put-text-property start end
'face
(eval (nth 1 highlight
)))))
1536 ;; Override existing fontification.
1537 (put-text-property start end
'face
(eval (nth 1 highlight
))))
1538 ((eq override
'prepend
)
1539 ;; Prepend to existing fontification.
1540 (font-lock-prepend-text-property start end
'face
(eval (nth 1 highlight
))))
1541 ((eq override
'append
)
1542 ;; Append to existing fontification.
1543 (font-lock-append-text-property start end
'face
(eval (nth 1 highlight
))))
1544 ((eq override
'keep
)
1545 ;; Keep existing fontification.
1546 (font-lock-fillin-text-property start end
'face
(eval (nth 1 highlight
)))))))
1548 (defsubst font-lock-fontify-anchored-keywords
(keywords limit
)
1549 "Fontify according to KEYWORDS until LIMIT.
1550 KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords',
1551 LIMIT can be modified by the value of its PRE-MATCH-FORM."
1552 (let ((matcher (nth 0 keywords
)) (lowdarks (nthcdr 3 keywords
)) highlights
1553 (lead-start (match-beginning 0))
1554 ;; Evaluate PRE-MATCH-FORM.
1555 (pre-match-value (eval (nth 1 keywords
))))
1556 ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line.
1557 (if (not (and (numberp pre-match-value
) (> pre-match-value
(point))))
1558 (setq limit
(line-end-position))
1559 (setq limit pre-match-value
)
1560 (when (and font-lock-multiline
(>= limit
(line-beginning-position 2)))
1561 ;; this is a multiline anchored match
1562 ;; (setq font-lock-multiline t)
1563 (put-text-property (if (= limit
(line-beginning-position 2))
1565 (min lead-start
(point)))
1567 'font-lock-multiline t
)))
1569 ;; Find an occurrence of `matcher' before `limit'.
1570 (while (and (< (point) limit
)
1571 (if (stringp matcher
)
1572 (re-search-forward matcher limit t
)
1573 (funcall matcher limit
)))
1574 ;; Apply each highlight to this instance of `matcher'.
1575 (setq highlights lowdarks
)
1577 (font-lock-apply-highlight (car highlights
))
1578 (setq highlights
(cdr highlights
)))))
1579 ;; Evaluate POST-MATCH-FORM.
1580 (eval (nth 2 keywords
))))
1582 (defun font-lock-fontify-keywords-region (start end
&optional loudly
)
1583 "Fontify according to `font-lock-keywords' between START and END.
1584 START should be at the beginning of a line."
1585 (unless (eq (car font-lock-keywords
) t
)
1586 (setq font-lock-keywords
(font-lock-compile-keywords font-lock-keywords
)))
1587 (let ((case-fold-search font-lock-keywords-case-fold-search
)
1588 (keywords (cdr font-lock-keywords
))
1589 (bufname (buffer-name)) (count 0)
1590 keyword matcher highlights
)
1592 ;; Fontify each item in `font-lock-keywords' from `start' to `end'.
1594 (if loudly
(message "Fontifying %s... (regexps..%s)" bufname
1595 (make-string (incf count
) ?.
)))
1597 ;; Find an occurrence of `matcher' from `start' to `end'.
1598 (setq keyword
(car keywords
) matcher
(car keyword
))
1600 (while (and (< (point) end
)
1601 (if (stringp matcher
)
1602 (re-search-forward matcher end t
)
1603 (funcall matcher end
)))
1604 (when (and font-lock-multiline
1607 (save-excursion (goto-char (match-beginning 0))
1608 (forward-line 1) (point))))
1609 ;; this is a multiline regexp match
1610 ;; (setq font-lock-multiline t)
1611 (put-text-property (if (= (point)
1613 (goto-char (match-beginning 0))
1614 (forward-line 1) (point)))
1616 (match-beginning 0))
1618 'font-lock-multiline t
))
1619 ;; Apply each highlight to this instance of `matcher', which may be
1620 ;; specific highlights or more keywords anchored to `matcher'.
1621 (setq highlights
(cdr keyword
))
1623 (if (numberp (car (car highlights
)))
1624 (font-lock-apply-highlight (car highlights
))
1625 (font-lock-fontify-anchored-keywords (car highlights
) end
))
1626 (setq highlights
(cdr highlights
))))
1627 (setq keywords
(cdr keywords
)))))
1629 ;;; End of Keyword regexp fontification functions.
1631 ;; Various functions.
1633 (defun font-lock-compile-keywords (keywords)
1634 "Compile KEYWORDS into the form (t KEYWORD ...).
1635 Here KEYWORD is of the form (MATCHER HIGHLIGHT ...) as shown in the
1636 `font-lock-keywords' doc string."
1637 (if (eq (car-safe keywords
) t
)
1639 (cons t
(mapcar 'font-lock-compile-keyword keywords
))))
1641 (defun font-lock-compile-keyword (keyword)
1642 (cond ((nlistp keyword
) ; MATCHER
1643 (list keyword
'(0 font-lock-keyword-face
)))
1644 ((eq (car keyword
) 'eval
) ; (eval . FORM)
1645 (font-lock-compile-keyword (eval (cdr keyword
))))
1646 ((eq (car-safe (cdr keyword
)) 'quote
) ; (MATCHER . 'FORM)
1647 ;; If FORM is a FACENAME then quote it. Otherwise ignore the quote.
1648 (if (symbolp (nth 2 keyword
))
1649 (list (car keyword
) (list 0 (cdr keyword
)))
1650 (font-lock-compile-keyword (cons (car keyword
) (nth 2 keyword
)))))
1651 ((numberp (cdr keyword
)) ; (MATCHER . MATCH)
1652 (list (car keyword
) (list (cdr keyword
) 'font-lock-keyword-face
)))
1653 ((symbolp (cdr keyword
)) ; (MATCHER . FACENAME)
1654 (list (car keyword
) (list 0 (cdr keyword
))))
1655 ((nlistp (nth 1 keyword
)) ; (MATCHER . HIGHLIGHT)
1656 (list (car keyword
) (cdr keyword
)))
1657 (t ; (MATCHER HIGHLIGHT ...)
1660 (defun font-lock-eval-keywords (keywords)
1661 "Evalulate KEYWORDS if a function (funcall) or variable (eval) name."
1662 (if (listp keywords
)
1664 (font-lock-eval-keywords (if (fboundp keywords
)
1668 (defun font-lock-value-in-major-mode (alist)
1669 "Return value in ALIST for `major-mode', or ALIST if it is not an alist.
1670 Structure is ((MAJOR-MODE . VALUE) ...) where MAJOR-MODE may be t."
1672 (cdr (or (assq major-mode alist
) (assq t alist
)))
1675 (defun font-lock-choose-keywords (keywords level
)
1676 "Return LEVELth element of KEYWORDS.
1677 A LEVEL of nil is equal to a LEVEL of 0, a LEVEL of t is equal to
1678 \(1- (length KEYWORDS))."
1679 (cond ((not (and (listp keywords
) (symbolp (car keywords
))))
1682 (or (nth level keywords
) (car (reverse keywords
))))
1684 (car (reverse keywords
)))
1688 (defvar font-lock-set-defaults nil
) ; Whether we have set up defaults.
1690 (defun font-lock-set-defaults ()
1691 "Set fontification defaults appropriately for this mode.
1692 Sets various variables using `font-lock-defaults' (or, if nil, using
1693 `font-lock-defaults-alist') and `font-lock-maximum-decoration'."
1694 ;; Set fontification defaults iff not previously set.
1695 (unless font-lock-set-defaults
1696 (set (make-local-variable 'font-lock-set-defaults
) t
)
1697 (set (make-local-variable 'font-lock-cache-state
) nil
)
1698 (set (make-local-variable 'font-lock-cache-position
) (make-marker))
1699 (make-local-variable 'font-lock-fontified
)
1700 (make-local-variable 'font-lock-multiline
)
1701 (let* ((defaults (or font-lock-defaults
1702 (cdr (assq major-mode font-lock-defaults-alist
))))
1704 (font-lock-choose-keywords (nth 0 defaults
)
1705 (font-lock-value-in-major-mode font-lock-maximum-decoration
)))
1706 (local (cdr (assq major-mode font-lock-keywords-alist
)))
1708 (cdr-safe (assq major-mode font-lock-removed-keywords-alist
))))
1709 ;; Regexp fontification?
1710 (set (make-local-variable 'font-lock-keywords
)
1711 (font-lock-compile-keywords (font-lock-eval-keywords keywords
)))
1712 ;; Local fontification?
1714 (font-lock-add-keywords nil
(car (car local
)) (cdr (car local
)))
1715 (setq local
(cdr local
)))
1716 (when removed-keywords
1717 (font-lock-remove-keywords nil removed-keywords
))
1718 ;; Syntactic fontification?
1719 (when (nth 1 defaults
)
1720 (set (make-local-variable 'font-lock-keywords-only
) t
))
1721 ;; Case fold during regexp fontification?
1722 (when (nth 2 defaults
)
1723 (set (make-local-variable 'font-lock-keywords-case-fold-search
) t
))
1724 ;; Syntax table for regexp and syntactic fontification?
1725 (when (nth 3 defaults
)
1726 (let ((slist (nth 3 defaults
)))
1727 (set (make-local-variable 'font-lock-syntax-table
)
1728 (copy-syntax-table (syntax-table)))
1730 ;; The character to modify may be a single CHAR or a STRING.
1731 (let ((chars (if (numberp (car (car slist
)))
1732 (list (car (car slist
)))
1733 (mapcar 'identity
(car (car slist
)))))
1734 (syntax (cdr (car slist
))))
1736 (modify-syntax-entry (car chars
) syntax font-lock-syntax-table
)
1737 (setq chars
(cdr chars
)))
1738 (setq slist
(cdr slist
))))))
1739 ;; Syntax function for syntactic fontification?
1740 (when (nth 4 defaults
)
1741 (set (make-local-variable 'font-lock-beginning-of-syntax-function
)
1744 (let ((alist (nthcdr 5 defaults
)))
1746 (let ((variable (car (car alist
))) (value (cdr (car alist
))))
1747 (unless (boundp variable
)
1749 (set (make-local-variable variable
) value
)
1750 (setq alist
(cdr alist
))))))))
1752 (defun font-lock-unset-defaults ()
1753 "Unset fontification defaults. See function `font-lock-set-defaults'."
1754 (setq font-lock-set-defaults nil
1755 font-lock-keywords nil
1756 font-lock-keywords-only nil
1757 font-lock-keywords-case-fold-search nil
1758 font-lock-syntax-table nil
1759 font-lock-beginning-of-syntax-function nil
)
1760 (let* ((defaults (or font-lock-defaults
1761 (cdr (assq major-mode font-lock-defaults-alist
))))
1762 (alist (nthcdr 5 defaults
)))
1764 (set (car (car alist
)) (default-value (car (car alist
))))
1765 (setq alist
(cdr alist
)))))
1767 ;;; Colour etc. support.
1769 ;; Originally face attributes were specified via `font-lock-face-attributes'.
1770 ;; Users then changed the default face attributes by setting that variable.
1771 ;; However, we try and be back-compatible and respect its value if set except
1772 ;; for faces where M-x customize has been used to save changes for the face.
1773 (when (boundp 'font-lock-face-attributes
)
1774 (let ((face-attributes font-lock-face-attributes
))
1775 (while face-attributes
1776 (let* ((face-attribute (pop face-attributes
))
1777 (face (car face-attribute
)))
1778 ;; Rustle up a `defface' SPEC from a `font-lock-face-attributes' entry.
1779 (unless (get face
'saved-face
)
1780 (let ((foreground (nth 1 face-attribute
))
1781 (background (nth 2 face-attribute
))
1782 (bold-p (nth 3 face-attribute
))
1783 (italic-p (nth 4 face-attribute
))
1784 (underline-p (nth 5 face-attribute
))
1787 (setq face-spec
(cons ':foreground
(cons foreground face-spec
))))
1789 (setq face-spec
(cons ':background
(cons background face-spec
))))
1791 (setq face-spec
(append '(:bold t
) face-spec
)))
1793 (setq face-spec
(append '(:italic t
) face-spec
)))
1795 (setq face-spec
(append '(:underline t
) face-spec
)))
1796 (custom-declare-face face
(list (list t face-spec
)) nil
)))))))
1798 ;; But now we do it the custom way. Note that `defface' will not overwrite any
1799 ;; faces declared above via `custom-declare-face'.
1800 (defface font-lock-comment-face
1801 '((((type tty pc
) (class color
) (background light
)) (:foreground
"red"))
1802 (((type tty pc
) (class color
) (background dark
)) (:foreground
"lightred"))
1803 (((class grayscale
) (background light
))
1804 (:foreground
"DimGray" :bold t
:italic t
))
1805 (((class grayscale
) (background dark
))
1806 (:foreground
"LightGray" :bold t
:italic t
))
1807 (((class color
) (background light
)) (:foreground
"Firebrick"))
1808 (((class color
) (background dark
)) (:foreground
"chocolate1"))
1809 (t (:bold t
:italic t
)))
1810 "Font Lock mode face used to highlight comments."
1811 :group
'font-lock-highlighting-faces
)
1813 (defface font-lock-string-face
1814 '((((type tty
) (class color
)) (:foreground
"green"))
1815 (((class grayscale
) (background light
)) (:foreground
"DimGray" :italic t
))
1816 (((class grayscale
) (background dark
)) (:foreground
"LightGray" :italic t
))
1817 (((class color
) (background light
)) (:foreground
"RosyBrown"))
1818 (((class color
) (background dark
)) (:foreground
"LightSalmon"))
1820 "Font Lock mode face used to highlight strings."
1821 :group
'font-lock-highlighting-faces
)
1823 (defface font-lock-doc-face
1824 '((t :inherit font-lock-string-face
))
1825 "Font Lock mode face used to highlight documentation."
1826 :group
'font-lock-highlighting-faces
)
1828 (defface font-lock-keyword-face
1829 '((((type tty
) (class color
)) (:foreground
"cyan" :weight bold
))
1830 (((class grayscale
) (background light
)) (:foreground
"LightGray" :bold t
))
1831 (((class grayscale
) (background dark
)) (:foreground
"DimGray" :bold t
))
1832 (((class color
) (background light
)) (:foreground
"Purple"))
1833 (((class color
) (background dark
)) (:foreground
"Cyan"))
1835 "Font Lock mode face used to highlight keywords."
1836 :group
'font-lock-highlighting-faces
)
1838 (defface font-lock-builtin-face
1839 '((((type tty
) (class color
)) (:foreground
"blue" :weight light
))
1840 (((class grayscale
) (background light
)) (:foreground
"LightGray" :bold t
))
1841 (((class grayscale
) (background dark
)) (:foreground
"DimGray" :bold t
))
1842 (((class color
) (background light
)) (:foreground
"Orchid"))
1843 (((class color
) (background dark
)) (:foreground
"LightSteelBlue"))
1845 "Font Lock mode face used to highlight builtins."
1846 :group
'font-lock-highlighting-faces
)
1848 (defface font-lock-function-name-face
1849 '((((type tty
) (class color
)) (:foreground
"blue" :weight bold
))
1850 (((class color
) (background light
)) (:foreground
"Blue"))
1851 (((class color
) (background dark
)) (:foreground
"LightSkyBlue"))
1852 (t (:inverse-video t
:bold t
)))
1853 "Font Lock mode face used to highlight function names."
1854 :group
'font-lock-highlighting-faces
)
1856 (defface font-lock-variable-name-face
1857 '((((type tty
) (class color
)) (:foreground
"yellow" :weight light
))
1858 (((class grayscale
) (background light
))
1859 (:foreground
"Gray90" :bold t
:italic t
))
1860 (((class grayscale
) (background dark
))
1861 (:foreground
"DimGray" :bold t
:italic t
))
1862 (((class color
) (background light
)) (:foreground
"DarkGoldenrod"))
1863 (((class color
) (background dark
)) (:foreground
"LightGoldenrod"))
1864 (t (:bold t
:italic t
)))
1865 "Font Lock mode face used to highlight variable names."
1866 :group
'font-lock-highlighting-faces
)
1868 (defface font-lock-type-face
1869 '((((type tty
) (class color
)) (:foreground
"green"))
1870 (((class grayscale
) (background light
)) (:foreground
"Gray90" :bold t
))
1871 (((class grayscale
) (background dark
)) (:foreground
"DimGray" :bold t
))
1872 (((class color
) (background light
)) (:foreground
"ForestGreen"))
1873 (((class color
) (background dark
)) (:foreground
"PaleGreen"))
1874 (t (:bold t
:underline t
)))
1875 "Font Lock mode face used to highlight type and classes."
1876 :group
'font-lock-highlighting-faces
)
1878 (defface font-lock-constant-face
1879 '((((type tty
) (class color
)) (:foreground
"magenta"))
1880 (((class grayscale
) (background light
))
1881 (:foreground
"LightGray" :bold t
:underline t
))
1882 (((class grayscale
) (background dark
))
1883 (:foreground
"Gray50" :bold t
:underline t
))
1884 (((class color
) (background light
)) (:foreground
"CadetBlue"))
1885 (((class color
) (background dark
)) (:foreground
"Aquamarine"))
1886 (t (:bold t
:underline t
)))
1887 "Font Lock mode face used to highlight constants and labels."
1888 :group
'font-lock-highlighting-faces
)
1890 (defface font-lock-warning-face
1891 '((((type tty
) (class color
)) (:foreground
"red"))
1892 (((class color
) (background light
)) (:foreground
"Red" :bold t
))
1893 (((class color
) (background dark
)) (:foreground
"Pink" :bold t
))
1894 (t (:inverse-video t
:bold t
)))
1895 "Font Lock mode face used to highlight warnings."
1896 :group
'font-lock-highlighting-faces
)
1898 ;;; End of Colour etc. support.
1902 ;; This section of code is commented out because Emacs does not have real menu
1903 ;; buttons. (We can mimic them by putting "( ) " or "(X) " at the beginning of
1904 ;; the menu entry text, but with Xt it looks both ugly and embarrassingly
1905 ;; amateur.) If/When Emacs gets real menus buttons, put in menu-bar.el after
1906 ;; the entry for "Text Properties" something like:
1908 ;; (define-key menu-bar-edit-menu [font-lock]
1909 ;; (cons "Syntax Highlighting" font-lock-menu))
1911 ;; and remove a single ";" from the beginning of each line in the rest of this
1912 ;; section. Probably the mechanism for telling the menu code what are menu
1913 ;; buttons and when they are on or off needs tweaking. I have assumed that the
1914 ;; mechanism is via `menu-toggle' and `menu-selected' symbol properties. sm.
1918 ; ;; Make the Font Lock menu.
1919 ; (defvar font-lock-menu (make-sparse-keymap "Syntax Highlighting"))
1920 ; ;; Add the menu items in reverse order.
1921 ; (define-key font-lock-menu [fontify-less]
1922 ; '("Less In Current Buffer" . font-lock-fontify-less))
1923 ; (define-key font-lock-menu [fontify-more]
1924 ; '("More In Current Buffer" . font-lock-fontify-more))
1925 ; (define-key font-lock-menu [font-lock-sep]
1927 ; (define-key font-lock-menu [font-lock-mode]
1928 ; '("In Current Buffer" . font-lock-mode))
1929 ; (define-key font-lock-menu [global-font-lock-mode]
1930 ; '("In All Buffers" . global-font-lock-mode)))
1934 ; ;; We put the appropriate `menu-enable' etc. symbol property values on when
1935 ; ;; font-lock.el is loaded, so we don't need to autoload the three variables.
1936 ; (put 'global-font-lock-mode 'menu-toggle t)
1937 ; (put 'font-lock-mode 'menu-toggle t)
1938 ; (put 'font-lock-fontify-more 'menu-enable '(identity))
1939 ; (put 'font-lock-fontify-less 'menu-enable '(identity)))
1941 ;;; Put the appropriate symbol property values on now. See above.
1942 ;(put 'global-font-lock-mode 'menu-selected 'global-font-lock-mode)
1943 ;(put 'font-lock-mode 'menu-selected 'font-lock-mode)
1944 ;(put 'font-lock-fontify-more 'menu-enable '(nth 2 font-lock-fontify-level))
1945 ;(put 'font-lock-fontify-less 'menu-enable '(nth 1 font-lock-fontify-level))
1947 ;(defvar font-lock-fontify-level nil) ; For less/more fontification.
1949 ;(defun font-lock-fontify-level (level)
1950 ; (let ((font-lock-maximum-decoration level))
1951 ; (when font-lock-mode
1954 ; (when font-lock-verbose
1955 ; (message "Fontifying %s... level %d" (buffer-name) level))))
1957 ;(defun font-lock-fontify-less ()
1958 ; "Fontify the current buffer with less decoration.
1959 ;See `font-lock-maximum-decoration'."
1961 ; ;; Check in case we get called interactively.
1962 ; (if (nth 1 font-lock-fontify-level)
1963 ; (font-lock-fontify-level (1- (car font-lock-fontify-level)))
1964 ; (error "No less decoration")))
1966 ;(defun font-lock-fontify-more ()
1967 ; "Fontify the current buffer with more decoration.
1968 ;See `font-lock-maximum-decoration'."
1970 ; ;; Check in case we get called interactively.
1971 ; (if (nth 2 font-lock-fontify-level)
1972 ; (font-lock-fontify-level (1+ (car font-lock-fontify-level)))
1973 ; (error "No more decoration")))
1975 ;;; This should be called by `font-lock-set-defaults'.
1976 ;(defun font-lock-set-menu ()
1977 ; ;; Activate less/more fontification entries if there are multiple levels for
1978 ; ;; the current buffer. Sets `font-lock-fontify-level' to be of the form
1979 ; ;; (CURRENT-LEVEL IS-LOWER-LEVEL-P IS-HIGHER-LEVEL-P) for menu activation.
1980 ; (let ((keywords (or (nth 0 font-lock-defaults)
1981 ; (nth 1 (assq major-mode font-lock-defaults-alist))))
1982 ; (level (font-lock-value-in-major-mode font-lock-maximum-decoration)))
1983 ; (make-local-variable 'font-lock-fontify-level)
1984 ; (if (or (symbolp keywords) (= (length keywords) 1))
1985 ; (font-lock-unset-menu)
1986 ; (cond ((eq level t)
1987 ; (setq level (1- (length keywords))))
1988 ; ((or (null level) (zerop level))
1989 ; ;; The default level is usually, but not necessarily, level 1.
1990 ; (setq level (- (length keywords)
1991 ; (length (member (eval (car keywords))
1992 ; (mapcar 'eval (cdr keywords))))))))
1993 ; (setq font-lock-fontify-level (list level (> level 1)
1994 ; (< level (1- (length keywords))))))))
1996 ;;; This should be called by `font-lock-unset-defaults'.
1997 ;(defun font-lock-unset-menu ()
1998 ; ;; Deactivate less/more fontification entries.
1999 ; (setq font-lock-fontify-level nil))
2001 ;;; End of Menu support.
2003 ;;; Various regexp information shared by several modes.
2004 ;;; Information specific to a single mode should go in its load library.
2006 ;; Font Lock support for C, C++, Objective-C and Java modes will one day be in
2007 ;; some cc-font.el (and required by cc-mode.el). However, the below function
2008 ;; should stay in font-lock.el, since it is used by other libraries. sm.
2010 (defun font-lock-match-c-style-declaration-item-and-skip-to-next (limit)
2011 "Match, and move over, any declaration/definition item after point.
2012 Matches after point, but ignores leading whitespace and `*' characters.
2013 Does not move further than LIMIT.
2015 The expected syntax of a declaration/definition item is `word' (preceded by
2016 optional whitespace and `*' characters and proceeded by optional whitespace)
2017 optionally followed by a `('. Everything following the item (but belonging to
2018 it) is expected to by skip-able by `scan-sexps', and items are expected to be
2019 separated with a `,' and to be terminated with a `;'.
2021 Thus the regexp matches after point: word (
2023 Where the match subexpressions are: 1 2
2025 The item is delimited by (match-beginning 1) and (match-end 1).
2026 If (match-beginning 2) is non-nil, the item is followed by a `('.
2028 This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
2029 (when (looking-at "[ \t*]*\\(\\sw+\\)[ \t]*\\((\\)?")
2033 ;; Restrict to the end of line, currently guaranteed to be LIMIT.
2034 (narrow-to-region (point-min) limit
)
2035 (goto-char (match-end 1))
2036 ;; Move over any item value, etc., to the next item.
2037 (while (not (looking-at "[ \t]*\\(\\(,\\)\\|;\\|$\\)"))
2038 (goto-char (or (scan-sexps (point) 1) (point-max))))
2039 (goto-char (match-end 2)))
2044 (defconst lisp-font-lock-keywords-1
2049 (list (concat "(\\(def\\("
2050 ;; Function declarations.
2051 "\\(advice\\|alias\\|generic\\|macro\\*?\\|method\\|"
2052 "setf\\|subst\\*?\\|un\\*?\\|"
2053 "ine-\\(condition\\|\\(?:derived\\|minor\\)-mode\\|"
2054 "method-combination\\|setf-expander\\|skeleton\\|widget\\|"
2055 "function\\|\\(compiler\\|modify\\|symbol\\)-macro\\)\\)\\|"
2056 ;; Variable declarations.
2057 "\\(const\\(ant\\)?\\|custom\\|face\\|parameter\\|var\\)\\|"
2058 ;; Structure declarations.
2059 "\\(class\\|group\\|package\\|struct\\|type\\)"
2061 ;; Any whitespace and defined object.
2063 "\\(setf[ \t]+\\sw+)\\|\\sw+\\)?")
2064 '(1 font-lock-keyword-face
)
2065 '(9 (cond ((match-beginning 3) font-lock-function-name-face
)
2066 ((match-beginning 6) font-lock-variable-name-face
)
2067 (t font-lock-type-face
))
2070 ;; Emacs Lisp autoload cookies.
2071 '("^;;;###\\(autoload\\)" 1 font-lock-warning-face prepend
)
2073 "Subdued level highlighting for Lisp modes.")
2075 (defconst lisp-font-lock-keywords-2
2076 (append lisp-font-lock-keywords-1
2080 ;; Control structures. Emacs Lisp forms.
2083 '("cond" "if" "while" "let" "let*"
2084 "prog" "progn" "progv" "prog1" "prog2" "prog*"
2085 "inline" "lambda" "save-restriction" "save-excursion"
2086 "save-window-excursion" "save-selected-window"
2087 "save-match-data" "save-current-buffer" "unwind-protect"
2088 "condition-case" "track-mouse"
2089 "eval-after-load" "eval-and-compile" "eval-when-compile"
2091 "with-current-buffer" "with-electric-help"
2092 "with-output-to-string" "with-output-to-temp-buffer"
2093 "with-temp-buffer" "with-temp-file" "with-temp-message"
2098 ;; Control structures. Common Lisp forms.
2101 '("when" "unless" "case" "ecase" "typecase" "etypecase"
2102 "ccase" "ctypecase" "handler-case" "handler-bind"
2103 "restart-bind" "restart-case" "in-package"
2104 "cerror" "break" "ignore-errors"
2105 "loop" "do" "do*" "dotimes" "dolist" "the" "locally"
2106 "proclaim" "declaim" "declare" "symbol-macrolet"
2107 "lexical-let" "lexical-let*" "flet" "labels" "compiler-let"
2108 "destructuring-bind" "macrolet" "tagbody" "block"
2109 "return" "return-from") t
)
2113 ;; Exit/Feature symbols as constants.
2114 (list (concat "(\\(catch\\|throw\\|featurep\\|provide\\|require\\)\\>"
2115 "[ \t']*\\(\\sw+\\)?")
2116 '(1 font-lock-keyword-face
)
2117 '(2 font-lock-constant-face nil t
))
2119 ;; Erroneous structures.
2120 '("(\\(abort\\|assert\\|error\\|signal\\)\\>" 1 font-lock-warning-face
)
2122 ;; Words inside \\[] tend to be for `substitute-command-keys'.
2123 '("\\\\\\\\\\[\\(\\sw+\\)]" 1 font-lock-constant-face prepend
)
2125 ;; Words inside `' tend to be symbol names.
2126 '("`\\(\\sw\\sw+\\)'" 1 font-lock-constant-face prepend
)
2129 '("\\<:\\sw\\sw+\\>" 0 font-lock-builtin-face
)
2131 ;; ELisp and CLisp `&' keywords as types.
2132 '("\\&\\sw+\\>" . font-lock-type-face
)
2134 ;; CL `with-' and `do-' constructs
2135 '("(\\(\\(do-\\|with-\\)\\(\\s_\\|\\w\\)*\\)" 1 font-lock-keyword-face
)
2137 "Gaudy level highlighting for Lisp modes.")
2139 (defvar lisp-font-lock-keywords lisp-font-lock-keywords-1
2140 "Default expressions to highlight in Lisp modes.")
2144 ;; These provide a means to fontify types not defined by the language. Those
2145 ;; types might be the user's own or they might be generally accepted and used.
2146 ;; Generally accepted types are used to provide default variable values.
2148 (define-widget 'font-lock-extra-types-widget
'radio
2149 "Widget `:type' for members of the custom group `font-lock-extra-types'.
2150 Members should `:load' the package `font-lock' to use this widget."
2151 :args
'((const :tag
"none" nil
)
2152 (repeat :tag
"types" regexp
)))
2154 (defcustom c-font-lock-extra-types
'("FILE" "\\sw+_t")
2155 "*List of extra types to fontify in C mode.
2156 Each list item should be a regexp not containing word-delimiters.
2157 For example, a value of (\"FILE\" \"\\\\sw+_t\") means the word FILE and words
2158 ending in _t are treated as type names.
2160 The value of this variable is used when Font Lock mode is turned on."
2161 :type
'font-lock-extra-types-widget
2162 :group
'font-lock-extra-types
)
2164 (defcustom c
++-font-lock-extra-types
2166 "\\([iof]\\|str\\)+stream\\(buf\\)?" "ios"
2169 "deque" "vector" "bit_vector"
2172 "hash\\(_\\(m\\(ap\\|ulti\\(map\\|set\\)\\)\\|set\\)\\)?"
2173 "stack" "queue" "priority_queue"
2175 "iterator" "const_iterator" "reverse_iterator" "const_reverse_iterator"
2176 "reference" "const_reference")
2177 "*List of extra types to fontify in C++ mode.
2178 Each list item should be a regexp not containing word-delimiters.
2179 For example, a value of (\"string\") means the word string is treated as a type
2182 The value of this variable is used when Font Lock mode is turned on."
2183 :type
'font-lock-extra-types-widget
2184 :group
'font-lock-extra-types
)
2186 (defcustom objc-font-lock-extra-types
'("Class" "BOOL" "IMP" "SEL")
2187 "*List of extra types to fontify in Objective-C mode.
2188 Each list item should be a regexp not containing word-delimiters.
2189 For example, a value of (\"Class\" \"BOOL\" \"IMP\" \"SEL\") means the words
2190 Class, BOOL, IMP and SEL are treated as type names.
2192 The value of this variable is used when Font Lock mode is turned on."
2193 :type
'font-lock-extra-types-widget
2194 :group
'font-lock-extra-types
)
2196 (defcustom java-font-lock-extra-types
2197 '("[A-Z\300-\326\330-\337]\\sw*[a-z]\\sw*")
2198 "*List of extra types to fontify in Java mode.
2199 Each list item should be a regexp not containing word-delimiters.
2200 For example, a value of (\"[A-Z\300-\326\330-\337]\\\\sw*[a-z]\\\\sw*\") means capitalised
2201 words (and words conforming to the Java id spec) are treated as type names.
2203 The value of this variable is used when Font Lock mode is turned on."
2204 :type
'font-lock-extra-types-widget
2205 :group
'font-lock-extra-types
)
2209 ;; [Murmur murmur murmur] Maestro, drum-roll please... [Murmur murmur murmur.]
2210 ;; Ahem. [Murmur murmur murmur] Lay-dees an Gennel-men. [Murmur murmur shhh!]
2211 ;; I am most proud and humbly honoured today [murmur murmur cough] to present
2212 ;; to you good people, the winner of the Second Millennium Award for The Most
2213 ;; Hairy Language Syntax. [Ahhh!] All rise please. [Shuffle shuffle
2214 ;; shuffle.] And a round of applause please. For... The C Language! [Roar.]
2216 ;; Thank you... You are too kind... It is with a feeling of great privilege
2217 ;; and indeed emotion [sob] that I accept this award. It has been a long hard
2218 ;; road. But we know our destiny. And our future. For we must not rest.
2219 ;; There are more tokens to overload, more shoehorn, more methodologies. But
2220 ;; more is a plus! [Ha ha ha.] And more means plus! [Ho ho ho.] The future
2221 ;; is C++! [Ohhh!] The Third Millennium Award... Will be ours! [Roar.]
2223 (defconst c-font-lock-keywords-1 nil
2224 "Subdued level highlighting for C mode.")
2226 (defconst c-font-lock-keywords-2 nil
2227 "Medium level highlighting for C mode.
2228 See also `c-font-lock-extra-types'.")
2230 (defconst c-font-lock-keywords-3 nil
2231 "Gaudy level highlighting for C mode.
2232 See also `c-font-lock-extra-types'.")
2236 (regexp-opt '("break" "continue" "do" "else" "for" "if" "return"
2237 "switch" "while" "sizeof"
2238 ;; Type related, but we don't do anything special.
2239 "typedef" "extern" "auto" "register" "static"
2241 ;; Dan Nicolaescu <done@gnu.org> says this is new.
2245 (regexp-opt '("enum" "struct" "union"))))
2247 (regexp-opt-depth c-type-specs
))
2249 `(mapconcat 'identity
2253 '("char" "short" "int" "long" "signed" "unsigned"
2254 "float" "double" "void" "complex")))
2255 c-font-lock-extra-types
)
2258 `(regexp-opt-depth ,c-type-names
))
2259 (c-preprocessor-directives
2262 '("define" "elif" "else" "endif" "error" "file" "if" "ifdef"
2263 "ifndef" "include" "line" "pragma" "undef"))))
2264 (c-preprocessor-directives-depth
2265 (regexp-opt-depth c-preprocessor-directives
)))
2266 (setq c-font-lock-keywords-1
2269 ;; These are all anchored at the beginning of line for speed.
2270 ;; Note that `c++-font-lock-keywords-1' depends on `c-font-lock-keywords-1'.
2272 ;; Fontify function name definitions (GNU style; without type on line).
2273 '("^\\(\\sw+\\)[ \t]*(" 1 font-lock-function-name-face
)
2275 ;; Fontify error directives.
2276 '("^#[ \t]*error[ \t]+\\(.+\\)" 1 font-lock-warning-face prepend
)
2278 ;; Fontify filenames in #include <...> preprocessor directives as strings.
2279 '("^#[ \t]*\\(import\\|include\\)[ \t]*\\(<[^>\"\n]*>?\\)"
2280 2 font-lock-string-face
)
2282 ;; Fontify function macro names.
2283 '("^#[ \t]*define[ \t]+\\(\\sw+\\)(" 1 font-lock-function-name-face
)
2285 ;; Fontify symbol names in #elif or #if ... defined preprocessor directives.
2286 '("^#[ \t]*\\(elif\\|if\\)\\>"
2287 ("\\<\\(defined\\)\\>[ \t]*(?\\(\\sw+\\)?" nil nil
2288 (1 font-lock-builtin-face
) (2 font-lock-variable-name-face nil t
)))
2290 ;; Fontify otherwise as symbol names, and the preprocessor directive names.
2292 (concat "^#[ \t]*\\(" c-preprocessor-directives
2293 "\\)\\>[ \t!]*\\(\\sw+\\)?")
2294 '(1 font-lock-builtin-face
)
2295 (list (+ 2 c-preprocessor-directives-depth
)
2296 'font-lock-variable-name-face nil t
))))
2298 (setq c-font-lock-keywords-2
2299 (append c-font-lock-keywords-1
2302 ;; Simple regexps for speed.
2304 ;; Fontify all type names.
2306 (cons (concat "\\<\\(" ,c-type-names
"\\)\\>") 'font-lock-type-face
))
2308 ;; Fontify all builtin keywords (except case, default and goto; see below).
2309 (concat "\\<\\(" c-keywords
"\\|" c-type-specs
"\\)\\>")
2311 ;; Fontify case/goto keywords and targets, and case default/goto tags.
2312 '("\\<\\(case\\|goto\\)\\>"
2313 (1 font-lock-keyword-face
)
2314 ("\\(-[0-9]+\\|\\sw+\\)"
2315 ;; Return limit of search.
2316 (save-excursion (skip-chars-forward "^:\n") (point))
2318 (1 font-lock-constant-face nil t
)))
2319 ;; Anders Lindgren <andersl@andersl.com> points out that it is quicker to
2320 ;; use MATCH-ANCHORED to effectively anchor the regexp on the left.
2321 ;; This must come after the one for keywords and targets.
2322 '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*$"
2323 (beginning-of-line) (end-of-line)
2324 (1 font-lock-constant-face
)))
2327 (setq c-font-lock-keywords-3
2328 (append c-font-lock-keywords-2
2330 ;; More complicated regexps for more complete highlighting for types.
2331 ;; We still have to fontify type specifiers individually, as C is so hairy.
2334 ;; Fontify all storage types, plus their items.
2336 (list (concat "\\<\\(" ,c-type-names
"\\)\\>"
2337 "\\([ \t*&]+\\sw+\\>\\)*")
2338 ;; Fontify each declaration item.
2339 (list 'font-lock-match-c-style-declaration-item-and-skip-to-next
2340 ;; Start with point after all type specifiers.
2341 (list 'goto-char
(list 'or
2342 (list 'match-beginning
2343 (+ ,c-type-names-depth
2))
2345 ;; Finish with point after first type specifier.
2346 '(goto-char (match-end 1))
2347 ;; Fontify as a variable or function name.
2348 '(1 (if (match-beginning 2)
2349 font-lock-function-name-face
2350 font-lock-variable-name-face
)))))
2352 ;; Fontify all storage specs and types, plus their items.
2354 (list (concat "\\<\\(" ,c-type-specs
"\\)\\>"
2355 "[ \t]*\\(\\sw+\\)?")
2356 (list 1 'font-lock-keyword-face
)
2357 (list ,(+ c-type-specs-depth
2) 'font-lock-type-face nil t
)
2358 (list 'font-lock-match-c-style-declaration-item-and-skip-to-next
2360 ;; Fontify as a variable or function name.
2361 '(1 (if (match-beginning 2)
2362 font-lock-function-name-face
2363 font-lock-variable-name-face
) nil t
))))
2365 ;; Fontify structures, or typedef names, plus their items.
2366 '("\\(}\\)[ \t*]*\\sw"
2367 (font-lock-match-c-style-declaration-item-and-skip-to-next
2368 (goto-char (match-end 1)) nil
2369 (1 font-lock-type-face
)))
2371 ;; Fontify anything at beginning of line as a declaration or definition.
2372 '("^\\(\\sw+\\)\\>\\([ \t*]+\\sw+\\>\\)*"
2373 (1 font-lock-type-face
)
2374 (font-lock-match-c-style-declaration-item-and-skip-to-next
2375 (goto-char (or (match-beginning 2) (match-end 1))) nil
2376 (1 (if (match-beginning 2)
2377 font-lock-function-name-face
2378 font-lock-variable-name-face
))))
2382 (defvar c-font-lock-keywords c-font-lock-keywords-1
2383 "Default expressions to highlight in C mode.
2384 See also `c-font-lock-extra-types'.")
2388 (defconst c
++-font-lock-keywords-1 nil
2389 "Subdued level highlighting for C++ mode.")
2391 (defconst c
++-font-lock-keywords-2 nil
2392 "Medium level highlighting for C++ mode.
2393 See also `c++-font-lock-extra-types'.")
2395 (defconst c
++-font-lock-keywords-3 nil
2396 "Gaudy level highlighting for C++ mode.
2397 See also `c++-font-lock-extra-types'.")
2399 (defun font-lock-match-c++-style-declaration-item-and-skip-to-next
(limit)
2400 ;; Regexp matches after point: word<word>::word (
2402 ;; Where the match subexpressions are: 1 3 5 6
2404 ;; Item is delimited by (match-beginning 1) and (match-end 1).
2405 ;; If (match-beginning 3) is non-nil, that part of the item incloses a `<>'.
2406 ;; If (match-beginning 5) is non-nil, that part of the item follows a `::'.
2407 ;; If (match-beginning 6) is non-nil, the item is followed by a `('.
2408 (when (looking-at (eval-when-compile
2410 ;; Skip any leading whitespace.
2412 ;; This is `c++-type-spec' from below. (Hint hint!)
2413 "\\(\\sw+\\)" ; The instance?
2414 "\\([ \t]*<\\([^>\n]+\\)[ \t*&]*>\\)?" ; Or template?
2415 "\\([ \t]*::[ \t*~]*\\(\\sw+\\)\\)*" ; Or member?
2416 ;; Match any trailing parenthesis.
2421 ;; Restrict to the end of line, currently guaranteed to be LIMIT.
2422 (narrow-to-region (point-min) limit
)
2423 (goto-char (match-end 1))
2424 ;; Move over any item value, etc., to the next item.
2425 (while (not (looking-at "[ \t]*\\(\\(,\\)\\|;\\|$\\)"))
2426 (goto-char (or (scan-sexps (point) 1) (point-max))))
2427 (goto-char (match-end 2)))
2430 (defun font-lock-match-c++-structor-declaration
(limit)
2431 ;; Match C++ constructors and destructors inside class declarations.
2433 (regexp (concat "^\\s-+\\(\\(virtual\\|explicit\\)\\s-+\\)*~?\\(\\<"
2434 (mapconcat 'identity
2435 c
++-font-lock-extra-types
"\\|")
2437 ;; Don't match function pointer declarations, e.g.:
2440 (while (progn (setq res
(re-search-forward regexp limit t
))
2445 (not (vectorp (c-at-toplevel-p))))))))
2448 (let* ((c++-keywords
2451 '("break" "continue" "do" "else" "for" "if" "return" "switch"
2452 "while" "asm" "catch" "delete" "new" "sizeof" "this" "throw" "try"
2454 ;; Branko Cibej <branko.cibej@hermes.si> says this is new.
2456 ;; Mark Mitchell <mmitchell@usa.net> says these are new.
2457 "mutable" "explicit"
2458 ;; Alain Picard <ap@abelard.apana.org.au> suggests treating these
2459 ;; as keywords not types.
2460 "typedef" "template"
2461 "extern" "auto" "register" "const" "volatile" "static"
2462 "inline" "friend" "virtual"))))
2466 ;; Taken from Stroustrup, minus keywords otherwise fontified.
2467 '("+" "-" "*" "/" "%" "^" "&" "|" "~" "!" "=" "<" ">" "+=" "-="
2468 "*=" "/=" "%=" "^=" "&=" "|=" "<<" ">>" ">>=" "<<=" "==" "!="
2469 "<=" ">=" "&&" "||" "++" "--" "->*" "," "->" "[]" "()"))))
2473 '("class" "public" "private" "protected" "typename"
2474 "struct" "union" "enum" "namespace" "using"
2475 ;; Eric Hopper <hopper@omnifarious.mn.org> says these are new.
2476 "static_cast" "dynamic_cast" "const_cast" "reinterpret_cast") t
)))
2477 (c++-type-specs-depth
2478 (regexp-opt-depth c
++-type-specs
))
2480 `(mapconcat 'identity
2484 '("signed" "unsigned" "short" "long"
2485 "int" "char" "float" "double" "void"
2487 c
++-font-lock-extra-types
)
2489 (c++-type-names-depth
`(regexp-opt-depth ,c
++-type-names
))
2491 ;; A brave attempt to match templates following a type and/or match
2492 ;; class membership. See and sync the above function
2493 ;; `font-lock-match-c++-style-declaration-item-and-skip-to-next'.
2494 (c++-type-suffix
(concat "\\([ \t]*<\\([^>\n]+\\)[ \t*&]*>\\)?"
2495 "\\([ \t]*::[ \t*~]*\\(\\sw+\\)\\)*"))
2496 (c++-type-suffix-depth
(regexp-opt-depth c
++-type-suffix
))
2497 ;; If the string is a type, it may be followed by the cruft above.
2498 (c++-type-spec
(concat "\\(\\sw+\\)\\>" c
++-type-suffix
))
2499 (c++-type-spec-depth
(regexp-opt-depth c
++-type-spec
))
2501 ;; Parenthesis depth of user-defined types not forgetting their cruft.
2502 (c++-type-depth
`(regexp-opt-depth
2503 (concat ,c
++-type-names
,c
++-type-suffix
)))
2505 (setq c
++-font-lock-keywords-1
2508 ;; The list `c-font-lock-keywords-1' less that for function names.
2509 (cdr c-font-lock-keywords-1
)
2512 ;; Fontify function name definitions, possibly incorporating class names.
2513 (list (concat "^" c
++-type-spec
"[ \t]*(")
2514 '(1 (if (or (match-beginning 2) (match-beginning 4))
2516 font-lock-function-name-face
))
2517 '(3 font-lock-type-face nil t
)
2518 '(5 font-lock-function-name-face nil t
))
2521 (setq c
++-font-lock-keywords-2
2522 (append c
++-font-lock-keywords-1
2525 ;; The list `c-font-lock-keywords-2' for C++ plus operator overloading.
2527 (cons (concat "\\<\\(" ,c
++-type-names
"\\)\\>")
2528 'font-lock-type-face
))
2530 ;; Fontify operator overloading.
2531 (list (concat "\\<\\(operator\\)\\>[ \t]*\\(" c
++-operators
"\\)?")
2532 '(1 font-lock-keyword-face
)
2533 '(2 font-lock-builtin-face nil t
))
2535 ;; Fontify case/goto keywords and targets, and case default/goto tags.
2536 '("\\<\\(case\\|goto\\)\\>"
2537 (1 font-lock-keyword-face
)
2538 ("\\(-[0-9]+\\|\\sw+\\)[ \t]*\\(::\\)?"
2539 ;; Return limit of search.
2542 (skip-chars-forward "^:\n")
2547 (1 (if (match-beginning 2)
2549 font-lock-constant-face
) nil t
)))
2550 ;; This must come after the one for keywords and targets.
2551 '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:\\($\\|[^:]\\)"
2552 (beginning-of-line) (end-of-line)
2553 (1 font-lock-constant-face
)))
2555 ;; Fontify other builtin keywords.
2556 (concat "\\<\\(" c
++-keywords
"\\|" c
++-type-specs
"\\)\\>")
2558 ;; Eric Hopper <hopper@omnifarious.mn.org> says `true' and `false' are new.
2559 '("\\<\\(false\\|true\\)\\>" . font-lock-constant-face
)
2562 (setq c
++-font-lock-keywords-3
2563 (append c
++-font-lock-keywords-2
2565 ;; More complicated regexps for more complete highlighting for types.
2568 ;; Fontify all storage classes and type specifiers, plus their items.
2570 (list (concat "\\<\\(" ,c
++-type-names
"\\)\\>" ,c
++-type-suffix
2571 "\\([ \t*&]+" ,c
++-type-spec
"\\)*")
2572 ;; The name of any template type.
2573 (list (+ ,c
++-type-names-depth
3) 'font-lock-type-face nil t
)
2574 ;; Fontify each declaration item.
2575 (list 'font-lock-match-c
++-style-declaration-item-and-skip-to-next
2576 ;; Start with point after all type specifiers.
2577 (list 'goto-char
(list 'or
(list 'match-beginning
2578 (+ ,c
++-type-depth
2))
2580 ;; Finish with point after first type specifier.
2581 '(goto-char (match-end 1))
2582 ;; Fontify as a variable or function name.
2583 '(1 (cond ((or (match-beginning 2) (match-beginning 4))
2584 font-lock-type-face
)
2585 ((and (match-beginning 6) (c-at-toplevel-p))
2586 font-lock-function-name-face
)
2588 font-lock-variable-name-face
)))
2589 '(3 font-lock-type-face nil t
)
2590 '(5 (if (match-beginning 6)
2591 font-lock-function-name-face
2592 font-lock-variable-name-face
) nil t
))))
2594 ;; Fontify all storage specs and types, plus their items.
2596 (list (concat "\\<" ,c
++-type-specs
"\\>" ,c
++-type-suffix
2597 "[ \t]*\\(" ,c
++-type-spec
"\\)?")
2598 ;; The name of any template type.
2599 (list ,(+ c
++-type-specs-depth
2) 'font-lock-type-face nil t
)
2600 ;; The name of any type.
2601 (list (+ ,c
++-type-specs-depth
,c
++-type-suffix-depth
2)
2602 'font-lock-type-face nil t
)
2603 ;; Fontify each declaration item.
2604 (list 'font-lock-match-c
++-style-declaration-item-and-skip-to-next
2605 ;; Start with point after all type specifiers.
2607 ;; Finish with point after first type specifier.
2609 ;; Fontify as a variable or function name.
2610 '(1 (cond ((or (match-beginning 2) (match-beginning 4))
2611 font-lock-type-face
)
2612 ((and (match-beginning 6) (c-at-toplevel-p))
2613 font-lock-function-name-face
)
2615 font-lock-variable-name-face
)))
2616 '(3 font-lock-type-face nil t
)
2617 '(5 (if (match-beginning 6)
2618 font-lock-function-name-face
2619 font-lock-variable-name-face
) nil t
))
2622 ;; Fontify structures, or typedef names, plus their items.
2623 '("\\(}\\)[ \t*]*\\sw"
2624 (font-lock-match-c++-style-declaration-item-and-skip-to-next
2625 (goto-char (match-end 1)) nil
2626 (1 font-lock-type-face
)))
2628 ;; Fontify anything at beginning of line as a declaration or definition.
2629 (list (concat "^\\(" c
++-type-spec
"[ \t*&]*\\)+")
2630 '(font-lock-match-c++-style-declaration-item-and-skip-to-next
2631 (goto-char (match-beginning 1))
2632 (goto-char (match-end 1))
2633 (1 (cond ((or (match-beginning 2) (match-beginning 4))
2634 font-lock-type-face
)
2635 ((match-beginning 6) font-lock-function-name-face
)
2636 (t font-lock-variable-name-face
)))
2637 (3 font-lock-type-face nil t
)
2638 (5 (if (match-beginning 6)
2639 font-lock-function-name-face
2640 font-lock-variable-name-face
) nil t
)))
2642 ;; Fontify constructors and destructors inside class declarations.
2643 '(font-lock-match-c++-structor-declaration
2644 (3 font-lock-function-name-face t
))
2648 (defvar c
++-font-lock-keywords c
++-font-lock-keywords-1
2649 "Default expressions to highlight in C++ mode.
2650 See also `c++-font-lock-extra-types'.")
2654 (defconst objc-font-lock-keywords-1 nil
2655 "Subdued level highlighting for Objective-C mode.")
2657 (defconst objc-font-lock-keywords-2 nil
2658 "Medium level highlighting for Objective-C mode.
2659 See also `objc-font-lock-extra-types'.")
2661 (defconst objc-font-lock-keywords-3 nil
2662 "Gaudy level highlighting for Objective-C mode.
2663 See also `objc-font-lock-extra-types'.")
2665 ;; Regexps written with help from Stephen Peters <speters@us.oracle.com> and
2666 ;; Jacques Duthen Prestataire <duthen@cegelec-red.fr>.
2667 (let* ((objc-keywords
2669 (regexp-opt '("break" "continue" "do" "else" "for" "if" "return"
2670 "switch" "while" "sizeof" "self" "super"
2671 "typedef" "auto" "extern" "static"
2672 "volatile" "const"))))
2676 '("register" "struct" "union" "enum"
2677 "oneway" "in" "out" "inout" "bycopy" "byref") t
)))
2678 (objc-type-specs-depth
2679 (regexp-opt-depth objc-type-specs
))
2681 `(mapconcat 'identity
2685 '("signed" "unsigned" "short" "long"
2686 "int" "char" "float" "double" "void"
2688 objc-font-lock-extra-types
)
2690 (objc-type-names-depth
2691 `(regexp-opt-depth ,objc-type-names
))
2693 (setq objc-font-lock-keywords-1
2696 ;; The list `c-font-lock-keywords-1' less that for function names.
2697 (cdr c-font-lock-keywords-1
)
2700 ;; Fontify compiler directives.
2702 (1 font-lock-keyword-face
)
2703 ("\\=[ \t:<,]*\\(\\sw+\\)" nil nil
2704 (1 font-lock-type-face
)))
2706 ;; Fontify method names and arguments. Oh Lordy!
2707 ;; First, on the same line as the function declaration.
2708 '("^[+-][ \t]*\\(PRIVATE\\>\\)?[ \t]*\\(([^)\n]+)\\)?[ \t]*\\(\\sw+\\)"
2709 (1 font-lock-keyword-face nil t
)
2710 (3 font-lock-function-name-face
)
2711 ("\\=[ \t]*\\(\\sw+\\)?:[ \t]*\\(([^)\n]+)\\)?[ \t]*\\(\\sw+\\)"
2713 (1 font-lock-function-name-face nil t
)
2714 (3 font-lock-variable-name-face
)))
2715 ;; Second, on lines following the function declaration.
2716 '(":" ("^[ \t]*\\(\\sw+\\)?:[ \t]*\\(([^)\n]+)\\)?[ \t]*\\(\\sw+\\)"
2717 (beginning-of-line) (end-of-line)
2718 (1 font-lock-function-name-face nil t
)
2719 (3 font-lock-variable-name-face
)))
2722 (setq objc-font-lock-keywords-2
2723 (append objc-font-lock-keywords-1
2726 ;; Simple regexps for speed.
2728 ;; Fontify all type specifiers.
2730 (cons (concat "\\<\\(" ,objc-type-names
"\\)\\>")
2731 'font-lock-type-face
))
2733 ;; Fontify all builtin keywords (except case, default and goto; see below).
2734 (concat "\\<\\(" objc-keywords
"\\|" objc-type-specs
"\\)\\>")
2736 ;; Fontify case/goto keywords and targets, and case default/goto tags.
2737 '("\\<\\(case\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?"
2738 (1 font-lock-keyword-face
) (2 font-lock-constant-face nil t
))
2739 ;; Fontify tags iff sole statement on line, otherwise we detect selectors.
2740 ;; This must come after the one for keywords and targets.
2741 '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*$"
2742 (beginning-of-line) (end-of-line)
2743 (1 font-lock-constant-face
)))
2745 ;; Fontify null object pointers.
2746 '("\\<[Nn]il\\>" . font-lock-constant-face
)
2749 (setq objc-font-lock-keywords-3
2750 (append objc-font-lock-keywords-2
2752 ;; More complicated regexps for more complete highlighting for types.
2753 ;; We still have to fontify type specifiers individually, as C is so hairy.
2756 ;; Fontify all storage classes and type specifiers, plus their items.
2758 (list (concat "\\<\\(" ,objc-type-names
"\\)\\>"
2759 "\\([ \t*&]+\\sw+\\>\\)*")
2760 ;; Fontify each declaration item.
2761 (list 'font-lock-match-c-style-declaration-item-and-skip-to-next
2762 ;; Start with point after all type specifiers.
2764 (list 'or
(list 'match-beginning
2765 (+ ,objc-type-names-depth
2))
2767 ;; Finish with point after first type specifier.
2768 '(goto-char (match-end 1))
2769 ;; Fontify as a variable or function name.
2770 '(1 (if (match-beginning 2)
2771 font-lock-function-name-face
2772 font-lock-variable-name-face
)))))
2774 ;; Fontify all storage specs and types, plus their items.
2776 (list (concat "\\<\\(" ,objc-type-specs
"[ \t]*\\)+\\>"
2777 "[ \t]*\\(\\sw+\\)?")
2778 ;; The name of any type.
2779 (list ,(+ objc-type-specs-depth
2) 'font-lock-type-face nil t
)
2780 ;; Fontify each declaration item.
2781 (list 'font-lock-match-c
++-style-declaration-item-and-skip-to-next
2783 ;; Fontify as a variable or function name.
2784 '(1 (if (match-beginning 2)
2785 font-lock-function-name-face
2786 font-lock-variable-name-face
)))
2789 ;; Fontify structures, or typedef names, plus their items.
2790 '("\\(}\\)[ \t*]*\\sw"
2791 (font-lock-match-c-style-declaration-item-and-skip-to-next
2792 (goto-char (match-end 1)) nil
2793 (1 font-lock-type-face
)))
2795 ;; Fontify anything at beginning of line as a declaration or definition.
2796 '("^\\(\\sw+\\)\\>\\([ \t*]+\\sw+\\>\\)*"
2797 (1 font-lock-type-face
)
2798 (font-lock-match-c-style-declaration-item-and-skip-to-next
2799 (goto-char (or (match-beginning 2) (match-end 1))) nil
2800 (1 (if (match-beginning 2)
2801 font-lock-function-name-face
2802 font-lock-variable-name-face
))))
2806 (defvar objc-font-lock-keywords objc-font-lock-keywords-1
2807 "Default expressions to highlight in Objective-C mode.
2808 See also `objc-font-lock-extra-types'.")
2812 (defconst java-font-lock-keywords-1 nil
2813 "Subdued level highlighting for Java mode.")
2815 (defconst java-font-lock-keywords-2 nil
2816 "Medium level highlighting for Java mode.
2817 See also `java-font-lock-extra-types'.")
2819 (defconst java-font-lock-keywords-3 nil
2820 "Gaudy level highlighting for Java mode.
2821 See also `java-font-lock-extra-types'.")
2823 ;; Regexps written with help from Fred White <fwhite@bbn.com>,
2824 ;; Anders Lindgren <andersl@andersl.com> and Carl Manning <caroma@ai.mit.edu>.
2825 (let* ((java-keywords
2828 '("catch" "do" "else" "super" "this" "finally" "for" "if"
2829 ;; Anders Lindgren <andersl@andersl.com> says these have gone.
2830 ;; "cast" "byvalue" "future" "generic" "operator" "var"
2831 ;; "inner" "outer" "rest"
2832 "implements" "extends" "throws" "instanceof" "new"
2833 "interface" "return" "switch" "throw" "try" "while"))))
2835 ;; Classes immediately followed by an object name.
2837 `(mapconcat 'identity
2840 (regexp-opt '("boolean" "char" "byte" "short" "int" "long"
2841 "float" "double" "void")))
2842 java-font-lock-extra-types
)
2844 (java-type-names-depth `(regexp-opt-depth ,java-type-names
))
2846 ;; These are eventually followed by an object name.
2850 '("abstract" "const" "final" "synchronized" "transient" "static"
2851 ;; Anders Lindgren <andersl@andersl.com> says this has gone.
2853 "volatile" "public" "private" "protected" "native"
2854 ;; Carl Manning <caroma@ai.mit.edu> says this is new.
2857 (setq java-font-lock-keywords-1
2860 ;; Fontify class names.
2861 '("\\<\\(class\\)\\>[ \t]*\\(\\sw+\\)?"
2862 (1 font-lock-keyword-face
) (2 font-lock-type-face nil t
))
2864 ;; Fontify package names in import directives.
2865 '("\\<\\(import\\|package\\)\\>[ \t]*\\(\\sw+\\)?"
2866 (1 font-lock-keyword-face
)
2867 (2 font-lock-constant-face nil t
)
2868 ("\\=\\.\\(\\*\\|\\sw+\\)" nil nil
2869 (1 font-lock-constant-face nil t
)))
2872 (setq java-font-lock-keywords-2
2873 (append java-font-lock-keywords-1
2876 ;; Fontify class names.
2878 (cons (concat "\\<\\(" ,java-type-names
"\\)\\>[^.]")
2879 '(1 font-lock-type-face
)))
2881 ;; Fontify all builtin keywords (except below).
2882 (concat "\\<\\(" java-keywords
"\\|" java-type-specs
"\\)\\>")
2884 ;; Fontify keywords and targets, and case default/goto tags.
2885 (list "\\<\\(break\\|case\\|continue\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?"
2886 '(1 font-lock-keyword-face
) '(2 font-lock-constant-face nil t
))
2887 ;; This must come after the one for keywords and targets.
2888 '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*$"
2889 (beginning-of-line) (end-of-line)
2890 (1 font-lock-constant-face
)))
2892 ;; Fontify all constants.
2893 '("\\<\\(false\\|null\\|true\\)\\>" . font-lock-constant-face
)
2895 ;; Javadoc tags within comments.
2898 "author\\|deprecated\\|exception"
2899 "\\|link\\|return\\|see\\|serial\\|serialData\\|serialField"
2903 '(1 font-lock-constant-face prepend
))
2904 '("@\\(param\\)\\>[ \t]*\\(\\sw+\\)?"
2905 (1 font-lock-constant-face prepend
)
2906 (2 font-lock-variable-name-face prepend t
))
2907 '("@\\(exception\\|throws\\)\\>[ \t]*\\(\\S-+\\)?"
2908 (1 font-lock-constant-face prepend
)
2909 (2 font-lock-type-face prepend t
))
2912 (setq java-font-lock-keywords-3
2913 (append java-font-lock-keywords-2
2915 ;; More complicated regexps for more complete highlighting for types.
2916 ;; We still have to fontify type specifiers individually, as Java is hairy.
2919 ;; Fontify random types immediately followed by an item or items.
2921 (list (concat "\\<\\(" ,java-type-names
"\\)\\>"
2922 "\\([ \t]*\\[[ \t]*\\]\\)*"
2924 ;; Fontify each declaration item.
2925 (list 'font-lock-match-c-style-declaration-item-and-skip-to-next
2926 ;; Start and finish with point after the type specifier.
2927 (list 'goto-char
(list 'match-beginning
2928 (+ ,java-type-names-depth
3)))
2929 (list 'goto-char
(list 'match-beginning
2930 (+ ,java-type-names-depth
3)))
2931 ;; Fontify as a variable or function name.
2932 '(1 (if (match-beginning 2)
2933 font-lock-function-name-face
2934 font-lock-variable-name-face
)))))
2936 ;; Fontify those that are eventually followed by an item or items.
2937 (list (concat "\\<\\(" java-type-specs
"\\)\\>"
2939 "\\([ \t]*\\[[ \t]*\\]\\)*"
2941 ;; Fontify each declaration item.
2942 '(font-lock-match-c-style-declaration-item-and-skip-to-next
2943 ;; Start with point after all type specifiers.
2944 (goto-char (or (match-beginning 5) (match-end 1)))
2945 ;; Finish with point after first type specifier.
2946 (goto-char (match-end 1))
2947 ;; Fontify as a variable or function name.
2948 (1 (if (match-beginning 2)
2949 font-lock-function-name-face
2950 font-lock-variable-name-face
))))
2954 (defvar java-font-lock-keywords java-font-lock-keywords-1
2955 "Default expressions to highlight in Java mode.
2956 See also `java-font-lock-extra-types'.")
2958 ;; Provide ourselves:
2960 (provide 'font-lock
)
2963 ;;; font-lock.el ends here