(Fformat_mode_line): Fix typo.
[bpt/emacs.git] / lisp / font-lock.el
CommitLineData
876f2438
SM
1;;; font-lock.el --- Electric font lock mode
2
53785d2b 3;; Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 1999, 2000, 2001, 2002
01b69148 4;; Free Software Foundation, Inc.
030f4a35 5
0279f991 6;; Author: jwz, then rms, then sm
030f4a35
RS
7;; Maintainer: FSF
8;; Keywords: languages, faces
9
10;; This file is part of GNU Emacs.
11
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)
15;; any later version.
16
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.
21
22;; You should have received a copy of the GNU General Public License
b578f267
EN
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.
030f4a35 26
030f4a35
RS
27;;; Commentary:
28
b89e1134
SM
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.
030f4a35
RS
31;;
32;; Comments will be displayed in `font-lock-comment-face'.
33;; Strings will be displayed in `font-lock-string-face'.
a1eb1cf1 34;; Regexps are used to display selected patterns in other faces.
030f4a35 35;;
9bfbb130
SM
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.
030f4a35 39;;
a2b8e66b 40;; To turn Font Lock mode on automatically, add this to your ~/.emacs file:
030f4a35 41;;
b89e1134 42;; (add-hook 'emacs-lisp-mode-hook 'turn-on-font-lock)
030f4a35 43;;
a2b8e66b
SM
44;; Or if you want to turn Font Lock mode on in many modes:
45;;
46;; (global-font-lock-mode t)
47;;
9bfbb130
SM
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
5aa29679
RS
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'.
98f84f52 53\f
56fcbd7e
SM
54;;; How Font Lock mode fontifies:
55
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.
62;;
63;; Fontification normally involves syntactic (i.e., strings and comments) and
ac6e572c
SM
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?
67;;
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.
75;;
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.
86;;
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.
92;;
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.
56fcbd7e 98
c1f2ffc8
SM
99;;; How Font Lock mode supports modes or is supported by modes:
100
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'.
56fcbd7e
SM
112;;
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.
c1f2ffc8
SM
115
116;;; Constructing patterns:
117
98f84f52
SM
118;; See the documentation for the variable `font-lock-keywords'.
119;;
ac6e572c
SM
120;; Efficient regexps for use as MATCHERs for `font-lock-keywords' and
121;; `font-lock-syntactic-keywords' can be generated via the function
afa18a4e 122;; `regexp-opt'.
98f84f52 123
c1f2ffc8
SM
124;;; Adding patterns for modes that already support Font Lock:
125
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:
98f84f52 132;;
c1f2ffc8 133;; (font-lock-add-keywords 'c-mode '("\\<\\(and\\|or\\|not\\)\\>"))
98f84f52 134;;
c1f2ffc8
SM
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'.
138
139;;; Adding patterns for modes that do not support Font Lock:
140
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:
98f84f52 148;;
c1f2ffc8
SM
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.")
98f84f52 153;;
c1f2ffc8 154;; (add-hook 'foo-mode-hook
e9476ca8
CW
155;; (lambda ()
156;; (make-local-variable 'font-lock-defaults)
157;; (setq font-lock-defaults '(foo-font-lock-keywords t))))
c1f2ffc8
SM
158
159;;; Adding Font Lock support for modes:
160
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
168;; could be:
98f84f52 169;;
c1f2ffc8
SM
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.")
98f84f52 174;;
c1f2ffc8 175;; and within `bar-mode' there could be:
98f84f52 176;;
c1f2ffc8
SM
177;; (make-local-variable 'font-lock-defaults)
178;; (setq font-lock-defaults '(bar-font-lock-keywords nil t))
98f84f52 179\f
9bfbb130
SM
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.
187;;
188;; So, here are my opinions/advice/guidelines:
5e9e032a 189;;
7d7d915a
SM
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.
194;; i.e., (a) above.
9bfbb130
SM
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.
9bfbb130
SM
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.
206;; - Err, that's it.
a1eb1cf1 207\f
2e6a15fc
SM
208;;; Code:
209
8259bf10
SM
210(require 'syntax)
211
2273c36b 212;; Define core `font-lock' group.
55015061
SM
213(defgroup font-lock nil
214 "Font Lock mode text highlighting package."
215 :link '(custom-manual "(emacs)Font Lock")
63e20d60 216 :link '(custom-manual "(elisp)Font Lock Mode")
55015061
SM
217 :group 'faces)
218
2273c36b
SM
219(defgroup font-lock-highlighting-faces nil
220 "Faces for highlighting text."
55015061 221 :prefix "font-lock-"
2273c36b
SM
222 :group 'font-lock)
223
224(defgroup font-lock-extra-types nil
225 "Extra mode-specific type names for highlighting declarations."
226 :group 'font-lock)
227
ac6e572c 228;; Define support mode groups here to impose `font-lock' group order.
2273c36b
SM
229(defgroup fast-lock nil
230 "Font Lock support mode to cache fontification."
231 :link '(custom-manual "(emacs)Support Modes")
232 :load 'fast-lock
233 :group 'font-lock)
234
235(defgroup lazy-lock nil
236 "Font Lock support mode to fontify lazily."
237 :link '(custom-manual "(emacs)Support Modes")
238 :load 'lazy-lock
55015061 239 :group 'font-lock)
e7f07c2c
GM
240
241(defgroup jit-lock nil
242 "Font Lock support mode to fontify just-in-time."
243 :link '(custom-manual "(emacs)Support Modes")
63e20d60 244 :version "21.1"
faa57c0a 245 :load 'jit-lock
e7f07c2c 246 :group 'font-lock)
55015061 247\f
9bfbb130
SM
248;; User variables.
249
4fffc071 250(defcustom font-lock-maximum-size 256000
23a0e11b
SM
251 "*Maximum size of a buffer for buffer fontification.
252Only buffers less than this can be fontified when Font Lock mode is turned on.
253If nil, means size is irrelevant.
254If a list, each element should be a cons pair of the form (MAJOR-MODE . SIZE),
255where MAJOR-MODE is a symbol or t (meaning the default). For example:
256 ((c-mode . 256000) (c++-mode . 256000) (rmail-mode . 1048576))
257means that the maximum size is 250K for buffers in C or C++ modes, one megabyte
258for buffers in Rmail mode, and size is irrelevant otherwise."
259 :type '(choice (const :tag "none" nil)
260 (integer :tag "size")
261 (repeat :menu-tag "mode specific" :tag "mode specific"
262 :value ((t . nil))
263 (cons :tag "Instance"
264 (radio :tag "Mode"
265 (const :tag "all" t)
266 (symbol :tag "name"))
267 (radio :tag "Size"
268 (const :tag "none" nil)
269 (integer :tag "size")))))
55015061 270 :group 'font-lock)
9bfbb130 271
55015061 272(defcustom font-lock-maximum-decoration t
2d9cdda8 273 "*Maximum decoration level for fontification.
9bfbb130
SM
274If nil, use the default decoration (typically the minimum available).
275If t, use the maximum decoration available.
276If a number, use that level of decoration (or if not available the maximum).
277If a list, each element should be a cons pair of the form (MAJOR-MODE . LEVEL),
278where MAJOR-MODE is a symbol or t (meaning the default). For example:
5aa29679
RS
279 ((c-mode . t) (c++-mode . 2) (t . 1))
280means use the maximum decoration available for buffers in C mode, level 2
55015061 281decoration for buffers in C++ mode, and level 1 decoration otherwise."
b34aa0a3
SM
282 :type '(choice (const :tag "default" nil)
283 (const :tag "maximum" t)
284 (integer :tag "level" 1)
285 (repeat :menu-tag "mode specific" :tag "mode specific"
286 :value ((t . t))
287 (cons :tag "Instance"
288 (radio :tag "Mode"
289 (const :tag "all" t)
290 (symbol :tag "name"))
291 (radio :tag "Decoration"
292 (const :tag "default" nil)
019f00d8 293 (const :tag "maximum" t)
b34aa0a3 294 (integer :tag "level" 1)))))
55015061
SM
295 :group 'font-lock)
296
4fffc071 297(defcustom font-lock-verbose 0
23a0e11b
SM
298 "*If non-nil, means show status messages for buffer fontification.
299If a number, only buffers greater than this size have fontification messages."
300 :type '(choice (const :tag "never" nil)
4fffc071
SM
301 (other :tag "always" t)
302 (integer :tag "size"))
55015061 303 :group 'font-lock)
9bfbb130 304\f
1c172af4
SM
305
306;; Originally these variable values were face names such as `bold' etc.
307;; Now we create our own faces, but we keep these variables for compatibility
308;; and they give users another mechanism for changing face appearance.
309;; We now allow a FACENAME in `font-lock-keywords' to be any expression that
310;; returns a face. So the easiest thing is to continue using these variables,
311;; rather than sometimes evaling FACENAME and sometimes not. sm.
312(defvar font-lock-comment-face 'font-lock-comment-face
313 "Face name to use for comments.")
314
315(defvar font-lock-string-face 'font-lock-string-face
316 "Face name to use for strings.")
317
318(defvar font-lock-doc-face 'font-lock-doc-face
319 "Face name to use for documentation.")
320
321(defvar font-lock-keyword-face 'font-lock-keyword-face
322 "Face name to use for keywords.")
323
324(defvar font-lock-builtin-face 'font-lock-builtin-face
325 "Face name to use for builtins.")
326
327(defvar font-lock-function-name-face 'font-lock-function-name-face
328 "Face name to use for function names.")
329
330(defvar font-lock-variable-name-face 'font-lock-variable-name-face
331 "Face name to use for variable names.")
332
333(defvar font-lock-type-face 'font-lock-type-face
334 "Face name to use for type and class names.")
335
336(defvar font-lock-constant-face 'font-lock-constant-face
337 "Face name to use for constant and label names.")
338
339(defvar font-lock-warning-face 'font-lock-warning-face
340 "Face name to use for things that should stand out.")
341
342(defvar font-lock-reference-face 'font-lock-constant-face
343 "This variable is obsolete. Use `font-lock-constant-face'.")
344
9bfbb130
SM
345;; Fontification variables:
346
030f4a35 347(defvar font-lock-keywords nil
ac6e572c 348 "A list of the keywords to highlight.
caf0dd71 349Each element should have one of these forms:
a1eb1cf1 350
826b2925
SM
351 MATCHER
352 (MATCHER . MATCH)
353 (MATCHER . FACENAME)
354 (MATCHER . HIGHLIGHT)
355 (MATCHER HIGHLIGHT ...)
a078558d 356 (eval . FORM)
a1eb1cf1 357
558371ba
SM
358where MATCHER can be either the regexp to search for, or the function name to
359call to make the search (called with one argument, the limit of the search) and
360return non-nil if it succeeds (and set `match-data' appropriately).
361MATCHER regexps can be generated via the function `regexp-opt'.
9bfbb130 362
a078558d
SM
363FORM is an expression, whose value should be a keyword element, evaluated when
364the keyword is (first) used in a buffer. This feature can be used to provide a
365keyword that can only be generated when Font Lock mode is actually turned on.
366
558371ba
SM
367HIGHLIGHT should be either MATCH-HIGHLIGHT or MATCH-ANCHORED.
368
9c8de95c
SM
369For highlighting single items, for example each instance of the word \"foo\",
370typically only MATCH-HIGHLIGHT is required.
d9f7b2d3 371However, if an item or (typically) items are to be highlighted following the
9c8de95c
SM
372instance of another item (the anchor), for example each instance of the
373word \"bar\" following the word \"anchor\" then MATCH-ANCHORED may be required.
9bfbb130
SM
374
375MATCH-HIGHLIGHT should be of the form:
376
377 (MATCH FACENAME OVERRIDE LAXMATCH)
378
558371ba
SM
379MATCH is the subexpression of MATCHER to be highlighted. FACENAME is an
380expression whose value is the face name to use. Face default attributes
381can be modified via \\[customize]. Instead of a face, FACENAME can
382evaluate to a property list of the form (face VAL1 PROP2 VAL2 PROP3 VAL3 ...)
383in which case all the listed text-properties will be set rather than
384just `face'. In such a case, you will most likely want to put those
385properties in `font-lock-extra-managed-props' or to override
386`font-lock-unfontify-region-function'.
a1eb1cf1 387
2d63aa67 388OVERRIDE and LAXMATCH are flags. If OVERRIDE is t, existing fontification can
9bfbb130
SM
389be overwritten. If `keep', only parts not already fontified are highlighted.
390If `prepend' or `append', existing fontification is merged with the new, in
391which the new or existing fontification, respectively, takes precedence.
d9f7b2d3 392If LAXMATCH is non-nil, no error is signaled if there is no MATCH in MATCHER.
a1eb1cf1 393
9bfbb130
SM
394For example, an element of the form highlights (if not already highlighted):
395
9c8de95c 396 \"\\\\\\=<foo\\\\\\=>\" discrete occurrences of \"foo\" in the value of the
876f2438 397 variable `font-lock-keyword-face'.
9c8de95c 398 (\"fu\\\\(bar\\\\)\" . 1) substring \"bar\" within all occurrences of \"fubar\" in
9bfbb130
SM
399 the value of `font-lock-keyword-face'.
400 (\"fubar\" . fubar-face) Occurrences of \"fubar\" in the value of `fubar-face'.
401 (\"foo\\\\|bar\" 0 foo-bar-face t)
9c8de95c 402 occurrences of either \"foo\" or \"bar\" in the value
9bfbb130 403 of `foo-bar-face', even if already highlighted.
844a6a46 404 (fubar-match 1 fubar-face)
9c8de95c 405 the first subexpression within all occurrences of
844a6a46
SM
406 whatever the function `fubar-match' finds and matches
407 in the value of `fubar-face'.
9bfbb130
SM
408
409MATCH-ANCHORED should be of the form:
410
411 (MATCHER PRE-MATCH-FORM POST-MATCH-FORM MATCH-HIGHLIGHT ...)
412
9c8de95c
SM
413where MATCHER is a regexp to search for or the function name to call to make
414the search, as for MATCH-HIGHLIGHT above, but with one exception; see below.
876f2438
SM
415PRE-MATCH-FORM and POST-MATCH-FORM are evaluated before the first, and after
416the last, instance MATCH-ANCHORED's MATCHER is used. Therefore they can be
417used to initialise before, and cleanup after, MATCHER is used. Typically,
418PRE-MATCH-FORM is used to move to some position relative to the original
419MATCHER, before starting with MATCH-ANCHORED's MATCHER. POST-MATCH-FORM might
420be used to move, before resuming with MATCH-ANCHORED's parent's MATCHER.
9bfbb130
SM
421
422For example, an element of the form highlights (if not already highlighted):
423
876f2438 424 (\"\\\\\\=<anchor\\\\\\=>\" (0 anchor-face) (\"\\\\\\=<item\\\\\\=>\" nil nil (0 item-face)))
9bfbb130 425
9c8de95c 426 discrete occurrences of \"anchor\" in the value of `anchor-face', and subsequent
876f2438
SM
427 discrete occurrences of \"item\" (on the same line) in the value of `item-face'.
428 (Here PRE-MATCH-FORM and POST-MATCH-FORM are nil. Therefore \"item\" is
429 initially searched for starting from the end of the match of \"anchor\", and
430 searching for subsequent instance of \"anchor\" resumes from where searching
431 for \"item\" concluded.)
9bfbb130 432
56fcbd7e
SM
433The above-mentioned exception is as follows. The limit of the MATCHER search
434defaults to the end of the line after PRE-MATCH-FORM is evaluated.
435However, if PRE-MATCH-FORM returns a position greater than the position after
436PRE-MATCH-FORM is evaluated, that position is used as the limit of the search.
437It is generally a bad idea to return a position greater than the end of the
438line, i.e., cause the MATCHER search to span lines.
439
6e1d0d15
SM
440These regular expressions can match text which spans lines, although
441it is better to avoid it if possible since updating them while editing
442text is slower, and it is not guaranteed to be always correct when using
443support modes like jit-lock or lazy-lock.
a1eb1cf1 444
2d63aa67
SM
445This variable is set by major modes via the variable `font-lock-defaults'.
446Be careful when composing regexps for this list; a poorly written pattern can
447dramatically slow things down!")
030f4a35 448
c1f2ffc8
SM
449(defvar font-lock-keywords-alist nil
450 "*Alist of `font-lock-keywords' local to a `major-mode'.
76f5e2af
GM
451This is normally set via `font-lock-add-keywords' and
452`font-lock-remove-keywords'.")
453
454(defvar font-lock-removed-keywords-alist nil
455 "*Alist of `font-lock-keywords' removed from `major-mode'.
456This is normally set via `font-lock-add-keywords' and
457`font-lock-remove-keywords'.")
c1f2ffc8 458
9bfbb130 459(defvar font-lock-keywords-only nil
d46c21ec
SM
460 "*Non-nil means Font Lock should not fontify comments or strings.
461This is normally set via `font-lock-defaults'.")
b89e1134 462
030f4a35 463(defvar font-lock-keywords-case-fold-search nil
d46c21ec
SM
464 "*Non-nil means the patterns in `font-lock-keywords' are case-insensitive.
465This is normally set via `font-lock-defaults'.")
1087f198 466(make-variable-buffer-local 'font-lock-keywords-case-fold-search)
030f4a35 467
c0a6a9fe
SM
468(defvar font-lock-syntactically-fontified 0
469 "Point up to which `font-lock-syntactic-keywords' has been applied.
470If nil, this is ignored, in which case the syntactic fontification may
471sometimes be slightly incorrect.")
472(make-variable-buffer-local 'font-lock-syntactically-fontified)
473
1c172af4
SM
474(defvar font-lock-syntactic-face-function
475 (lambda (state)
476 (if (nth 3 state) font-lock-string-face font-lock-comment-face))
477 "Function to determine which face to use when fontifying syntactically.
478The function is called with a single parameter (the state as returned by
479`parse-partial-sexp' at the beginning of the region to highlight) and
480should return a face.")
481
ac6e572c
SM
482(defvar font-lock-syntactic-keywords nil
483 "A list of the syntactic keywords to highlight.
484Can be the list or the name of a function or variable whose value is the list.
485See `font-lock-keywords' for a description of the form of this list;
486the differences are listed below. MATCH-HIGHLIGHT should be of the form:
487
488 (MATCH SYNTAX OVERRIDE LAXMATCH)
489
5299cb8e
SM
490where SYNTAX can be a string (as taken by `modify-syntax-entry'), a syntax
491table, a cons cell (as returned by `string-to-syntax') or an expression whose
492value is such a form. OVERRIDE cannot be `prepend' or `append'.
ac6e572c 493
9c8de95c
SM
494For example, an element of the form highlights syntactically:
495
5299cb8e 496 (\"\\\\$\\\\(#\\\\)\" 1 \".\")
9c8de95c 497
5299cb8e
SM
498 a hash character when following a dollar character, with a SYNTAX of
499 \".\" (meaning punctuation syntax). Assuming that the buffer syntax table does
9c8de95c
SM
500 specify hash characters to have comment start syntax, the element will only
501 highlight hash characters that do not follow dollar characters as comments
502 syntactically.
503
504 (\"\\\\('\\\\).\\\\('\\\\)\"
5299cb8e
SM
505 (1 \"\\\"\")
506 (2 \"\\\"\"))
9c8de95c 507
5299cb8e
SM
508 both single quotes which surround a single character, with a SYNTAX of
509 \"\\\"\" (meaning string quote syntax). Assuming that the buffer syntax table
9c8de95c
SM
510 does not specify single quotes to have quote syntax, the element will only
511 highlight single quotes of the form 'c' as strings syntactically.
512 Other forms, such as foo'bar or 'fubar', will not be highlighted as strings.
513
ac6e572c
SM
514This is normally set via `font-lock-defaults'.")
515
b056da51 516(defvar font-lock-syntax-table nil
799761f0 517 "Non-nil means use this syntax table for fontifying.
d46c21ec
SM
518If this is nil, the major mode's syntax table is used.
519This is normally set via `font-lock-defaults'.")
520
521(defvar font-lock-beginning-of-syntax-function nil
9bfbb130 522 "*Non-nil means use this function to move back outside of a syntactic block.
a078558d
SM
523When called with no args it should leave point at the beginning of any
524enclosing syntactic block.
9bfbb130 525If this is nil, the beginning of the buffer is used (in the worst case).
47fc2db3
SM
526This is normally set via `font-lock-defaults'.
527It is preferable to set `syntax-begin-function' instead.")
b056da51 528
a078558d
SM
529(defvar font-lock-mark-block-function nil
530 "*Non-nil means use this function to mark a block of text.
531When called with no args it should leave point at the beginning of any
532enclosing textual block and mark at the end.
533This is normally set via `font-lock-defaults'.")
534
a2b8e66b
SM
535(defvar font-lock-fontify-buffer-function 'font-lock-default-fontify-buffer
536 "Function to use for fontifying the buffer.
537This is normally set via `font-lock-defaults'.")
538
539(defvar font-lock-unfontify-buffer-function 'font-lock-default-unfontify-buffer
540 "Function to use for unfontifying the buffer.
541This is used when turning off Font Lock mode.
542This is normally set via `font-lock-defaults'.")
543
544(defvar font-lock-fontify-region-function 'font-lock-default-fontify-region
545 "Function to use for fontifying a region.
546It should take two args, the beginning and end of the region, and an optional
547third arg VERBOSE. If non-nil, the function should print status messages.
548This is normally set via `font-lock-defaults'.")
549
550(defvar font-lock-unfontify-region-function 'font-lock-default-unfontify-region
551 "Function to use for unfontifying a region.
552It should take two args, the beginning and end of the region.
553This is normally set via `font-lock-defaults'.")
554
555(defvar font-lock-inhibit-thing-lock nil
556 "List of Font Lock mode related modes that should not be turned on.
019f00d8 557Currently, valid mode names are `fast-lock-mode', `jit-lock-mode' and
e7f07c2c 558`lazy-lock-mode'. This is normally set via `font-lock-defaults'.")
a2b8e66b 559
030f4a35 560\f
5aa29679
RS
561;; Font Lock mode.
562
563(eval-when-compile
2e6a15fc 564 ;;
5aa29679 565 ;; We don't do this at the top-level as we only use non-autoloaded macros.
2e6a15fc
SM
566 (require 'cl)
567 ;;
568 ;; Borrowed from lazy-lock.el.
569 ;; We use this to preserve or protect things when modifying text properties.
570 (defmacro save-buffer-state (varlist &rest body)
571 "Bind variables according to VARLIST and eval BODY restoring buffer state."
7b7a23f4
EZ
572 (let ((modified (make-symbol "modified")))
573 `(let* ,(append varlist
886c13f1 574 `((,modified (buffer-modified-p))
7b7a23f4
EZ
575 (buffer-undo-list t)
576 (inhibit-read-only t)
577 (inhibit-point-motion-hooks t)
578 (inhibit-modification-hooks t)
579 deactivate-mark
580 buffer-file-name
581 buffer-file-truename))
582 (progn
583 ,@body)
584 (unless ,modified
585 (restore-buffer-modified-p nil)))))
e0e277ff 586 (put 'save-buffer-state 'lisp-indent-function 1)
afa18a4e 587 (def-edebug-spec save-buffer-state let)
e0e277ff
SM
588 ;;
589 ;; Shut up the byte compiler.
1c172af4 590 (defvar font-lock-face-attributes)) ; Obsolete but respected if set.
030f4a35 591
c1f2ffc8 592;;;###autoload
041470d2
SM
593(defun font-lock-add-keywords (mode keywords &optional append)
594 "Add highlighting KEYWORDS for MODE.
595MODE should be a symbol, the major mode command name, such as `c-mode'
1c626aaf 596or nil. If nil, highlighting keywords are added for the current buffer.
c1f2ffc8
SM
597KEYWORDS should be a list; see the variable `font-lock-keywords'.
598By default they are added at the beginning of the current highlighting list.
599If optional argument APPEND is `set', they are used to replace the current
2d63aa67
SM
600highlighting list. If APPEND is any other non-nil value, they are added at the
601end of the current highlighting list.
c1f2ffc8
SM
602
603For example:
604
605 (font-lock-add-keywords 'c-mode
606 '((\"\\\\\\=<\\\\(FIXME\\\\):\" 1 font-lock-warning-face prepend)
607 (\"\\\\\\=<\\\\(and\\\\|or\\\\|not\\\\)\\\\\\=>\" . font-lock-keyword-face)))
608
609adds two fontification patterns for C mode, to fontify `FIXME:' words, even in
2d63aa67
SM
610comments, and to fontify `and', `or' and `not' words as keywords.
611
558371ba
SM
612When used from an elisp package (such as a minor mode), it is recommended
613to use nil for MODE (and place the call in a loop or on a hook) to avoid
614subtle problems due to details of the implementation.
615
2d63aa67
SM
616Note that some modes have specialised support for additional patterns, e.g.,
617see the variables `c-font-lock-extra-types', `c++-font-lock-extra-types',
618`objc-font-lock-extra-types' and `java-font-lock-extra-types'."
041470d2
SM
619 (cond (mode
620 ;; If MODE is non-nil, add the KEYWORDS and APPEND spec to
c1f2ffc8
SM
621 ;; `font-lock-keywords-alist' so `font-lock-set-defaults' uses them.
622 (let ((spec (cons keywords append)) cell)
041470d2 623 (if (setq cell (assq mode font-lock-keywords-alist))
76f5e2af
GM
624 (if (eq append 'set)
625 (setcdr cell (list spec))
626 (setcdr cell (append (cdr cell) (list spec))))
627 (push (list mode spec) font-lock-keywords-alist)))
628 ;; Make sure that `font-lock-removed-keywords-alist' does not
629 ;; contain the new keywords.
630 (font-lock-update-removed-keyword-alist mode keywords append))
6e1d0d15
SM
631 (t
632 ;; Otherwise set or add the keywords now.
633 (font-lock-set-defaults)
634 (if (eq append 'set)
635 (setq font-lock-keywords keywords)
636 (font-lock-remove-keywords nil keywords) ;to avoid duplicates
c1f2ffc8
SM
637 (let ((old (if (eq (car-safe font-lock-keywords) t)
638 (cdr font-lock-keywords)
639 font-lock-keywords)))
640 (setq font-lock-keywords (if append
641 (append old keywords)
642 (append keywords old))))))))
3708dfe9 643
6e1d0d15 644(defun font-lock-update-removed-keyword-alist (mode keywords append)
76f5e2af 645 ;; Update `font-lock-removed-keywords-alist' when adding new
6e1d0d15 646 ;; KEYWORDS to MODE.
76f5e2af
GM
647 ;;
648 ;; When font-lock is enabled first all keywords in the list
649 ;; `font-lock-keywords-alist' are added, then all keywords in the
650 ;; list `font-lock-removed-keywords-alist' are removed. If a
651 ;; keyword was once added, removed, and then added again it must be
652 ;; removed from the removed-keywords list. Otherwise the second add
653 ;; will not take effect.
6e1d0d15 654 (let ((cell (assq mode font-lock-removed-keywords-alist)))
76f5e2af
GM
655 (if cell
656 (if (eq append 'set)
657 ;; A new set of keywords is defined. Forget all about
658 ;; our old keywords that should be removed.
659 (setq font-lock-removed-keywords-alist
660 (delq cell font-lock-removed-keywords-alist))
661 ;; Delete all previously removed keywords.
662 (dolist (kword keywords)
663 (setcdr cell (delete kword (cdr cell))))
6e1d0d15 664 ;; Delete the mode cell if empty.
76f5e2af
GM
665 (if (null (cdr cell))
666 (setq font-lock-removed-keywords-alist
667 (delq cell font-lock-removed-keywords-alist)))))))
668
669;; Written by Anders Lindgren <andersl@andersl.com>.
670;;
671;; Case study:
672;; (I) The keywords are removed from a major mode.
673;; In this case the keyword could be local (i.e. added earlier by
674;; `font-lock-add-keywords'), global, or both.
675;;
676;; (a) In the local case we remove the keywords from the variable
677;; `font-lock-keywords-alist'.
678;;
679;; (b) The actual global keywords are not known at this time.
680;; All keywords are added to `font-lock-removed-keywords-alist',
681;; when font-lock is enabled those keywords are removed.
682;;
683;; Note that added keywords are taken out of the list of removed
684;; keywords. This ensure correct operation when the same keyword
685;; is added and removed several times.
686;;
687;; (II) The keywords are removed from the current buffer.
3708dfe9 688;;;###autoload
6e1d0d15
SM
689(defun font-lock-remove-keywords (mode keywords)
690 "Remove highlighting KEYWORDS for MODE.
3708dfe9 691
6e1d0d15 692MODE should be a symbol, the major mode command name, such as `c-mode'
558371ba
SM
693or nil. If nil, highlighting keywords are removed for the current buffer.
694
695When used from an elisp package (such as a minor mode), it is recommended
696to use nil for MODE (and place the call in a loop or on a hook) to avoid
697subtle problems due to details of the implementation."
6e1d0d15
SM
698 (cond (mode
699 ;; Remove one keyword at the time.
700 (dolist (keyword keywords)
701 (let ((top-cell (assq mode font-lock-keywords-alist)))
702 ;; If MODE is non-nil, remove the KEYWORD from
76f5e2af
GM
703 ;; `font-lock-keywords-alist'.
704 (when top-cell
705 (dolist (keyword-list-append-pair (cdr top-cell))
706 ;; `keywords-list-append-pair' is a cons with a list of
707 ;; keywords in the car top-cell and the original append
708 ;; argument in the cdr top-cell.
709 (setcar keyword-list-append-pair
710 (delete keyword (car keyword-list-append-pair))))
711 ;; Remove keyword list/append pair when the keyword list
712 ;; is empty and append doesn't specify `set'. (If it
713 ;; should be deleted then previously deleted keywords
714 ;; would appear again.)
715 (let ((cell top-cell))
716 (while (cdr cell)
717 (if (and (null (car (car (cdr cell))))
718 (not (eq (cdr (car (cdr cell))) 'set)))
719 (setcdr cell (cdr (cdr cell)))
720 (setq cell (cdr cell)))))
721 ;; Final cleanup, remove major mode cell if last keyword
722 ;; was deleted.
723 (if (null (cdr top-cell))
724 (setq font-lock-keywords-alist
725 (delq top-cell font-lock-keywords-alist))))
726 ;; Remember the keyword in case it is not local.
6e1d0d15 727 (let ((cell (assq mode font-lock-removed-keywords-alist)))
76f5e2af
GM
728 (if cell
729 (unless (member keyword (cdr cell))
730 (nconc cell (list keyword)))
6e1d0d15
SM
731 (push (cons mode (list keyword))
732 font-lock-removed-keywords-alist))))))
733 (t
734 ;; Otherwise remove it immediately.
735 (font-lock-set-defaults)
736 (setq font-lock-keywords (copy-sequence font-lock-keywords))
737 (dolist (keyword keywords)
76f5e2af 738 (setq font-lock-keywords
6e1d0d15
SM
739 (delete keyword
740 ;; The keywords might be compiled.
741 (delete (font-lock-compile-keyword keyword)
742 font-lock-keywords)))))))
a2b8e66b 743\f
2d63aa67
SM
744;;; Font Lock Support mode.
745
5aa29679
RS
746;; This is the code used to interface font-lock.el with any of its add-on
747;; packages, and provide the user interface. Packages that have their own
748;; local buffer fontification functions (see below) may have to call
749;; `font-lock-after-fontify-buffer' and/or `font-lock-after-unfontify-buffer'
750;; themselves.
751
5f999b0b 752(defcustom font-lock-support-mode 'jit-lock-mode
5aa29679
RS
753 "*Support mode for Font Lock mode.
754Support modes speed up Font Lock mode by being choosy about when fontification
e7f07c2c
GM
755occurs. Known support modes are Fast Lock mode (symbol `fast-lock-mode'),
756Lazy Lock mode (symbol `lazy-lock-mode'), and Just-in-time Lock mode (symbol
757`jit-lock-mode'. See those modes for more info.
5aa29679
RS
758If nil, means support for Font Lock mode is never performed.
759If a symbol, use that support mode.
760If a list, each element should be of the form (MAJOR-MODE . SUPPORT-MODE),
761where MAJOR-MODE is a symbol or t (meaning the default). For example:
762 ((c-mode . fast-lock-mode) (c++-mode . fast-lock-mode) (t . lazy-lock-mode))
763means that Fast Lock mode is used to support Font Lock mode for buffers in C or
764C++ modes, and Lazy Lock mode is used to support Font Lock mode otherwise.
765
55015061 766The value of this variable is used when Font Lock mode is turned on."
b34aa0a3
SM
767 :type '(choice (const :tag "none" nil)
768 (const :tag "fast lock" fast-lock-mode)
769 (const :tag "lazy lock" lazy-lock-mode)
e7f07c2c 770 (const :tag "jit lock" jit-lock-mode)
b34aa0a3 771 (repeat :menu-tag "mode specific" :tag "mode specific"
1c172af4 772 :value ((t . jit-lock-mode))
b34aa0a3
SM
773 (cons :tag "Instance"
774 (radio :tag "Mode"
775 (const :tag "all" t)
776 (symbol :tag "name"))
39df451b
SM
777 (radio :tag "Support"
778 (const :tag "none" nil)
b34aa0a3 779 (const :tag "fast lock" fast-lock-mode)
e7f07c2c
GM
780 (const :tag "lazy lock" lazy-lock-mode)
781 (const :tag "JIT lock" jit-lock-mode)))
b34aa0a3 782 ))
c69e5fcd 783 :version "21.1"
55015061 784 :group 'font-lock)
5aa29679 785
2e6a15fc
SM
786(defvar fast-lock-mode nil)
787(defvar lazy-lock-mode nil)
e7f07c2c 788(defvar jit-lock-mode nil)
2e6a15fc 789
5aa29679
RS
790(defun font-lock-turn-on-thing-lock ()
791 (let ((thing-mode (font-lock-value-in-major-mode font-lock-support-mode)))
792 (cond ((eq thing-mode 'fast-lock-mode)
793 (fast-lock-mode t))
794 ((eq thing-mode 'lazy-lock-mode)
e7f07c2c
GM
795 (lazy-lock-mode t))
796 ((eq thing-mode 'jit-lock-mode)
28a53bc1
SM
797 ;; Prepare for jit-lock
798 (remove-hook 'after-change-functions
799 'font-lock-after-change-function t)
800 (set (make-local-variable 'font-lock-fontify-buffer-function)
fd612dd9 801 'jit-lock-refontify)
28a53bc1
SM
802 ;; Don't fontify eagerly (and don't abort is the buffer is large).
803 (set (make-local-variable 'font-lock-fontified) t)
804 ;; Use jit-lock.
805 (jit-lock-register 'font-lock-fontify-region
806 (not font-lock-keywords-only))))))
5aa29679 807
5aa29679
RS
808(defun font-lock-turn-off-thing-lock ()
809 (cond (fast-lock-mode
1c172af4 810 (fast-lock-mode -1))
e7f07c2c 811 (jit-lock-mode
28a53bc1
SM
812 (jit-lock-unregister 'font-lock-fontify-region)
813 ;; Reset local vars to the non-jit-lock case.
814 (kill-local-variable 'font-lock-fontify-buffer-function))
5aa29679 815 (lazy-lock-mode
1c172af4 816 (lazy-lock-mode -1))))
5aa29679
RS
817
818(defun font-lock-after-fontify-buffer ()
819 (cond (fast-lock-mode
820 (fast-lock-after-fontify-buffer))
13f0d185
SM
821 ;; Useless now that jit-lock intercepts font-lock-fontify-buffer. -sm
822 ;; (jit-lock-mode
823 ;; (jit-lock-after-fontify-buffer))
5aa29679
RS
824 (lazy-lock-mode
825 (lazy-lock-after-fontify-buffer))))
826
827(defun font-lock-after-unfontify-buffer ()
828 (cond (fast-lock-mode
829 (fast-lock-after-unfontify-buffer))
13f0d185
SM
830 ;; Useless as well. It's only called when:
831 ;; - turning off font-lock: it does not matter if we leave spurious
832 ;; `fontified' text props around since jit-lock-mode is also off.
833 ;; - font-lock-default-fontify-buffer fails: this is not run
834 ;; any more anyway. -sm
5e9e032a 835 ;;
13f0d185
SM
836 ;; (jit-lock-mode
837 ;; (jit-lock-after-unfontify-buffer))
5aa29679
RS
838 (lazy-lock-mode
839 (lazy-lock-after-unfontify-buffer))))
840
2d63aa67 841;;; End of Font Lock Support mode.
5aa29679 842\f
2d63aa67 843;;; Fontification functions.
a1eb1cf1 844
56fcbd7e
SM
845;; Rather than the function, e.g., `font-lock-fontify-region' containing the
846;; code to fontify a region, the function runs the function whose name is the
847;; value of the variable, e.g., `font-lock-fontify-region-function'. Normally,
848;; the value of this variable is, e.g., `font-lock-default-fontify-region'
849;; which does contain the code to fontify a region. However, the value of the
850;; variable could be anything and thus, e.g., `font-lock-fontify-region' could
851;; do anything. The indirection of the fontification functions gives major
852;; modes the capability of modifying the way font-lock.el fontifies. Major
853;; modes can modify the values of, e.g., `font-lock-fontify-region-function',
854;; via the variable `font-lock-defaults'.
855;;
856;; For example, Rmail mode sets the variable `font-lock-defaults' so that
857;; font-lock.el uses its own function for buffer fontification. This function
858;; makes fontification be on a message-by-message basis and so visiting an
859;; RMAIL file is much faster. A clever implementation of the function might
860;; fontify the headers differently than the message body. (It should, and
861;; correspondingly for Mail mode, but I can't be bothered to do the work. Can
862;; you?) This hints at a more interesting use...
863;;
864;; Languages that contain text normally contained in different major modes
865;; could define their own fontification functions that treat text differently
866;; depending on its context. For example, Perl mode could arrange that here
867;; docs are fontified differently than Perl code. Or Yacc mode could fontify
868;; rules one way and C code another. Neat!
869;;
870;; A further reason to use the fontification indirection feature is when the
871;; default syntactual fontification, or the default fontification in general,
872;; is not flexible enough for a particular major mode. For example, perhaps
55015061
SM
873;; comments are just too hairy for `font-lock-fontify-syntactically-region' to
874;; cope with. You need to write your own version of that function, e.g.,
875;; `hairy-fontify-syntactically-region', and make your own version of
876;; `hairy-fontify-region' call that function before calling
56fcbd7e
SM
877;; `font-lock-fontify-keywords-region' for the normal regexp fontification
878;; pass. And Hairy mode would set `font-lock-defaults' so that font-lock.el
879;; would call your region fontification function instead of its own. For
55015061 880;; example, TeX modes could fontify {\foo ...} and \bar{...} etc. multi-line
56fcbd7e
SM
881;; directives correctly and cleanly. (It is the same problem as fontifying
882;; multi-line strings and comments; regexps are not appropriate for the job.)
883
a1eb1cf1 884;;;###autoload
030f4a35 885(defun font-lock-fontify-buffer ()
019f00d8 886 "Fontify the current buffer the way the function `font-lock-mode' would."
030f4a35 887 (interactive)
a2b8e66b
SM
888 (let ((font-lock-verbose (or font-lock-verbose (interactive-p))))
889 (funcall font-lock-fontify-buffer-function)))
890
891(defun font-lock-unfontify-buffer ()
892 (funcall font-lock-unfontify-buffer-function))
893
894(defun font-lock-fontify-region (beg end &optional loudly)
895 (funcall font-lock-fontify-region-function beg end loudly))
896
897(defun font-lock-unfontify-region (beg end)
898 (funcall font-lock-unfontify-region-function beg end))
899
900(defun font-lock-default-fontify-buffer ()
5aa29679
RS
901 (let ((verbose (if (numberp font-lock-verbose)
902 (> (buffer-size) font-lock-verbose)
903 font-lock-verbose)))
79f238c9 904 (with-temp-message
1787769b
SM
905 (when verbose
906 (format "Fontifying %s..." (buffer-name)))
79f238c9
SM
907 ;; Make sure we have the right `font-lock-keywords' etc.
908 (unless font-lock-mode
909 (font-lock-set-defaults))
910 ;; Make sure we fontify etc. in the whole buffer.
911 (save-restriction
912 (widen)
913 (condition-case nil
914 (save-excursion
915 (save-match-data
916 (font-lock-fontify-region (point-min) (point-max) verbose)
917 (font-lock-after-fontify-buffer)
918 (setq font-lock-fontified t)))
919 ;; We don't restore the old fontification, so it's best to unfontify.
8259bf10 920 (quit (font-lock-unfontify-buffer)))))))
7d7d915a 921
a2b8e66b 922(defun font-lock-default-unfontify-buffer ()
56fcbd7e 923 ;; Make sure we unfontify etc. in the whole buffer.
a2b8e66b
SM
924 (save-restriction
925 (widen)
926 (font-lock-unfontify-region (point-min) (point-max))
271c888a 927 (font-lock-after-unfontify-buffer)
a2b8e66b 928 (setq font-lock-fontified nil)))
9bfbb130 929
a2b8e66b 930(defun font-lock-default-fontify-region (beg end loudly)
ac6e572c
SM
931 (save-buffer-state
932 ((parse-sexp-lookup-properties font-lock-syntactic-keywords)
933 (old-syntax-table (syntax-table)))
876f2438 934 (unwind-protect
a078558d
SM
935 (save-restriction
936 (widen)
876f2438 937 ;; Use the fontification syntax table, if any.
2e6a15fc
SM
938 (when font-lock-syntax-table
939 (set-syntax-table font-lock-syntax-table))
fb0e4f8a
RS
940 ;; check to see if we should expand the beg/end area for
941 ;; proper multiline matches
f9261020
GM
942 (when (and font-lock-multiline
943 (> beg (point-min))
28a53bc1
SM
944 (get-text-property (1- beg) 'font-lock-multiline))
945 ;; We are just after or in a multiline match.
946 (setq beg (or (previous-single-property-change
947 beg 'font-lock-multiline)
ba22aeff
SM
948 (point-min)))
949 (goto-char beg)
950 (setq beg (line-beginning-position)))
111c181e
GM
951 (when font-lock-multiline
952 (setq end (or (text-property-any end (point-max)
953 'font-lock-multiline nil)
954 (point-max))))
ba22aeff 955 (goto-char end)
724a330f 956 (setq end (line-beginning-position 2))
876f2438 957 ;; Now do the fontification.
2e6a15fc 958 (font-lock-unfontify-region beg end)
ac6e572c
SM
959 (when font-lock-syntactic-keywords
960 (font-lock-fontify-syntactic-keywords-region beg end))
2e6a15fc 961 (unless font-lock-keywords-only
876f2438
SM
962 (font-lock-fontify-syntactically-region beg end loudly))
963 (font-lock-fontify-keywords-region beg end loudly))
964 ;; Clean up.
2e6a15fc 965 (set-syntax-table old-syntax-table))))
9bfbb130
SM
966
967;; The following must be rethought, since keywords can override fontification.
968; ;; Now scan for keywords, but not if we are inside a comment now.
969; (or (and (not font-lock-keywords-only)
019f00d8 970; (let ((state (parse-partial-sexp beg end nil nil
9bfbb130
SM
971; font-lock-cache-state)))
972; (or (nth 4 state) (nth 7 state))))
973; (font-lock-fontify-keywords-region beg end))
974
8259bf10
SM
975(defvar font-lock-extra-managed-props nil
976 "Additional text properties managed by font-lock.
977This is used by `font-lock-default-unfontify-region' to decide
8e12e275
SM
978what properties to clear before refontifying a region.
979Since it is more or less directly passed to `remove-text-properties',
980it should have the shape of a property list (i.e. every other element
981is ignored).")
8259bf10 982
a2b8e66b 983(defun font-lock-default-unfontify-region (beg end)
2e6a15fc 984 (save-buffer-state nil
8259bf10
SM
985 (remove-text-properties
986 beg end (append
987 font-lock-extra-managed-props
988 (if font-lock-syntactic-keywords
989 '(face nil syntax-table nil font-lock-multiline nil)
990 '(face nil font-lock-multiline nil))))))
9bfbb130
SM
991
992;; Called when any modification is made to buffer text.
993(defun font-lock-after-change-function (beg end old-len)
46f26fcf
SM
994 (let ((inhibit-point-motion-hooks t))
995 (save-excursion
996 (save-match-data
997 ;; Rescan between start of lines enclosing the region.
998 (font-lock-fontify-region
999 (progn (goto-char beg) (beginning-of-line) (point))
1000 (progn (goto-char end) (forward-line 1) (point)))))))
a2b8e66b 1001
a078558d
SM
1002(defun font-lock-fontify-block (&optional arg)
1003 "Fontify some lines the way `font-lock-fontify-buffer' would.
1004The lines could be a function or paragraph, or a specified number of lines.
a078558d 1005If ARG is given, fontify that many lines before and after point, or 16 lines if
a465832f
SM
1006no ARG is given and `font-lock-mark-block-function' is nil.
1007If `font-lock-mark-block-function' non-nil and no ARG is given, it is used to
1008delimit the region to fontify."
a078558d 1009 (interactive "P")
46f26fcf
SM
1010 (let ((inhibit-point-motion-hooks t) font-lock-beginning-of-syntax-function
1011 deactivate-mark)
a078558d
SM
1012 ;; Make sure we have the right `font-lock-keywords' etc.
1013 (if (not font-lock-mode) (font-lock-set-defaults))
a2b8e66b
SM
1014 (save-excursion
1015 (save-match-data
1016 (condition-case error-data
a078558d
SM
1017 (if (or arg (not font-lock-mark-block-function))
1018 (let ((lines (if arg (prefix-numeric-value arg) 16)))
1019 (font-lock-fontify-region
1020 (save-excursion (forward-line (- lines)) (point))
1021 (save-excursion (forward-line lines) (point))))
1022 (funcall font-lock-mark-block-function)
1023 (font-lock-fontify-region (point) (mark)))
6c0fc428 1024 ((error quit) (message "Fontifying block...%s" error-data)))))))
a078558d 1025
94de9afe 1026(define-key facemenu-keymap "\M-g" 'font-lock-fontify-block)
2d63aa67
SM
1027
1028;;; End of Fontification functions.
9bfbb130 1029\f
9bfbb130
SM
1030;;; Additional text property functions.
1031
1c626aaf
SM
1032;; The following text property functions should be builtins. This means they
1033;; should be written in C and put with all the other text property functions.
1034;; In the meantime, those that are used by font-lock.el are defined in Lisp
1035;; below and given a `font-lock-' prefix. Those that are not used are defined
1036;; in Lisp below and commented out. sm.
9bfbb130 1037
1c626aaf 1038(defun font-lock-prepend-text-property (start end prop value &optional object)
9bfbb130
SM
1039 "Prepend to one property of the text from START to END.
1040Arguments PROP and VALUE specify the property and value to prepend to the value
1c626aaf 1041already in place. The resulting property values are always lists.
9bfbb130
SM
1042Optional argument OBJECT is the string or buffer containing the text."
1043 (let ((val (if (listp value) value (list value))) next prev)
1044 (while (/= start end)
1045 (setq next (next-single-property-change start prop object end)
1046 prev (get-text-property start prop object))
1c626aaf
SM
1047 (put-text-property start next prop
1048 (append val (if (listp prev) prev (list prev)))
1049 object)
9bfbb130
SM
1050 (setq start next))))
1051
1c626aaf 1052(defun font-lock-append-text-property (start end prop value &optional object)
9bfbb130
SM
1053 "Append to one property of the text from START to END.
1054Arguments PROP and VALUE specify the property and value to append to the value
1c626aaf 1055already in place. The resulting property values are always lists.
9bfbb130
SM
1056Optional argument OBJECT is the string or buffer containing the text."
1057 (let ((val (if (listp value) value (list value))) next prev)
1058 (while (/= start end)
1059 (setq next (next-single-property-change start prop object end)
1060 prev (get-text-property start prop object))
1c626aaf
SM
1061 (put-text-property start next prop
1062 (append (if (listp prev) prev (list prev)) val)
1063 object)
9bfbb130 1064 (setq start next))))
1c626aaf
SM
1065
1066(defun font-lock-fillin-text-property (start end prop value &optional object)
1067 "Fill in one property of the text from START to END.
1068Arguments PROP and VALUE specify the property and value to put where none are
1069already in place. Therefore existing property values are not overwritten.
1070Optional argument OBJECT is the string or buffer containing the text."
1071 (let ((start (text-property-any start end prop nil object)) next)
1072 (while start
1073 (setq next (next-single-property-change start prop object end))
1074 (put-text-property start next prop value object)
1075 (setq start (text-property-any next end prop nil object)))))
1076
1077;; For completeness: this is to `remove-text-properties' as `put-text-property'
1078;; is to `add-text-properties', etc.
1079;(defun remove-text-property (start end property &optional object)
1080; "Remove a property from text from START to END.
1081;Argument PROPERTY is the property to remove.
1082;Optional argument OBJECT is the string or buffer containing the text.
1083;Return t if the property was actually removed, nil otherwise."
1084; (remove-text-properties start end (list property) object))
1085
1086;; For consistency: maybe this should be called `remove-single-property' like
1087;; `next-single-property-change' (not `next-single-text-property-change'), etc.
1088;(defun remove-single-text-property (start end prop value &optional object)
1089; "Remove a specific property value from text from START to END.
1090;Arguments PROP and VALUE specify the property and value to remove. The
1091;resulting property values are not equal to VALUE nor lists containing VALUE.
1092;Optional argument OBJECT is the string or buffer containing the text."
1093; (let ((start (text-property-not-all start end prop nil object)) next prev)
1094; (while start
1095; (setq next (next-single-property-change start prop object end)
1096; prev (get-text-property start prop object))
1097; (cond ((and (symbolp prev) (eq value prev))
1098; (remove-text-property start next prop object))
1099; ((and (listp prev) (memq value prev))
1100; (let ((new (delq value prev)))
1101; (cond ((null new)
1102; (remove-text-property start next prop object))
1103; ((= (length new) 1)
1104; (put-text-property start next prop (car new) object))
1105; (t
1106; (put-text-property start next prop new object))))))
1107; (setq start (text-property-not-all next end prop nil object)))))
2d63aa67
SM
1108
1109;;; End of Additional text property functions.
9bfbb130 1110\f
ac6e572c
SM
1111;;; Syntactic regexp fontification functions.
1112
1113;; These syntactic keyword pass functions are identical to those keyword pass
1114;; functions below, with the following exceptions; (a) they operate on
1115;; `font-lock-syntactic-keywords' of course, (b) they are all `defun' as speed
1116;; is less of an issue, (c) eval of property value does not occur JIT as speed
1117;; is less of an issue, (d) OVERRIDE cannot be `prepend' or `append' as it
1118;; makes no sense for `syntax-table' property values, (e) they do not do it
1119;; LOUDLY as it is not likely to be intensive.
1120
1121(defun font-lock-apply-syntactic-highlight (highlight)
1122 "Apply HIGHLIGHT following a match.
1123HIGHLIGHT should be of the form MATCH-HIGHLIGHT,
1124see `font-lock-syntactic-keywords'."
1125 (let* ((match (nth 0 highlight))
1126 (start (match-beginning match)) (end (match-end match))
1127 (value (nth 1 highlight))
1128 (override (nth 2 highlight)))
8259bf10
SM
1129 (if (not start)
1130 ;; No match but we might not signal an error.
1131 (or (nth 3 highlight)
1132 (error "No match %d in highlight %S" match highlight))
1133 (when (and (consp value) (not (numberp (car value))))
1134 (setq value (eval value)))
1135 (when (stringp value) (setq value (string-to-syntax value)))
1136 ;; Flush the syntax-cache. I believe this is not necessary for
1137 ;; font-lock's use of syntax-ppss, but I'm not 100% sure and it can
1138 ;; still be necessary for other users of syntax-ppss anyway.
1139 (syntax-ppss-after-change-function start)
1140 (cond
1141 ((not override)
1142 ;; Cannot override existing fontification.
1143 (or (text-property-not-all start end 'syntax-table nil)
1144 (put-text-property start end 'syntax-table value)))
1145 ((eq override t)
1146 ;; Override existing fontification.
1147 (put-text-property start end 'syntax-table value))
1148 ((eq override 'keep)
1149 ;; Keep existing fontification.
1150 (font-lock-fillin-text-property start end 'syntax-table value))))))
ac6e572c
SM
1151
1152(defun font-lock-fontify-syntactic-anchored-keywords (keywords limit)
1153 "Fontify according to KEYWORDS until LIMIT.
1154KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords',
1155LIMIT can be modified by the value of its PRE-MATCH-FORM."
1156 (let ((matcher (nth 0 keywords)) (lowdarks (nthcdr 3 keywords)) highlights
1157 ;; Evaluate PRE-MATCH-FORM.
1158 (pre-match-value (eval (nth 1 keywords))))
1159 ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line.
1160 (if (and (numberp pre-match-value) (> pre-match-value (point)))
1161 (setq limit pre-match-value)
6e1d0d15 1162 (setq limit (line-end-position)))
ac6e572c
SM
1163 (save-match-data
1164 ;; Find an occurrence of `matcher' before `limit'.
1165 (while (if (stringp matcher)
1166 (re-search-forward matcher limit t)
1167 (funcall matcher limit))
1168 ;; Apply each highlight to this instance of `matcher'.
1169 (setq highlights lowdarks)
1170 (while highlights
1171 (font-lock-apply-syntactic-highlight (car highlights))
1172 (setq highlights (cdr highlights)))))
1173 ;; Evaluate POST-MATCH-FORM.
1174 (eval (nth 2 keywords))))
1175
1176(defun font-lock-fontify-syntactic-keywords-region (start end)
1177 "Fontify according to `font-lock-syntactic-keywords' between START and END.
1178START should be at the beginning of a line."
c0a6a9fe
SM
1179 ;; Ensure the beginning of the file is properly syntactic-fontified.
1180 (when (and font-lock-syntactically-fontified
1181 (< font-lock-syntactically-fontified start))
1182 (setq start (max font-lock-syntactically-fontified (point-min)))
1183 (setq font-lock-syntactically-fontified end))
ac6e572c
SM
1184 ;; If `font-lock-syntactic-keywords' is a symbol, get the real keywords.
1185 (when (symbolp font-lock-syntactic-keywords)
1186 (setq font-lock-syntactic-keywords (font-lock-eval-keywords
1187 font-lock-syntactic-keywords)))
1188 ;; If `font-lock-syntactic-keywords' is not compiled, compile it.
1189 (unless (eq (car font-lock-syntactic-keywords) t)
1190 (setq font-lock-syntactic-keywords (font-lock-compile-keywords
1191 font-lock-syntactic-keywords)))
1192 ;; Get down to business.
1193 (let ((case-fold-search font-lock-keywords-case-fold-search)
1194 (keywords (cdr font-lock-syntactic-keywords))
1195 keyword matcher highlights)
1196 (while keywords
1197 ;; Find an occurrence of `matcher' from `start' to `end'.
1198 (setq keyword (car keywords) matcher (car keyword))
1199 (goto-char start)
1200 (while (if (stringp matcher)
1201 (re-search-forward matcher end t)
1202 (funcall matcher end))
1203 ;; Apply each highlight to this instance of `matcher', which may be
1204 ;; specific highlights or more keywords anchored to `matcher'.
1205 (setq highlights (cdr keyword))
1206 (while highlights
1207 (if (numberp (car (car highlights)))
1208 (font-lock-apply-syntactic-highlight (car highlights))
1209 (font-lock-fontify-syntactic-anchored-keywords (car highlights)
1210 end))
1211 (setq highlights (cdr highlights))))
1212 (setq keywords (cdr keywords)))))
1213
1214;;; End of Syntactic regexp fontification functions.
1215\f
1216;;; Syntactic fontification functions.
1217
8259bf10 1218(defun font-lock-fontify-syntactically-region (start end &optional loudly ppss)
ac6e572c
SM
1219 "Put proper face on each string and comment between START and END.
1220START should be at the beginning of a line."
8259bf10 1221 (let (state face beg)
ac6e572c
SM
1222 (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name)))
1223 (goto-char start)
1224 ;;
1225 ;; Find the state at the `beginning-of-line' before `start'.
47fc2db3 1226 (setq state (or ppss (syntax-ppss start)))
ac6e572c
SM
1227 ;;
1228 ;; Find each interesting place between here and `end'.
8259bf10
SM
1229 (while
1230 (progn
1231 (when (or (nth 3 state) (nth 4 state))
1232 (setq face (funcall font-lock-syntactic-face-function state))
1233 (setq beg (max (nth 8 state) start))
1234 (setq state (parse-partial-sexp (point) end nil nil state
1235 'syntax-table))
1236 (when face (put-text-property beg (point) 'face face)))
1237 (setq state (parse-partial-sexp (point) end nil nil state
1238 'syntax-table))
1239 (< (point) end)))))
ac6e572c
SM
1240
1241;;; End of Syntactic fontification functions.
1242\f
1243;;; Keyword regexp fontification functions.
9bfbb130
SM
1244
1245(defsubst font-lock-apply-highlight (highlight)
1246 "Apply HIGHLIGHT following a match.
1247HIGHLIGHT should be of the form MATCH-HIGHLIGHT, see `font-lock-keywords'."
1248 (let* ((match (nth 0 highlight))
1249 (start (match-beginning match)) (end (match-end match))
1250 (override (nth 2 highlight)))
8259bf10
SM
1251 (if (not start)
1252 ;; No match but we might not signal an error.
1253 (or (nth 3 highlight)
1254 (error "No match %d in highlight %S" match highlight))
1255 (let ((val (eval (nth 1 highlight))))
1256 (when (eq (car-safe val) 'face)
1257 (add-text-properties start end (cddr val))
1258 (setq val (cadr val)))
1259 (cond
1260 ((not override)
1261 ;; Cannot override existing fontification.
1262 (or (text-property-not-all start end 'face nil)
1263 (put-text-property start end 'face val)))
1264 ((eq override t)
1265 ;; Override existing fontification.
1266 (put-text-property start end 'face val))
1267 ((eq override 'prepend)
1268 ;; Prepend to existing fontification.
1269 (font-lock-prepend-text-property start end 'face val))
1270 ((eq override 'append)
1271 ;; Append to existing fontification.
1272 (font-lock-append-text-property start end 'face val))
1273 ((eq override 'keep)
1274 ;; Keep existing fontification.
1275 (font-lock-fillin-text-property start end 'face val)))))))
9bfbb130
SM
1276
1277(defsubst font-lock-fontify-anchored-keywords (keywords limit)
1278 "Fontify according to KEYWORDS until LIMIT.
56fcbd7e
SM
1279KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords',
1280LIMIT can be modified by the value of its PRE-MATCH-FORM."
1281 (let ((matcher (nth 0 keywords)) (lowdarks (nthcdr 3 keywords)) highlights
fb0e4f8a 1282 (lead-start (match-beginning 0))
56fcbd7e
SM
1283 ;; Evaluate PRE-MATCH-FORM.
1284 (pre-match-value (eval (nth 1 keywords))))
1285 ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line.
fb0e4f8a 1286 (if (not (and (numberp pre-match-value) (> pre-match-value (point))))
6e1d0d15 1287 (setq limit (line-end-position))
fb0e4f8a 1288 (setq limit pre-match-value)
ba22aeff 1289 (when (and font-lock-multiline (>= limit (line-beginning-position 2)))
fb0e4f8a 1290 ;; this is a multiline anchored match
ba22aeff
SM
1291 ;; (setq font-lock-multiline t)
1292 (put-text-property (if (= limit (line-beginning-position 2))
1293 (1- limit)
1294 (min lead-start (point)))
1295 limit
28a53bc1 1296 'font-lock-multiline t)))
9bfbb130 1297 (save-match-data
876f2438 1298 ;; Find an occurrence of `matcher' before `limit'.
afa18a4e
SM
1299 (while (and (< (point) limit)
1300 (if (stringp matcher)
1301 (re-search-forward matcher limit t)
1302 (funcall matcher limit)))
876f2438 1303 ;; Apply each highlight to this instance of `matcher'.
9bfbb130
SM
1304 (setq highlights lowdarks)
1305 (while highlights
1306 (font-lock-apply-highlight (car highlights))
1307 (setq highlights (cdr highlights)))))
876f2438 1308 ;; Evaluate POST-MATCH-FORM.
9bfbb130
SM
1309 (eval (nth 2 keywords))))
1310
1311(defun font-lock-fontify-keywords-region (start end &optional loudly)
1312 "Fontify according to `font-lock-keywords' between START and END.
1313START should be at the beginning of a line."
ac6e572c 1314 (unless (eq (car font-lock-keywords) t)
2d5eba0e
SM
1315 (setq font-lock-keywords
1316 (font-lock-compile-keywords font-lock-keywords t)))
9bfbb130 1317 (let ((case-fold-search font-lock-keywords-case-fold-search)
55015061 1318 (keywords (cdr font-lock-keywords))
9bfbb130 1319 (bufname (buffer-name)) (count 0)
876f2438
SM
1320 keyword matcher highlights)
1321 ;;
1322 ;; Fontify each item in `font-lock-keywords' from `start' to `end'.
1323 (while keywords
1324 (if loudly (message "Fontifying %s... (regexps..%s)" bufname
2e6a15fc 1325 (make-string (incf count) ?.)))
9bfbb130 1326 ;;
876f2438
SM
1327 ;; Find an occurrence of `matcher' from `start' to `end'.
1328 (setq keyword (car keywords) matcher (car keyword))
1329 (goto-char start)
e7f07c2c
GM
1330 (while (and (< (point) end)
1331 (if (stringp matcher)
1332 (re-search-forward matcher end t)
1333 (funcall matcher end)))
041470d2 1334 (when (and font-lock-multiline
ba22aeff
SM
1335 (>= (point)
1336 (save-excursion (goto-char (match-beginning 0))
1337 (forward-line 1) (point))))
fb0e4f8a 1338 ;; this is a multiline regexp match
ba22aeff
SM
1339 ;; (setq font-lock-multiline t)
1340 (put-text-property (if (= (point)
1341 (save-excursion
1342 (goto-char (match-beginning 0))
1343 (forward-line 1) (point)))
1344 (1- (point))
1345 (match-beginning 0))
1346 (point)
fb0e4f8a 1347 'font-lock-multiline t))
876f2438
SM
1348 ;; Apply each highlight to this instance of `matcher', which may be
1349 ;; specific highlights or more keywords anchored to `matcher'.
1350 (setq highlights (cdr keyword))
1351 (while highlights
1352 (if (numberp (car (car highlights)))
1353 (font-lock-apply-highlight (car highlights))
1354 (font-lock-fontify-anchored-keywords (car highlights) end))
1355 (setq highlights (cdr highlights))))
1356 (setq keywords (cdr keywords)))))
2d63aa67 1357
ac6e572c 1358;;; End of Keyword regexp fontification functions.
9bfbb130
SM
1359\f
1360;; Various functions.
1361
2d5eba0e 1362(defun font-lock-compile-keywords (keywords &optional regexp)
019f00d8
DL
1363 "Compile KEYWORDS into the form (t KEYWORD ...).
1364Here KEYWORD is of the form (MATCHER HIGHLIGHT ...) as shown in the
2d5eba0e
SM
1365`font-lock-keywords' doc string.
1366If REGEXP is non-nil, it means these keywords are used for
1367`font-lock-keywords' rather than for `font-lock-syntactic-keywords'."
55015061
SM
1368 (if (eq (car-safe keywords) t)
1369 keywords
2d5eba0e
SM
1370 (setq keywords (cons t (mapcar 'font-lock-compile-keyword keywords)))
1371 (if (and regexp
1372 (eq (or syntax-begin-function
1373 font-lock-beginning-of-syntax-function)
1374 'beginning-of-defun)
1375 (not beginning-of-defun-function))
1376 ;; Try to detect when a string or comment contains something that
1377 ;; looks like a defun and would thus confuse font-lock.
1378 (nconc keywords
1379 `((,(if defun-prompt-regexp
1380 (concat "^\\(?:" defun-prompt-regexp "\\)?\\s(")
1381 "^\\s(")
1382 (0
47fc2db3 1383 (if (memq (get-text-property (1- (point)) 'face)
2d5eba0e
SM
1384 '(font-lock-string-face font-lock-doc-face
1385 font-lock-comment-face))
1386 font-lock-warning-face)
1387 prepend)))))
1388 keywords))
a2b8e66b
SM
1389
1390(defun font-lock-compile-keyword (keyword)
c1f2ffc8 1391 (cond ((nlistp keyword) ; MATCHER
a2b8e66b 1392 (list keyword '(0 font-lock-keyword-face)))
c1f2ffc8 1393 ((eq (car keyword) 'eval) ; (eval . FORM)
a2b8e66b 1394 (font-lock-compile-keyword (eval (cdr keyword))))
c1f2ffc8
SM
1395 ((eq (car-safe (cdr keyword)) 'quote) ; (MATCHER . 'FORM)
1396 ;; If FORM is a FACENAME then quote it. Otherwise ignore the quote.
1397 (if (symbolp (nth 2 keyword))
1398 (list (car keyword) (list 0 (cdr keyword)))
1399 (font-lock-compile-keyword (cons (car keyword) (nth 2 keyword)))))
1400 ((numberp (cdr keyword)) ; (MATCHER . MATCH)
a2b8e66b 1401 (list (car keyword) (list (cdr keyword) 'font-lock-keyword-face)))
c1f2ffc8 1402 ((symbolp (cdr keyword)) ; (MATCHER . FACENAME)
a2b8e66b 1403 (list (car keyword) (list 0 (cdr keyword))))
c1f2ffc8 1404 ((nlistp (nth 1 keyword)) ; (MATCHER . HIGHLIGHT)
a2b8e66b 1405 (list (car keyword) (cdr keyword)))
c1f2ffc8 1406 (t ; (MATCHER HIGHLIGHT ...)
a2b8e66b 1407 keyword)))
d46c21ec 1408
ac6e572c 1409(defun font-lock-eval-keywords (keywords)
019f00d8 1410 "Evalulate KEYWORDS if a function (funcall) or variable (eval) name."
46f26fcf
SM
1411 (if (listp keywords)
1412 keywords
1413 (font-lock-eval-keywords (if (fboundp keywords)
1414 (funcall keywords)
1415 (eval keywords)))))
ac6e572c 1416
343204bd 1417(defun font-lock-value-in-major-mode (alist)
019f00d8
DL
1418 "Return value in ALIST for `major-mode', or ALIST if it is not an alist.
1419Structure is ((MAJOR-MODE . VALUE) ...) where MAJOR-MODE may be t."
343204bd
SM
1420 (if (consp alist)
1421 (cdr (or (assq major-mode alist) (assq t alist)))
1422 alist))
1423
d46c21ec 1424(defun font-lock-choose-keywords (keywords level)
019f00d8
DL
1425 "Return LEVELth element of KEYWORDS.
1426A LEVEL of nil is equal to a LEVEL of 0, a LEVEL of t is equal to
1427\(1- (length KEYWORDS))."
fd612dd9 1428 (cond ((not (and (listp keywords) (symbolp (car keywords))))
343204bd
SM
1429 keywords)
1430 ((numberp level)
1431 (or (nth level keywords) (car (reverse keywords))))
1432 ((eq level t)
1433 (car (reverse keywords)))
1434 (t
1435 (car keywords))))
d46c21ec 1436
53785d2b
CW
1437(defun font-lock-set-defaults-1 ()
1438 (let* ((defaults (or font-lock-defaults
1439 (cdr (assq major-mode font-lock-defaults-alist))))
1440 (keywords
1441 (font-lock-choose-keywords (nth 0 defaults)
1442 (font-lock-value-in-major-mode font-lock-maximum-decoration)))
1443 (local (cdr (assq major-mode font-lock-keywords-alist)))
1444 (removed-keywords
1445 (cdr-safe (assq major-mode font-lock-removed-keywords-alist))))
1446 (set (make-local-variable 'font-lock-defaults) defaults)
1447 ;; Syntactic fontification?
1448 (when (nth 1 defaults)
1449 (set (make-local-variable 'font-lock-keywords-only) t))
1450 ;; Case fold during regexp fontification?
1451 (when (nth 2 defaults)
1452 (set (make-local-variable 'font-lock-keywords-case-fold-search) t))
1453 ;; Syntax table for regexp and syntactic fontification?
1454 (when (nth 3 defaults)
1455 (set (make-local-variable 'font-lock-syntax-table)
1456 (copy-syntax-table (syntax-table)))
1457 (dolist (selem (nth 3 defaults))
1458 ;; The character to modify may be a single CHAR or a STRING.
1459 (let ((syntax (cdr selem)))
1460 (dolist (char (if (numberp (car selem))
1461 (list (car selem))
1462 (mapcar 'identity (car selem))))
1463 (modify-syntax-entry char syntax font-lock-syntax-table)))))
1464 ;; Syntax function for syntactic fontification?
1465 (when (nth 4 defaults)
1466 (set (make-local-variable 'font-lock-beginning-of-syntax-function)
1467 (nth 4 defaults)))
93e5c2b5
CW
1468 ;; Variable alist?
1469 (dolist (x (nthcdr 5 defaults))
1470 (set (make-local-variable (car x)) (cdr x)))
53785d2b
CW
1471 ;; Setup `font-lock-keywords' last because its value might depend
1472 ;; on other settings (e.g. font-lock-compile-keywords uses
1473 ;; font-lock-beginning-of-syntax-function).
1474 (set (make-local-variable 'font-lock-keywords)
1475 (font-lock-compile-keywords (font-lock-eval-keywords keywords) t))
1476 ;; Local fontification?
1477 (while local
1478 (font-lock-add-keywords nil (car (car local)) (cdr (car local)))
1479 (setq local (cdr local)))
1480 (when removed-keywords
1481 (font-lock-remove-keywords nil removed-keywords))))
030f4a35 1482\f
2d63aa67 1483;;; Colour etc. support.
9bfbb130 1484
2273c36b 1485;; Originally face attributes were specified via `font-lock-face-attributes'.
23a0e11b 1486;; Users then changed the default face attributes by setting that variable.
2273c36b
SM
1487;; However, we try and be back-compatible and respect its value if set except
1488;; for faces where M-x customize has been used to save changes for the face.
1489(when (boundp 'font-lock-face-attributes)
1490 (let ((face-attributes font-lock-face-attributes))
1491 (while face-attributes
1492 (let* ((face-attribute (pop face-attributes))
1493 (face (car face-attribute)))
1494 ;; Rustle up a `defface' SPEC from a `font-lock-face-attributes' entry.
1495 (unless (get face 'saved-face)
1496 (let ((foreground (nth 1 face-attribute))
1497 (background (nth 2 face-attribute))
1498 (bold-p (nth 3 face-attribute))
1499 (italic-p (nth 4 face-attribute))
1500 (underline-p (nth 5 face-attribute))
1501 face-spec)
1502 (when foreground
1503 (setq face-spec (cons ':foreground (cons foreground face-spec))))
1504 (when background
1505 (setq face-spec (cons ':background (cons background face-spec))))
1506 (when bold-p
0cccb49d 1507 (setq face-spec (append '(:weight bold) face-spec)))
2273c36b 1508 (when italic-p
0cccb49d 1509 (setq face-spec (append '(:slant italic) face-spec)))
2273c36b
SM
1510 (when underline-p
1511 (setq face-spec (append '(:underline t) face-spec)))
1512 (custom-declare-face face (list (list t face-spec)) nil)))))))
1513
1514;; But now we do it the custom way. Note that `defface' will not overwrite any
1515;; faces declared above via `custom-declare-face'.
55015061 1516(defface font-lock-comment-face
8379c868 1517 '((((type tty pc) (class color) (background light)) (:foreground "red"))
ce6b1982 1518 (((type tty pc) (class color) (background dark)) (:foreground "red1"))
e7f07c2c 1519 (((class grayscale) (background light))
0cccb49d 1520 (:foreground "DimGray" :weight bold :slant italic))
55015061 1521 (((class grayscale) (background dark))
0cccb49d 1522 (:foreground "LightGray" :weight bold :slant italic))
55015061 1523 (((class color) (background light)) (:foreground "Firebrick"))
86b7fcbb 1524 (((class color) (background dark)) (:foreground "chocolate1"))
0cccb49d 1525 (t (:weight bold :slant italic)))
55015061 1526 "Font Lock mode face used to highlight comments."
2273c36b 1527 :group 'font-lock-highlighting-faces)
55015061
SM
1528
1529(defface font-lock-string-face
e7f07c2c 1530 '((((type tty) (class color)) (:foreground "green"))
0cccb49d
RS
1531 (((class grayscale) (background light)) (:foreground "DimGray" :slant italic))
1532 (((class grayscale) (background dark)) (:foreground "LightGray" :slant italic))
55015061
SM
1533 (((class color) (background light)) (:foreground "RosyBrown"))
1534 (((class color) (background dark)) (:foreground "LightSalmon"))
0cccb49d 1535 (t (:slant italic)))
55015061 1536 "Font Lock mode face used to highlight strings."
2273c36b 1537 :group 'font-lock-highlighting-faces)
55015061 1538
1c172af4
SM
1539(defface font-lock-doc-face
1540 '((t :inherit font-lock-string-face))
1541 "Font Lock mode face used to highlight documentation."
1542 :group 'font-lock-highlighting-faces)
1543
55015061 1544(defface font-lock-keyword-face
e7f07c2c 1545 '((((type tty) (class color)) (:foreground "cyan" :weight bold))
0cccb49d
RS
1546 (((class grayscale) (background light)) (:foreground "LightGray" :weight bold))
1547 (((class grayscale) (background dark)) (:foreground "DimGray" :weight bold))
55015061
SM
1548 (((class color) (background light)) (:foreground "Purple"))
1549 (((class color) (background dark)) (:foreground "Cyan"))
0cccb49d 1550 (t (:weight bold)))
55015061 1551 "Font Lock mode face used to highlight keywords."
2273c36b 1552 :group 'font-lock-highlighting-faces)
55015061
SM
1553
1554(defface font-lock-builtin-face
e7f07c2c 1555 '((((type tty) (class color)) (:foreground "blue" :weight light))
0cccb49d
RS
1556 (((class grayscale) (background light)) (:foreground "LightGray" :weight bold))
1557 (((class grayscale) (background dark)) (:foreground "DimGray" :weight bold))
55015061
SM
1558 (((class color) (background light)) (:foreground "Orchid"))
1559 (((class color) (background dark)) (:foreground "LightSteelBlue"))
0cccb49d 1560 (t (:weight bold)))
55015061 1561 "Font Lock mode face used to highlight builtins."
2273c36b 1562 :group 'font-lock-highlighting-faces)
55015061
SM
1563
1564(defface font-lock-function-name-face
e7f07c2c
GM
1565 '((((type tty) (class color)) (:foreground "blue" :weight bold))
1566 (((class color) (background light)) (:foreground "Blue"))
55015061 1567 (((class color) (background dark)) (:foreground "LightSkyBlue"))
0cccb49d 1568 (t (:inverse-video t :weight bold)))
55015061 1569 "Font Lock mode face used to highlight function names."
2273c36b 1570 :group 'font-lock-highlighting-faces)
55015061
SM
1571
1572(defface font-lock-variable-name-face
e7f07c2c
GM
1573 '((((type tty) (class color)) (:foreground "yellow" :weight light))
1574 (((class grayscale) (background light))
0cccb49d 1575 (:foreground "Gray90" :weight bold :slant italic))
55015061 1576 (((class grayscale) (background dark))
0cccb49d 1577 (:foreground "DimGray" :weight bold :slant italic))
55015061
SM
1578 (((class color) (background light)) (:foreground "DarkGoldenrod"))
1579 (((class color) (background dark)) (:foreground "LightGoldenrod"))
0cccb49d 1580 (t (:weight bold :slant italic)))
55015061 1581 "Font Lock mode face used to highlight variable names."
2273c36b 1582 :group 'font-lock-highlighting-faces)
55015061
SM
1583
1584(defface font-lock-type-face
e7f07c2c 1585 '((((type tty) (class color)) (:foreground "green"))
0cccb49d
RS
1586 (((class grayscale) (background light)) (:foreground "Gray90" :weight bold))
1587 (((class grayscale) (background dark)) (:foreground "DimGray" :weight bold))
46f26fcf 1588 (((class color) (background light)) (:foreground "ForestGreen"))
55015061 1589 (((class color) (background dark)) (:foreground "PaleGreen"))
0cccb49d 1590 (t (:weight bold :underline t)))
8acf2292 1591 "Font Lock mode face used to highlight type and classes."
2273c36b 1592 :group 'font-lock-highlighting-faces)
55015061 1593
8acf2292 1594(defface font-lock-constant-face
e7f07c2c
GM
1595 '((((type tty) (class color)) (:foreground "magenta"))
1596 (((class grayscale) (background light))
0cccb49d 1597 (:foreground "LightGray" :weight bold :underline t))
55015061 1598 (((class grayscale) (background dark))
0cccb49d 1599 (:foreground "Gray50" :weight bold :underline t))
55015061
SM
1600 (((class color) (background light)) (:foreground "CadetBlue"))
1601 (((class color) (background dark)) (:foreground "Aquamarine"))
0cccb49d 1602 (t (:weight bold :underline t)))
8acf2292 1603 "Font Lock mode face used to highlight constants and labels."
2273c36b 1604 :group 'font-lock-highlighting-faces)
55015061
SM
1605
1606(defface font-lock-warning-face
e7f07c2c 1607 '((((type tty) (class color)) (:foreground "red"))
0cccb49d
RS
1608 (((class color) (background light)) (:foreground "Red" :weight bold))
1609 (((class color) (background dark)) (:foreground "Pink" :weight bold))
1610 (t (:inverse-video t :weight bold)))
55015061 1611 "Font Lock mode face used to highlight warnings."
2273c36b 1612 :group 'font-lock-highlighting-faces)
2d63aa67
SM
1613
1614;;; End of Colour etc. support.
9bfbb130 1615\f
56fcbd7e
SM
1616;;; Menu support.
1617
1618;; This section of code is commented out because Emacs does not have real menu
1619;; buttons. (We can mimic them by putting "( ) " or "(X) " at the beginning of
1620;; the menu entry text, but with Xt it looks both ugly and embarrassingly
1621;; amateur.) If/When Emacs gets real menus buttons, put in menu-bar.el after
1622;; the entry for "Text Properties" something like:
1623;;
1624;; (define-key menu-bar-edit-menu [font-lock]
9c8de95c 1625;; (cons "Syntax Highlighting" font-lock-menu))
56fcbd7e
SM
1626;;
1627;; and remove a single ";" from the beginning of each line in the rest of this
1628;; section. Probably the mechanism for telling the menu code what are menu
1629;; buttons and when they are on or off needs tweaking. I have assumed that the
1630;; mechanism is via `menu-toggle' and `menu-selected' symbol properties. sm.
1631
1632;;;;###autoload
1633;(progn
1634; ;; Make the Font Lock menu.
1635; (defvar font-lock-menu (make-sparse-keymap "Syntax Highlighting"))
1636; ;; Add the menu items in reverse order.
1637; (define-key font-lock-menu [fontify-less]
1638; '("Less In Current Buffer" . font-lock-fontify-less))
1639; (define-key font-lock-menu [fontify-more]
1640; '("More In Current Buffer" . font-lock-fontify-more))
1641; (define-key font-lock-menu [font-lock-sep]
1642; '("--"))
1643; (define-key font-lock-menu [font-lock-mode]
1644; '("In Current Buffer" . font-lock-mode))
1645; (define-key font-lock-menu [global-font-lock-mode]
1646; '("In All Buffers" . global-font-lock-mode)))
1647;
1648;;;;###autoload
1649;(progn
1650; ;; We put the appropriate `menu-enable' etc. symbol property values on when
1651; ;; font-lock.el is loaded, so we don't need to autoload the three variables.
1652; (put 'global-font-lock-mode 'menu-toggle t)
1653; (put 'font-lock-mode 'menu-toggle t)
1654; (put 'font-lock-fontify-more 'menu-enable '(identity))
1655; (put 'font-lock-fontify-less 'menu-enable '(identity)))
1656;
1657;;; Put the appropriate symbol property values on now. See above.
9c8de95c 1658;(put 'global-font-lock-mode 'menu-selected 'global-font-lock-mode)
56fcbd7e
SM
1659;(put 'font-lock-mode 'menu-selected 'font-lock-mode)
1660;(put 'font-lock-fontify-more 'menu-enable '(nth 2 font-lock-fontify-level))
1661;(put 'font-lock-fontify-less 'menu-enable '(nth 1 font-lock-fontify-level))
1662;
1663;(defvar font-lock-fontify-level nil) ; For less/more fontification.
1664;
1665;(defun font-lock-fontify-level (level)
1666; (let ((font-lock-maximum-decoration level))
1667; (when font-lock-mode
1668; (font-lock-mode))
1669; (font-lock-mode)
1670; (when font-lock-verbose
1671; (message "Fontifying %s... level %d" (buffer-name) level))))
1672;
1673;(defun font-lock-fontify-less ()
1674; "Fontify the current buffer with less decoration.
1675;See `font-lock-maximum-decoration'."
1676; (interactive)
1677; ;; Check in case we get called interactively.
1678; (if (nth 1 font-lock-fontify-level)
1679; (font-lock-fontify-level (1- (car font-lock-fontify-level)))
1680; (error "No less decoration")))
1681;
1682;(defun font-lock-fontify-more ()
1683; "Fontify the current buffer with more decoration.
1684;See `font-lock-maximum-decoration'."
1685; (interactive)
1686; ;; Check in case we get called interactively.
1687; (if (nth 2 font-lock-fontify-level)
1688; (font-lock-fontify-level (1+ (car font-lock-fontify-level)))
1689; (error "No more decoration")))
1690;
1691;;; This should be called by `font-lock-set-defaults'.
1692;(defun font-lock-set-menu ()
1693; ;; Activate less/more fontification entries if there are multiple levels for
1694; ;; the current buffer. Sets `font-lock-fontify-level' to be of the form
1695; ;; (CURRENT-LEVEL IS-LOWER-LEVEL-P IS-HIGHER-LEVEL-P) for menu activation.
1696; (let ((keywords (or (nth 0 font-lock-defaults)
1697; (nth 1 (assq major-mode font-lock-defaults-alist))))
1698; (level (font-lock-value-in-major-mode font-lock-maximum-decoration)))
1699; (make-local-variable 'font-lock-fontify-level)
1700; (if (or (symbolp keywords) (= (length keywords) 1))
1701; (font-lock-unset-menu)
1702; (cond ((eq level t)
1703; (setq level (1- (length keywords))))
1704; ((or (null level) (zerop level))
1705; ;; The default level is usually, but not necessarily, level 1.
1706; (setq level (- (length keywords)
1707; (length (member (eval (car keywords))
1708; (mapcar 'eval (cdr keywords))))))))
1709; (setq font-lock-fontify-level (list level (> level 1)
1710; (< level (1- (length keywords))))))))
1711;
1712;;; This should be called by `font-lock-unset-defaults'.
1713;(defun font-lock-unset-menu ()
1714; ;; Deactivate less/more fontification entries.
1715; (setq font-lock-fontify-level nil))
2d63aa67
SM
1716
1717;;; End of Menu support.
56fcbd7e 1718\f
9bfbb130 1719;;; Various regexp information shared by several modes.
a1eb1cf1 1720;;; Information specific to a single mode should go in its load library.
030f4a35 1721
1c626aaf 1722;; Font Lock support for C, C++, Objective-C and Java modes will one day be in
56fcbd7e
SM
1723;; some cc-font.el (and required by cc-mode.el). However, the below function
1724;; should stay in font-lock.el, since it is used by other libraries. sm.
2e6a15fc 1725
c1f2ffc8 1726(defun font-lock-match-c-style-declaration-item-and-skip-to-next (limit)
2e6a15fc 1727 "Match, and move over, any declaration/definition item after point.
c1f2ffc8
SM
1728Matches after point, but ignores leading whitespace and `*' characters.
1729Does not move further than LIMIT.
1730
ac6e572c
SM
1731The expected syntax of a declaration/definition item is `word' (preceded by
1732optional whitespace and `*' characters and proceeded by optional whitespace)
1733optionally followed by a `('. Everything following the item (but belonging to
1734it) is expected to by skip-able by `scan-sexps', and items are expected to be
1735separated with a `,' and to be terminated with a `;'.
c1f2ffc8
SM
1736
1737Thus the regexp matches after point: word (
1738 ^^^^ ^
1739Where the match subexpressions are: 1 2
1740
1741The item is delimited by (match-beginning 1) and (match-end 1).
1742If (match-beginning 2) is non-nil, the item is followed by a `('.
1743
1744This function could be MATCHER in a MATCH-ANCHORED `font-lock-keywords' item."
c1966bb4 1745 (when (looking-at "[ \n\t*]*\\(\\sw+\\)[ \t\n]*\\(((?\\)?")
8259bf10
SM
1746 (when (and (match-end 2) (> (- (match-end 2) (match-beginning 2)) 1))
1747 ;; If `word' is followed by a double open-paren, it's probably
1748 ;; a macro used for "int myfun P_ ((int arg1))". Let's go back one
1749 ;; word to try and match `myfun' rather than `P_'.
1750 (let ((pos (point)))
c1966bb4 1751 (skip-chars-backward " \t\n")
8259bf10 1752 (skip-syntax-backward "w")
c1966bb4 1753 (unless (looking-at "\\(\\sw+\\)[ \t\n]*\\sw*_\\sw*[ \t\n]*\\((\\)?")
8259bf10
SM
1754 ;; Looks like it was something else, so go back to where we
1755 ;; were and reset the match data by rematching.
1756 (goto-char pos)
c1966bb4 1757 (looking-at "[ \n\t*]*\\(\\sw+\\)[ \t\n]*\\(((?\\)?"))))
2e6a15fc
SM
1758 (save-match-data
1759 (condition-case nil
1760 (save-restriction
c1966bb4 1761 ;; Restrict to the LIMIT.
2e6a15fc
SM
1762 (narrow-to-region (point-min) limit)
1763 (goto-char (match-end 1))
1764 ;; Move over any item value, etc., to the next item.
c1966bb4 1765 (while (not (looking-at "[ \t\n]*\\(\\(,\\)\\|;\\|\\'\\)"))
2e6a15fc
SM
1766 (goto-char (or (scan-sexps (point) 1) (point-max))))
1767 (goto-char (match-end 2)))
1768 (error t)))))
46f26fcf
SM
1769\f
1770;; Lisp.
2e6a15fc 1771
030f4a35 1772(defconst lisp-font-lock-keywords-1
2e6a15fc
SM
1773 (eval-when-compile
1774 (list
2d63aa67 1775 ;;
55015061
SM
1776 ;; Definitions.
1777 (list (concat "(\\(def\\("
1778 ;; Function declarations.
7c5312b2 1779 "\\(advice\\|varalias\\|alias\\|generic\\|macro\\*?\\|method\\|"
4fffc071 1780 "setf\\|subst\\*?\\|un\\*?\\|"
1a5c5f2e 1781 "ine-\\(condition\\|\\(?:derived\\|minor\\)-mode\\|"
4fffc071 1782 "method-combination\\|setf-expander\\|skeleton\\|widget\\|"
1a5c5f2e 1783 "function\\|\\(compiler\\|modify\\|symbol\\)-macro\\)\\)\\|"
2e6a15fc 1784 ;; Variable declarations.
4fffc071 1785 "\\(const\\(ant\\)?\\|custom\\|face\\|parameter\\|var\\)\\|"
2e6a15fc 1786 ;; Structure declarations.
5bbc1cf7 1787 "\\(class\\|group\\|package\\|struct\\|type\\)"
2e6a15fc 1788 "\\)\\)\\>"
55015061 1789 ;; Any whitespace and defined object.
2e6a15fc 1790 "[ \t'\(]*"
11b42ef4 1791 "\\(setf[ \t]+\\sw+)\\|\\sw+\\)?")
2e6a15fc 1792 '(1 font-lock-keyword-face)
ae659ad5 1793 '(9 (cond ((match-beginning 3) font-lock-function-name-face)
aaa15488 1794 ((match-beginning 6) font-lock-variable-name-face)
55015061 1795 (t font-lock-type-face))
2e6a15fc 1796 nil t))
2d63aa67
SM
1797 ;;
1798 ;; Emacs Lisp autoload cookies.
731dd885 1799 '("^;;;###\\(autoload\\)" 1 font-lock-warning-face prepend)
2e6a15fc 1800 ))
56fcbd7e 1801 "Subdued level highlighting for Lisp modes.")
030f4a35
RS
1802
1803(defconst lisp-font-lock-keywords-2
799761f0 1804 (append lisp-font-lock-keywords-1
2e6a15fc
SM
1805 (eval-when-compile
1806 (list
1807 ;;
2d63aa67 1808 ;; Control structures. Emacs Lisp forms.
ac6e572c
SM
1809 (cons (concat
1810 "(" (regexp-opt
4fffc071 1811 '("cond" "if" "while" "let" "let*"
ac6e572c 1812 "prog" "progn" "progv" "prog1" "prog2" "prog*"
4fffc071 1813 "inline" "lambda" "save-restriction" "save-excursion"
ac6e572c
SM
1814 "save-window-excursion" "save-selected-window"
1815 "save-match-data" "save-current-buffer" "unwind-protect"
9c8de95c 1816 "condition-case" "track-mouse"
ac6e572c 1817 "eval-after-load" "eval-and-compile" "eval-when-compile"
4fffc071 1818 "eval-when"
844a6a46
SM
1819 "with-current-buffer" "with-electric-help"
1820 "with-output-to-string" "with-output-to-temp-buffer"
79f238c9 1821 "with-temp-buffer" "with-temp-file" "with-temp-message"
844a6a46 1822 "with-timeout") t)
ac6e572c 1823 "\\>")
2e6a15fc
SM
1824 1)
1825 ;;
2d63aa67 1826 ;; Control structures. Common Lisp forms.
ac6e572c
SM
1827 (cons (concat
1828 "(" (regexp-opt
1829 '("when" "unless" "case" "ecase" "typecase" "etypecase"
aaa15488 1830 "ccase" "ctypecase" "handler-case" "handler-bind"
ae659ad5 1831 "restart-bind" "restart-case" "in-package"
4fffc071 1832 "cerror" "break" "ignore-errors"
ae659ad5 1833 "loop" "do" "do*" "dotimes" "dolist" "the" "locally"
aaa15488
RS
1834 "proclaim" "declaim" "declare" "symbol-macrolet"
1835 "lexical-let" "lexical-let*" "flet" "labels" "compiler-let"
1836 "destructuring-bind" "macrolet" "tagbody" "block"
ac6e572c
SM
1837 "return" "return-from") t)
1838 "\\>")
2d63aa67
SM
1839 1)
1840 ;;
4fffc071
SM
1841 ;; Exit/Feature symbols as constants.
1842 (list (concat "(\\(catch\\|throw\\|featurep\\|provide\\|require\\)\\>"
1843 "[ \t']*\\(\\sw+\\)?")
1844 '(1 font-lock-keyword-face)
1845 '(2 font-lock-constant-face nil t))
1846 ;;
1847 ;; Erroneous structures.
1848 '("(\\(abort\\|assert\\|error\\|signal\\)\\>" 1 font-lock-warning-face)
2e6a15fc
SM
1849 ;;
1850 ;; Words inside \\[] tend to be for `substitute-command-keys'.
8acf2292 1851 '("\\\\\\\\\\[\\(\\sw+\\)]" 1 font-lock-constant-face prepend)
2e6a15fc
SM
1852 ;;
1853 ;; Words inside `' tend to be symbol names.
8acf2292 1854 '("`\\(\\sw\\sw+\\)'" 1 font-lock-constant-face prepend)
2e6a15fc 1855 ;;
9c8de95c 1856 ;; Constant values.
6c4bb7f6 1857 '("\\<:\\sw+\\>" 0 font-lock-builtin-face)
2e6a15fc
SM
1858 ;;
1859 ;; ELisp and CLisp `&' keywords as types.
f56f1421 1860 '("\\&\\sw+\\>" . font-lock-type-face)
5e9e032a
SS
1861 ;;
1862 ;; CL `with-' and `do-' constructs
1863 '("(\\(\\(do-\\|with-\\)\\(\\s_\\|\\w\\)*\\)" 1 font-lock-keyword-face)
2e6a15fc 1864 )))
fb512de9 1865 "Gaudy level highlighting for Lisp modes.")
030f4a35 1866
fb512de9
SM
1867(defvar lisp-font-lock-keywords lisp-font-lock-keywords-1
1868 "Default expressions to highlight in Lisp modes.")
46f26fcf 1869\f
2e6a15fc 1870;;; User choices.
030f4a35 1871
c1f2ffc8
SM
1872;; These provide a means to fontify types not defined by the language. Those
1873;; types might be the user's own or they might be generally accepted and used.
55015061 1874;; Generally accepted types are used to provide default variable values.
c1f2ffc8 1875
2273c36b
SM
1876(define-widget 'font-lock-extra-types-widget 'radio
1877 "Widget `:type' for members of the custom group `font-lock-extra-types'.
1878Members should `:load' the package `font-lock' to use this widget."
1879 :args '((const :tag "none" nil)
46f26fcf 1880 (repeat :tag "types" regexp)))
2273c36b 1881
31b482ee 1882(defcustom c-font-lock-extra-types '("FILE" "\\sw+_t" "Lisp_Object")
2e6a15fc 1883 "*List of extra types to fontify in C mode.
55015061 1884Each list item should be a regexp not containing word-delimiters.
c1f2ffc8 1885For example, a value of (\"FILE\" \"\\\\sw+_t\") means the word FILE and words
55015061
SM
1886ending in _t are treated as type names.
1887
2273c36b
SM
1888The value of this variable is used when Font Lock mode is turned on."
1889 :type 'font-lock-extra-types-widget
1890 :group 'font-lock-extra-types)
9bfbb130 1891
b9dd672d 1892(defcustom c++-font-lock-extra-types
4fffc071
SM
1893 '("\\sw+_t"
1894 "\\([iof]\\|str\\)+stream\\(buf\\)?" "ios"
b9dd672d
SM
1895 "string" "rope"
1896 "list" "slist"
1897 "deque" "vector" "bit_vector"
1898 "set" "multiset"
1899 "map" "multimap"
1900 "hash\\(_\\(m\\(ap\\|ulti\\(map\\|set\\)\\)\\|set\\)\\)?"
1901 "stack" "queue" "priority_queue"
9dc09247 1902 "type_info"
4fffc071
SM
1903 "iterator" "const_iterator" "reverse_iterator" "const_reverse_iterator"
1904 "reference" "const_reference")
2e6a15fc 1905 "*List of extra types to fontify in C++ mode.
55015061 1906Each list item should be a regexp not containing word-delimiters.
b9dd672d
SM
1907For example, a value of (\"string\") means the word string is treated as a type
1908name.
55015061 1909
2273c36b
SM
1910The value of this variable is used when Font Lock mode is turned on."
1911 :type 'font-lock-extra-types-widget
1912 :group 'font-lock-extra-types)
030f4a35 1913
2273c36b 1914(defcustom objc-font-lock-extra-types '("Class" "BOOL" "IMP" "SEL")
2e6a15fc 1915 "*List of extra types to fontify in Objective-C mode.
55015061 1916Each list item should be a regexp not containing word-delimiters.
c1f2ffc8 1917For example, a value of (\"Class\" \"BOOL\" \"IMP\" \"SEL\") means the words
55015061
SM
1918Class, BOOL, IMP and SEL are treated as type names.
1919
2273c36b
SM
1920The value of this variable is used when Font Lock mode is turned on."
1921 :type 'font-lock-extra-types-widget
1922 :group 'font-lock-extra-types)
1bd50840 1923
68c67d1f 1924(defcustom java-font-lock-extra-types
b3f1e48a 1925 '("[A-Z\300-\326\330-\337]\\sw*[a-z]\\sw*" "URL")
2e6a15fc 1926 "*List of extra types to fontify in Java mode.
55015061 1927Each list item should be a regexp not containing word-delimiters.
b3f1e48a
PJ
1928For example, a value of (\"[A-Z\300-\326\330-\337]\\\\sw*[a-z]\\\\sw*\" \"URL\") means
1929capitalised words (that conform to the Java id spec) and URL are treated as
1930type names.
55015061 1931
2273c36b
SM
1932The value of this variable is used when Font Lock mode is turned on."
1933 :type 'font-lock-extra-types-widget
1934 :group 'font-lock-extra-types)
2e6a15fc
SM
1935\f
1936;;; C.
c1f2ffc8
SM
1937
1938;; [Murmur murmur murmur] Maestro, drum-roll please... [Murmur murmur murmur.]
1939;; Ahem. [Murmur murmur murmur] Lay-dees an Gennel-men. [Murmur murmur shhh!]
1940;; I am most proud and humbly honoured today [murmur murmur cough] to present
1941;; to you good people, the winner of the Second Millennium Award for The Most
1942;; Hairy Language Syntax. [Ahhh!] All rise please. [Shuffle shuffle
1943;; shuffle.] And a round of applause please. For... The C Language! [Roar.]
1944;;
1945;; Thank you... You are too kind... It is with a feeling of great privilege
1946;; and indeed emotion [sob] that I accept this award. It has been a long hard
1947;; road. But we know our destiny. And our future. For we must not rest.
1948;; There are more tokens to overload, more shoehorn, more methodologies. But
1949;; more is a plus! [Ha ha ha.] And more means plus! [Ho ho ho.] The future
1c626aaf 1950;; is C++! [Ohhh!] The Third Millennium Award... Will be ours! [Roar.]
c1f2ffc8 1951
2d63aa67 1952(let* ((c-keywords
ac6e572c
SM
1953 (eval-when-compile
1954 (regexp-opt '("break" "continue" "do" "else" "for" "if" "return"
4fffc071
SM
1955 "switch" "while" "sizeof"
1956 ;; Type related, but we don't do anything special.
1957 "typedef" "extern" "auto" "register" "static"
336911a1
SM
1958 "volatile" "const"
1959 ;; Dan Nicolaescu <done@gnu.org> says this is new.
47fc2db3
SM
1960 "restrict"
1961 ;; Henrik Enberg <henrik@enberg.org> says this is new.
1962 "inline"))))
4fffc071
SM
1963 (c-type-specs
1964 (eval-when-compile
fd612dd9 1965 (regexp-opt '("enum" "struct" "union"))))
4fffc071
SM
1966 (c-type-specs-depth
1967 (regexp-opt-depth c-type-specs))
1968 (c-type-names
2d63aa67 1969 `(mapconcat 'identity
019f00d8 1970 (cons
d2251bbf
SM
1971 ,(eval-when-compile
1972 (regexp-opt
1973 '("char" "short" "int" "long" "signed" "unsigned"
47fc2db3
SM
1974 "float" "double" "void" "complex"
1975 ;; Henrik Enberg <henrik@enberg.org> says these are new.
1976 "_Complex" "_Imaginary" "_Bool")))
2d63aa67
SM
1977 c-font-lock-extra-types)
1978 "\\|"))
4fffc071 1979 (c-type-names-depth
d2251bbf 1980 `(regexp-opt-depth ,c-type-names))
76f5e2af
GM
1981 (c-preprocessor-directives
1982 (eval-when-compile
1983 (regexp-opt
1984 '("define" "elif" "else" "endif" "error" "file" "if" "ifdef"
1985 "ifndef" "include" "line" "pragma" "undef"))))
1986 (c-preprocessor-directives-depth
d2251bbf 1987 (regexp-opt-depth c-preprocessor-directives)))
8259bf10 1988 (defconst c-font-lock-keywords-1
f60f18ae 1989 (list
f60f18ae 1990 ;;
9bfbb130 1991 ;; These are all anchored at the beginning of line for speed.
2e6a15fc 1992 ;; Note that `c++-font-lock-keywords-1' depends on `c-font-lock-keywords-1'.
9bfbb130
SM
1993 ;;
1994 ;; Fontify function name definitions (GNU style; without type on line).
c1f2ffc8
SM
1995 '("^\\(\\sw+\\)[ \t]*(" 1 font-lock-function-name-face)
1996 ;;
1997 ;; Fontify error directives.
1998 '("^#[ \t]*error[ \t]+\\(.+\\)" 1 font-lock-warning-face prepend)
9bfbb130
SM
1999 ;;
2000 ;; Fontify filenames in #include <...> preprocessor directives as strings.
9c8de95c 2001 '("^#[ \t]*\\(import\\|include\\)[ \t]*\\(<[^>\"\n]*>?\\)"
2e6a15fc 2002 2 font-lock-string-face)
f60f18ae 2003 ;;
a1eb1cf1 2004 ;; Fontify function macro names.
7d7d915a 2005 '("^#[ \t]*define[ \t]+\\(\\sw+\\)(" 1 font-lock-function-name-face)
f60f18ae 2006 ;;
5aa29679
RS
2007 ;; Fontify symbol names in #elif or #if ... defined preprocessor directives.
2008 '("^#[ \t]*\\(elif\\|if\\)\\>"
9bfbb130 2009 ("\\<\\(defined\\)\\>[ \t]*(?\\(\\sw+\\)?" nil nil
b9dd672d 2010 (1 font-lock-builtin-face) (2 font-lock-variable-name-face nil t)))
9bfbb130 2011 ;;
a1eb1cf1 2012 ;; Fontify otherwise as symbol names, and the preprocessor directive names.
76f5e2af
GM
2013 (list
2014 (concat "^#[ \t]*\\(" c-preprocessor-directives
2015 "\\)\\>[ \t!]*\\(\\sw+\\)?")
2016 '(1 font-lock-builtin-face)
2017 (list (+ 2 c-preprocessor-directives-depth)
8259bf10
SM
2018 'font-lock-variable-name-face nil t)))
2019 "Subdued level highlighting for C mode.")
f60f18ae 2020
8259bf10 2021 (defconst c-font-lock-keywords-2
f60f18ae 2022 (append c-font-lock-keywords-1
030f4a35 2023 (list
030f4a35 2024 ;;
9bfbb130 2025 ;; Simple regexps for speed.
b89e1134 2026 ;;
4fffc071 2027 ;; Fontify all type names.
c1f2ffc8 2028 `(eval .
d2251bbf 2029 (cons (concat "\\<\\(" ,c-type-names "\\)\\>") 'font-lock-type-face))
030f4a35 2030 ;;
b89e1134 2031 ;; Fontify all builtin keywords (except case, default and goto; see below).
4fffc071 2032 (concat "\\<\\(" c-keywords "\\|" c-type-specs "\\)\\>")
030f4a35 2033 ;;
9bfbb130 2034 ;; Fontify case/goto keywords and targets, and case default/goto tags.
76f5e2af
GM
2035 '("\\<\\(case\\|goto\\)\\>"
2036 (1 font-lock-keyword-face)
2037 ("\\(-[0-9]+\\|\\sw+\\)"
2038 ;; Return limit of search.
2039 (save-excursion (skip-chars-forward "^:\n") (point))
2040 nil
2041 (1 font-lock-constant-face nil t)))
8259bf10
SM
2042 ;; Anders Lindgren <andersl@andersl.com> points out that it is quicker
2043 ;; to use MATCH-ANCHORED to effectively anchor the regexp on the left.
2044 ;; This must come after the one for keywords and targets.
2d5eba0e
SM
2045 ;; Note: the lack of `:' in the first char-range prevents `bar' from being
2046 ;; highlighted in "foo: bar:". But adding `:' would break cases like
2047 ;; "test1 ? test2 ? foo : bar : baz".
2048 '(":" ("\\(?:^\\|[{};]\\)[ \t]*\\(\\sw+\\)[ \t]*:"
8259bf10
SM
2049 (beginning-of-line) (end-of-line)
2050 (1 font-lock-constant-face)))
2051 ))
2052 "Medium level highlighting for C mode. See also `c-font-lock-extra-types'.")
1bd50840 2053
8259bf10 2054 (defconst c-font-lock-keywords-3
9bfbb130
SM
2055 (append c-font-lock-keywords-2
2056 ;;
2057 ;; More complicated regexps for more complete highlighting for types.
2058 ;; We still have to fontify type specifiers individually, as C is so hairy.
2059 (list
2060 ;;
4fffc071 2061 ;; Fontify all storage types, plus their items.
c1f2ffc8 2062 `(eval .
d2251bbf 2063 (list (concat "\\<\\(" ,c-type-names "\\)\\>"
c1f2ffc8
SM
2064 "\\([ \t*&]+\\sw+\\>\\)*")
2065 ;; Fontify each declaration item.
2d5eba0e
SM
2066 `(font-lock-match-c-style-declaration-item-and-skip-to-next
2067 ;; Start with point after all type specifiers.
2068 (prog1 (progn (skip-chars-forward "^;{}") (point))
2069 (goto-char (or (match-beginning
2070 ,(+ ,c-type-names-depth 2))
2071 (match-end 1))))
2072 ;; Finish with point after first type specifier.
2073 (goto-char (match-end 1))
2074 ;; Fontify as a variable or function name.
2075 (1 (if (match-beginning 2)
2076 font-lock-function-name-face
2077 font-lock-variable-name-face)))))
9bfbb130 2078 ;;
4fffc071 2079 ;; Fontify all storage specs and types, plus their items.
2d5eba0e
SM
2080 `(,(concat "\\<\\(" c-type-specs "\\)\\>" "[ \t]*\\(\\sw+\\)?")
2081 (1 font-lock-keyword-face)
2082 (,(+ c-type-specs-depth 2) font-lock-type-face nil t)
2083 (font-lock-match-c-style-declaration-item-and-skip-to-next
2084 (save-excursion (skip-chars-forward "^;{}") (point))
2085 ;; Finish with point after the variable name if
2086 ;; there is one.
2087 (if (match-end 2)
2088 (goto-char (match-end 2)))
2089 ;; Fontify as a variable or function name.
2090 (1 (if (match-beginning 2)
2091 font-lock-function-name-face
2092 font-lock-variable-name-face) nil t)))
4fffc071 2093 ;;
9bfbb130
SM
2094 ;; Fontify structures, or typedef names, plus their items.
2095 '("\\(}\\)[ \t*]*\\sw"
c1f2ffc8 2096 (font-lock-match-c-style-declaration-item-and-skip-to-next
2d5eba0e
SM
2097 (prog1 (progn (skip-chars-forward "^;{}") (point))
2098 (goto-char (match-end 1))) nil
4fffc071 2099 (1 font-lock-type-face)))
9bfbb130
SM
2100 ;;
2101 ;; Fontify anything at beginning of line as a declaration or definition.
2102 '("^\\(\\sw+\\)\\>\\([ \t*]+\\sw+\\>\\)*"
2103 (1 font-lock-type-face)
c1f2ffc8 2104 (font-lock-match-c-style-declaration-item-and-skip-to-next
2d5eba0e
SM
2105 (prog1 (progn (skip-chars-forward "^;{}") (point))
2106 (goto-char (or (match-beginning 2) (match-end 1)))) nil
c1f2ffc8 2107 (1 (if (match-beginning 2)
9bfbb130
SM
2108 font-lock-function-name-face
2109 font-lock-variable-name-face))))
8259bf10
SM
2110 ))
2111 "Gaudy level highlighting for C mode.
2112See also `c-font-lock-extra-types'."))
2113
2114(defun c-font-lock-syntactic-face-function (state)
2115 (save-excursion
2116 (if (nth 3 state)
2117 ;; Check whether the string is properly terminated.
2118 (let ((nstate (parse-partial-sexp (point) (line-end-position)
2119 nil nil state 'syntax-table)))
2120 (if (and (eolp) (not (nth 5 nstate)) (nth 3 nstate))
2121 ;; We're inside a string, at EOL and there was no \.
2122 font-lock-warning-face
2123 font-lock-string-face))
2124 (goto-char (nth 8 state))
ba460008
SM
2125 ;; `doxygen' uses /*! while others use /**.
2126 (if (looking-at "/\\*[*!]\n")
2127 font-lock-doc-face font-lock-comment-face))))
2e6a15fc
SM
2128
2129(defvar c-font-lock-keywords c-font-lock-keywords-1
2130 "Default expressions to highlight in C mode.
2131See also `c-font-lock-extra-types'.")
2132\f
2133;;; C++.
2134
c1f2ffc8
SM
2135(defun font-lock-match-c++-style-declaration-item-and-skip-to-next (limit)
2136 ;; Regexp matches after point: word<word>::word (
2137 ;; ^^^^ ^^^^ ^^^^ ^
2138 ;; Where the match subexpressions are: 1 3 5 6
2139 ;;
2140 ;; Item is delimited by (match-beginning 1) and (match-end 1).
2141 ;; If (match-beginning 3) is non-nil, that part of the item incloses a `<>'.
2142 ;; If (match-beginning 5) is non-nil, that part of the item follows a `::'.
2143 ;; If (match-beginning 6) is non-nil, the item is followed by a `('.
2144 (when (looking-at (eval-when-compile
55015061
SM
2145 (concat
2146 ;; Skip any leading whitespace.
2d5eba0e 2147 "[ \t\n*&]*"
55015061
SM
2148 ;; This is `c++-type-spec' from below. (Hint hint!)
2149 "\\(\\sw+\\)" ; The instance?
2d5eba0e
SM
2150 "\\([ \t\n]*<\\(\\(?:[^<>]\\|<[^>]+>\\)+\\)[ \t\n*&]*>\\)?" ; Or template?
2151 "\\([ \t\n]*::[ \t\n*~]*\\(\\sw+\\)\\)*" ; Or member?
55015061 2152 ;; Match any trailing parenthesis.
2d5eba0e 2153 "[ \t\n]*\\((\\)?")))
c1f2ffc8
SM
2154 (save-match-data
2155 (condition-case nil
2156 (save-restriction
2157 ;; Restrict to the end of line, currently guaranteed to be LIMIT.
2158 (narrow-to-region (point-min) limit)
2159 (goto-char (match-end 1))
2160 ;; Move over any item value, etc., to the next item.
2d5eba0e 2161 (while (not (looking-at "[ \t\n]*\\(\\(,\\)\\|;\\|\\'\\)"))
c1f2ffc8
SM
2162 (goto-char (or (scan-sexps (point) 1) (point-max))))
2163 (goto-char (match-end 2)))
2164 (error t)))))
2165
76f5e2af
GM
2166(defun font-lock-match-c++-structor-declaration (limit)
2167 ;; Match C++ constructors and destructors inside class declarations.
2168 (let ((res nil)
2169 (regexp (concat "^\\s-+\\(\\(virtual\\|explicit\\)\\s-+\\)*~?\\(\\<"
2170 (mapconcat 'identity
2171 c++-font-lock-extra-types "\\|")
2172 "\\>\\)\\s-*("
2173 ;; Don't match function pointer declarations, e.g.:
2174 ;; Foo (*fptr)();
2175 "\\s-*[^*( \t]")))
2176 (while (progn (setq res (re-search-forward regexp limit t))
2177 (and res
2178 (save-excursion
2179 (beginning-of-line)
2180 (save-match-data
2181 (not (vectorp (c-at-toplevel-p))))))))
2182 res))
2183
c1f2ffc8 2184(let* ((c++-keywords
ac6e572c
SM
2185 (eval-when-compile
2186 (regexp-opt
2187 '("break" "continue" "do" "else" "for" "if" "return" "switch"
e0e277ff 2188 "while" "asm" "catch" "delete" "new" "sizeof" "this" "throw" "try"
5d8b66eb 2189 "typeid"
4fffc071
SM
2190 ;; Branko Cibej <branko.cibej@hermes.si> says this is new.
2191 "export"
2192 ;; Mark Mitchell <mmitchell@usa.net> says these are new.
2193 "mutable" "explicit"
2194 ;; Alain Picard <ap@abelard.apana.org.au> suggests treating these
2195 ;; as keywords not types.
2196 "typedef" "template"
2197 "extern" "auto" "register" "const" "volatile" "static"
7e5d8879
GM
2198 "inline" "friend" "virtual"
2199 ;; Standard C++ operator names.
2200 "and" "and_eq" "bitand" "bitor" "compl" "not" "not_eq"
2201 "or" "or_eq" "xor" "xor_eq"))))
c1f2ffc8 2202 (c++-operators
23a0e11b
SM
2203 (eval-when-compile
2204 (regexp-opt
2205 ;; Taken from Stroustrup, minus keywords otherwise fontified.
2206 '("+" "-" "*" "/" "%" "^" "&" "|" "~" "!" "=" "<" ">" "+=" "-="
2207 "*=" "/=" "%=" "^=" "&=" "|=" "<<" ">>" ">>=" "<<=" "==" "!="
2208 "<=" ">=" "&&" "||" "++" "--" "->*" "," "->" "[]" "()"))))
4fffc071
SM
2209 (c++-type-specs
2210 (eval-when-compile
2211 (regexp-opt
2212 '("class" "public" "private" "protected" "typename"
2213 "struct" "union" "enum" "namespace" "using"
2214 ;; Eric Hopper <hopper@omnifarious.mn.org> says these are new.
2215 "static_cast" "dynamic_cast" "const_cast" "reinterpret_cast") t)))
2216 (c++-type-specs-depth
2217 (regexp-opt-depth c++-type-specs))
2218 (c++-type-names
c1f2ffc8 2219 `(mapconcat 'identity
019f00d8 2220 (cons
d2251bbf
SM
2221 ,(eval-when-compile
2222 (regexp-opt
2223 '("signed" "unsigned" "short" "long"
2224 "int" "char" "float" "double" "void"
2225 "bool" "complex")))
c1f2ffc8
SM
2226 c++-font-lock-extra-types)
2227 "\\|"))
d2251bbf 2228 (c++-type-names-depth `(regexp-opt-depth ,c++-type-names))
55015061
SM
2229 ;;
2230 ;; A brave attempt to match templates following a type and/or match
2231 ;; class membership. See and sync the above function
2232 ;; `font-lock-match-c++-style-declaration-item-and-skip-to-next'.
8259bf10 2233 (c++-type-suffix (concat "\\([ \t]*<\\(\\(?:[^<>\n]\\|<[^>\n]+>\\)+\\)[ \t*&]*>\\)?"
844a6a46 2234 "\\([ \t]*::[ \t*~]*\\(\\sw+\\)\\)*"))
4fffc071 2235 (c++-type-suffix-depth (regexp-opt-depth c++-type-suffix))
55015061
SM
2236 ;; If the string is a type, it may be followed by the cruft above.
2237 (c++-type-spec (concat "\\(\\sw+\\)\\>" c++-type-suffix))
4fffc071 2238 (c++-type-spec-depth (regexp-opt-depth c++-type-spec))
55015061
SM
2239 ;;
2240 ;; Parenthesis depth of user-defined types not forgetting their cruft.
ac6e572c 2241 (c++-type-depth `(regexp-opt-depth
d2251bbf 2242 (concat ,c++-type-names ,c++-type-suffix)))
2d63aa67 2243 )
8259bf10 2244 (defconst c++-font-lock-keywords-1
9bfbb130
SM
2245 (append
2246 ;;
2247 ;; The list `c-font-lock-keywords-1' less that for function names.
2248 (cdr c-font-lock-keywords-1)
9bfbb130 2249 (list
2e6a15fc 2250 ;;
c1f2ffc8
SM
2251 ;; Fontify function name definitions, possibly incorporating class names.
2252 (list (concat "^" c++-type-spec "[ \t]*(")
2253 '(1 (if (or (match-beginning 2) (match-beginning 4))
2254 font-lock-type-face
2255 font-lock-function-name-face))
4fffc071 2256 '(3 font-lock-type-face nil t)
c1f2ffc8 2257 '(5 font-lock-function-name-face nil t))
8259bf10
SM
2258 ))
2259 "Subdued level highlighting for C++ mode.")
9bfbb130 2260
8259bf10 2261 (defconst c++-font-lock-keywords-2
b89e1134 2262 (append c++-font-lock-keywords-1
a1eb1cf1 2263 (list
9bfbb130
SM
2264 ;;
2265 ;; The list `c-font-lock-keywords-2' for C++ plus operator overloading.
c1f2ffc8 2266 `(eval .
d2251bbf 2267 (cons (concat "\\<\\(" ,c++-type-names "\\)\\>")
c1f2ffc8 2268 'font-lock-type-face))
9bfbb130 2269 ;;
c1f2ffc8
SM
2270 ;; Fontify operator overloading.
2271 (list (concat "\\<\\(operator\\)\\>[ \t]*\\(" c++-operators "\\)?")
2272 '(1 font-lock-keyword-face)
2273 '(2 font-lock-builtin-face nil t))
9bfbb130
SM
2274 ;;
2275 ;; Fontify case/goto keywords and targets, and case default/goto tags.
76f5e2af
GM
2276 '("\\<\\(case\\|goto\\)\\>"
2277 (1 font-lock-keyword-face)
2278 ("\\(-[0-9]+\\|\\sw+\\)[ \t]*\\(::\\)?"
2279 ;; Return limit of search.
2280 (save-excursion
2281 (while (progn
2282 (skip-chars-forward "^:\n")
2283 (looking-at "::"))
2284 (forward-char 2))
2285 (point))
2286 nil
2287 (1 (if (match-beginning 2)
2288 font-lock-type-face
2289 font-lock-constant-face) nil t)))
e0e277ff 2290 ;; This must come after the one for keywords and targets.
2e6a15fc
SM
2291 '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:\\($\\|[^:]\\)"
2292 (beginning-of-line) (end-of-line)
8acf2292 2293 (1 font-lock-constant-face)))
9bfbb130
SM
2294 ;;
2295 ;; Fontify other builtin keywords.
4fffc071 2296 (concat "\\<\\(" c++-keywords "\\|" c++-type-specs "\\)\\>")
2e6a15fc
SM
2297 ;;
2298 ;; Eric Hopper <hopper@omnifarious.mn.org> says `true' and `false' are new.
8acf2292 2299 '("\\<\\(false\\|true\\)\\>" . font-lock-constant-face)
8259bf10
SM
2300 ))
2301 "Medium level highlighting for C++ mode.
2302See also `c++-font-lock-extra-types'.")
9bfbb130 2303
8259bf10 2304 (defconst c++-font-lock-keywords-3
9bfbb130
SM
2305 (append c++-font-lock-keywords-2
2306 ;;
2307 ;; More complicated regexps for more complete highlighting for types.
2308 (list
2309 ;;
2310 ;; Fontify all storage classes and type specifiers, plus their items.
c1f2ffc8 2311 `(eval .
d2251bbf
SM
2312 (list (concat "\\<\\(" ,c++-type-names "\\)\\>" ,c++-type-suffix
2313 "\\([ \t*&]+" ,c++-type-spec "\\)*")
4fffc071 2314 ;; The name of any template type.
2d5eba0e 2315 `(,(+ ,c++-type-names-depth 3) font-lock-type-face nil t)
c1f2ffc8 2316 ;; Fontify each declaration item.
2d5eba0e
SM
2317 `(font-lock-match-c++-style-declaration-item-and-skip-to-next
2318 ;; Start with point after all type specifiers.
2319 (prog1 (progn (skip-chars-forward "^;{}") (point))
2320 (goto-char (or (match-beginning
2321 ,(+ ,c++-type-depth 2))
2322 (match-end 1))))
2323 ;; Finish with point after first type specifier.
2324 (goto-char (match-end 1))
2325 ;; Fontify as a variable or function name.
2326 (1 (cond ((or (match-beginning 2) (match-beginning 4))
2327 font-lock-type-face)
2328 ((and (match-beginning 6) (c-at-toplevel-p))
2329 font-lock-function-name-face)
2330 (t
2331 font-lock-variable-name-face)))
2332 (3 font-lock-type-face nil t)
2333 (5 (if (match-beginning 6)
2334 font-lock-function-name-face
2335 font-lock-variable-name-face) nil t))))
9bfbb130 2336 ;;
4fffc071 2337 ;; Fontify all storage specs and types, plus their items.
2d5eba0e
SM
2338 `(,(concat "\\<" c++-type-specs "\\>" c++-type-suffix
2339 "[ \t]*\\(" c++-type-spec "\\)?")
2340 ;; The name of any template type.
2341 (,(+ c++-type-specs-depth 2) 'font-lock-type-face nil t)
2342 ;; The name of any type.
2343 (,(+ c++-type-specs-depth c++-type-suffix-depth 2)
2344 font-lock-type-face nil t)
2345 ;; Fontify each declaration item.
2346 (font-lock-match-c++-style-declaration-item-and-skip-to-next
2347 ;; Start with point after all type specifiers.
2348 (save-excursion (skip-chars-forward "^;{}") (point))
2349 ;; Finish with point after first type specifier.
2350 nil
2351 ;; Fontify as a variable or function name.
2352 (1 (cond ((or (match-beginning 2) (match-beginning 4))
2353 font-lock-type-face)
2354 ((and (match-beginning 6) (c-at-toplevel-p))
2355 font-lock-function-name-face)
2356 (t
2357 font-lock-variable-name-face)))
2358 (3 font-lock-type-face nil t)
2359 (5 (if (match-beginning 6)
2360 font-lock-function-name-face
2361 font-lock-variable-name-face) nil t)))
4fffc071 2362 ;;
9bfbb130
SM
2363 ;; Fontify structures, or typedef names, plus their items.
2364 '("\\(}\\)[ \t*]*\\sw"
2365 (font-lock-match-c++-style-declaration-item-and-skip-to-next
2d5eba0e
SM
2366 (prog1 (progn (skip-chars-forward "^;{}") (point))
2367 (goto-char (match-end 1))) nil
4fffc071 2368 (1 font-lock-type-face)))
9bfbb130
SM
2369 ;;
2370 ;; Fontify anything at beginning of line as a declaration or definition.
2d5eba0e
SM
2371 `(,(concat "^\\(" c++-type-spec "[ \t*&]*\\)+")
2372 (font-lock-match-c++-style-declaration-item-and-skip-to-next
2373 (prog1 (progn (skip-chars-forward "^;{}") (point))
2374 (goto-char (match-beginning 1)))
2375 (goto-char (match-end 1))
2376 (1 (cond ((or (match-beginning 2) (match-beginning 4))
2377 font-lock-type-face)
2378 ((match-beginning 6) font-lock-function-name-face)
2379 (t font-lock-variable-name-face)))
2380 (3 font-lock-type-face nil t)
2381 (5 (if (match-beginning 6)
2382 font-lock-function-name-face
2383 font-lock-variable-name-face) nil t)))
76f5e2af
GM
2384 ;;
2385 ;; Fontify constructors and destructors inside class declarations.
2386 '(font-lock-match-c++-structor-declaration
2387 (3 font-lock-function-name-face t))
8259bf10
SM
2388 ))
2389 "Gaudy level highlighting for C++ mode.
2390See also `c++-font-lock-extra-types'.")
f60f18ae 2391 )
030f4a35 2392
fb512de9 2393(defvar c++-font-lock-keywords c++-font-lock-keywords-1
2e6a15fc
SM
2394 "Default expressions to highlight in C++ mode.
2395See also `c++-font-lock-extra-types'.")
2396\f
2397;;; Objective-C.
2398
2e6a15fc
SM
2399;; Regexps written with help from Stephen Peters <speters@us.oracle.com> and
2400;; Jacques Duthen Prestataire <duthen@cegelec-red.fr>.
2d63aa67 2401(let* ((objc-keywords
ac6e572c
SM
2402 (eval-when-compile
2403 (regexp-opt '("break" "continue" "do" "else" "for" "if" "return"
4fffc071
SM
2404 "switch" "while" "sizeof" "self" "super"
2405 "typedef" "auto" "extern" "static"
fd612dd9 2406 "volatile" "const"))))
4fffc071
SM
2407 (objc-type-specs
2408 (eval-when-compile
2409 (regexp-opt
2410 '("register" "struct" "union" "enum"
2411 "oneway" "in" "out" "inout" "bycopy" "byref") t)))
2412 (objc-type-specs-depth
2413 (regexp-opt-depth objc-type-specs))
2414 (objc-type-names
2d63aa67
SM
2415 `(mapconcat 'identity
2416 (cons
d2251bbf
SM
2417 ,(eval-when-compile
2418 (regexp-opt
2419 '("signed" "unsigned" "short" "long"
2420 "int" "char" "float" "double" "void"
2421 "id")))
2d63aa67
SM
2422 objc-font-lock-extra-types)
2423 "\\|"))
4fffc071 2424 (objc-type-names-depth
d2251bbf 2425 `(regexp-opt-depth ,objc-type-names))
2d63aa67 2426 )
8259bf10 2427 (defconst objc-font-lock-keywords-1
2e6a15fc
SM
2428 (append
2429 ;;
2430 ;; The list `c-font-lock-keywords-1' less that for function names.
2431 (cdr c-font-lock-keywords-1)
2432 (list
2433 ;;
2434 ;; Fontify compiler directives.
c1f2ffc8
SM
2435 '("@\\(\\sw+\\)\\>"
2436 (1 font-lock-keyword-face)
4fffc071
SM
2437 ("\\=[ \t:<,]*\\(\\sw+\\)" nil nil
2438 (1 font-lock-type-face)))
2e6a15fc
SM
2439 ;;
2440 ;; Fontify method names and arguments. Oh Lordy!
2441 ;; First, on the same line as the function declaration.
4fffc071
SM
2442 '("^[+-][ \t]*\\(PRIVATE\\>\\)?[ \t]*\\(([^)\n]+)\\)?[ \t]*\\(\\sw+\\)"
2443 (1 font-lock-keyword-face nil t)
2444 (3 font-lock-function-name-face)
2445 ("\\=[ \t]*\\(\\sw+\\)?:[ \t]*\\(([^)\n]+)\\)?[ \t]*\\(\\sw+\\)"
2e6a15fc
SM
2446 nil nil
2447 (1 font-lock-function-name-face nil t)
4fffc071 2448 (3 font-lock-variable-name-face)))
2e6a15fc 2449 ;; Second, on lines following the function declaration.
4fffc071 2450 '(":" ("^[ \t]*\\(\\sw+\\)?:[ \t]*\\(([^)\n]+)\\)?[ \t]*\\(\\sw+\\)"
2e6a15fc
SM
2451 (beginning-of-line) (end-of-line)
2452 (1 font-lock-function-name-face nil t)
4fffc071 2453 (3 font-lock-variable-name-face)))
8259bf10
SM
2454 ))
2455 "Subdued level highlighting for Objective-C mode.")
030f4a35 2456
8259bf10 2457 (defconst objc-font-lock-keywords-2
2e6a15fc
SM
2458 (append objc-font-lock-keywords-1
2459 (list
2460 ;;
2461 ;; Simple regexps for speed.
2462 ;;
2463 ;; Fontify all type specifiers.
c1f2ffc8 2464 `(eval .
d2251bbf 2465 (cons (concat "\\<\\(" ,objc-type-names "\\)\\>")
c1f2ffc8 2466 'font-lock-type-face))
2e6a15fc
SM
2467 ;;
2468 ;; Fontify all builtin keywords (except case, default and goto; see below).
4fffc071 2469 (concat "\\<\\(" objc-keywords "\\|" objc-type-specs "\\)\\>")
2e6a15fc
SM
2470 ;;
2471 ;; Fontify case/goto keywords and targets, and case default/goto tags.
56fcbd7e 2472 '("\\<\\(case\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?"
8acf2292 2473 (1 font-lock-keyword-face) (2 font-lock-constant-face nil t))
2e6a15fc 2474 ;; Fontify tags iff sole statement on line, otherwise we detect selectors.
e0e277ff 2475 ;; This must come after the one for keywords and targets.
2e6a15fc
SM
2476 '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*$"
2477 (beginning-of-line) (end-of-line)
8acf2292 2478 (1 font-lock-constant-face)))
2e6a15fc
SM
2479 ;;
2480 ;; Fontify null object pointers.
8acf2292 2481 '("\\<[Nn]il\\>" . font-lock-constant-face)
8259bf10
SM
2482 ))
2483 "Medium level highlighting for Objective-C mode.
2484See also `objc-font-lock-extra-types'.")
d46c21ec 2485
8259bf10 2486 (defconst objc-font-lock-keywords-3
2e6a15fc
SM
2487 (append objc-font-lock-keywords-2
2488 ;;
2489 ;; More complicated regexps for more complete highlighting for types.
2490 ;; We still have to fontify type specifiers individually, as C is so hairy.
2491 (list
2492 ;;
2493 ;; Fontify all storage classes and type specifiers, plus their items.
c1f2ffc8 2494 `(eval .
d2251bbf 2495 (list (concat "\\<\\(" ,objc-type-names "\\)\\>"
c1f2ffc8
SM
2496 "\\([ \t*&]+\\sw+\\>\\)*")
2497 ;; Fontify each declaration item.
2d5eba0e
SM
2498 `(font-lock-match-c-style-declaration-item-and-skip-to-next
2499 ;; Start with point after all type specifiers.
2500 (prog1 (progn (skip-chars-forward "^;{}") (point))
2501 (goto-char (or (match-beginning
2502 ,(+ ,objc-type-names-depth 2))
2503 (match-end 1))))
2504 ;; Finish with point after first type specifier.
2505 (goto-char (match-end 1))
2506 ;; Fontify as a variable or function name.
2507 (1 (if (match-beginning 2)
2508 font-lock-function-name-face
2509 font-lock-variable-name-face)))))
2e6a15fc 2510 ;;
4fffc071 2511 ;; Fontify all storage specs and types, plus their items.
2d5eba0e
SM
2512 `(,(concat "\\<\\(" objc-type-specs "[ \t]*\\)+\\>" "[ \t]*\\(\\sw+\\)?")
2513 ;; The name of any type.
2514 (,(+ objc-type-specs-depth 2) font-lock-type-face nil t)
2515 ;; Fontify each declaration item.
2516 (font-lock-match-c++-style-declaration-item-and-skip-to-next
2517 (save-excursion (skip-chars-forward "^;{}") (point)) nil
2518 ;; Fontify as a variable or function name.
2519 (1 (if (match-beginning 2)
2520 font-lock-function-name-face
2521 font-lock-variable-name-face))))
4fffc071 2522 ;;
2e6a15fc
SM
2523 ;; Fontify structures, or typedef names, plus their items.
2524 '("\\(}\\)[ \t*]*\\sw"
c1f2ffc8 2525 (font-lock-match-c-style-declaration-item-and-skip-to-next
2d5eba0e
SM
2526 (prog1 (progn (skip-chars-forward "^;{}") (point))
2527 (goto-char (match-end 1))) nil
4fffc071 2528 (1 font-lock-type-face)))
2e6a15fc
SM
2529 ;;
2530 ;; Fontify anything at beginning of line as a declaration or definition.
2531 '("^\\(\\sw+\\)\\>\\([ \t*]+\\sw+\\>\\)*"
2532 (1 font-lock-type-face)
c1f2ffc8 2533 (font-lock-match-c-style-declaration-item-and-skip-to-next
2d5eba0e
SM
2534 (prog1 (progn (skip-chars-forward "^;{}") (point))
2535 (goto-char (or (match-beginning 2) (match-end 1)))) nil
c1f2ffc8 2536 (1 (if (match-beginning 2)
2e6a15fc
SM
2537 font-lock-function-name-face
2538 font-lock-variable-name-face))))
8259bf10
SM
2539 ))
2540 "Gaudy level highlighting for Objective-C mode.
2541See also `objc-font-lock-extra-types'.")
2e6a15fc
SM
2542 )
2543
2544(defvar objc-font-lock-keywords objc-font-lock-keywords-1
2545 "Default expressions to highlight in Objective-C mode.
2546See also `objc-font-lock-extra-types'.")
2547\f
2548;;; Java.
2549
4d80b2cc
SM
2550;; Regexps written with help from Fred White <fwhite@bbn.com>,
2551;; Anders Lindgren <andersl@andersl.com> and Carl Manning <caroma@ai.mit.edu>.
2d63aa67 2552(let* ((java-keywords
ac6e572c
SM
2553 (eval-when-compile
2554 (regexp-opt
2555 '("catch" "do" "else" "super" "this" "finally" "for" "if"
68c67d1f 2556 ;; Anders Lindgren <andersl@andersl.com> says these have gone.
ac6e572c
SM
2557 ;; "cast" "byvalue" "future" "generic" "operator" "var"
2558 ;; "inner" "outer" "rest"
68c67d1f 2559 "implements" "extends" "throws" "instanceof" "new"
fd612dd9 2560 "interface" "return" "switch" "throw" "try" "while"))))
2d63aa67 2561 ;;
68c67d1f
SM
2562 ;; Classes immediately followed by an object name.
2563 (java-type-names
2564 `(mapconcat 'identity
8259bf10 2565 (cons
d2251bbf
SM
2566 ,(eval-when-compile
2567 (regexp-opt '("boolean" "char" "byte" "short" "int" "long"
2568 "float" "double" "void")))
68c67d1f
SM
2569 java-font-lock-extra-types)
2570 "\\|"))
d2251bbf 2571 (java-type-names-depth `(regexp-opt-depth ,java-type-names))
2d63aa67
SM
2572 ;;
2573 ;; These are eventually followed by an object name.
68c67d1f 2574 (java-type-specs
ac6e572c
SM
2575 (eval-when-compile
2576 (regexp-opt
2577 '("abstract" "const" "final" "synchronized" "transient" "static"
68c67d1f 2578 ;; Anders Lindgren <andersl@andersl.com> says this has gone.
ac6e572c 2579 ;; "threadsafe"
b09f207a
SM
2580 "volatile" "public" "private" "protected" "native"
2581 ;; Carl Manning <caroma@ai.mit.edu> says this is new.
2582 "strictfp"))))
ac6e572c 2583 )
8259bf10 2584 (defconst java-font-lock-keywords-1
2e6a15fc
SM
2585 (list
2586 ;;
2587 ;; Fontify class names.
2588 '("\\<\\(class\\)\\>[ \t]*\\(\\sw+\\)?"
4d80b2cc 2589 (1 font-lock-keyword-face) (2 font-lock-type-face nil t))
2e6a15fc
SM
2590 ;;
2591 ;; Fontify package names in import directives.
2592 '("\\<\\(import\\|package\\)\\>[ \t]*\\(\\sw+\\)?"
68c67d1f
SM
2593 (1 font-lock-keyword-face)
2594 (2 font-lock-constant-face nil t)
2595 ("\\=\\.\\(\\*\\|\\sw+\\)" nil nil
2596 (1 font-lock-constant-face nil t)))
8259bf10
SM
2597 )
2598 "Subdued level highlighting for Java mode.")
2e6a15fc 2599
8259bf10 2600 (defconst java-font-lock-keywords-2
2e6a15fc
SM
2601 (append java-font-lock-keywords-1
2602 (list
2603 ;;
68c67d1f
SM
2604 ;; Fontify class names.
2605 `(eval .
d2251bbf 2606 (cons (concat "\\<\\(" ,java-type-names "\\)\\>[^.]")
4d80b2cc 2607 '(1 font-lock-type-face)))
2e6a15fc
SM
2608 ;;
2609 ;; Fontify all builtin keywords (except below).
68c67d1f 2610 (concat "\\<\\(" java-keywords "\\|" java-type-specs "\\)\\>")
2e6a15fc
SM
2611 ;;
2612 ;; Fontify keywords and targets, and case default/goto tags.
56fcbd7e 2613 (list "\\<\\(break\\|case\\|continue\\|goto\\)\\>[ \t]*\\(-?\\sw+\\)?"
8acf2292 2614 '(1 font-lock-keyword-face) '(2 font-lock-constant-face nil t))
e0e277ff 2615 ;; This must come after the one for keywords and targets.
4d80b2cc 2616 '(":" ("^[ \t]*\\(\\sw+\\)[ \t]*:[ \t]*$"
2e6a15fc 2617 (beginning-of-line) (end-of-line)
8acf2292 2618 (1 font-lock-constant-face)))
2e6a15fc 2619 ;;
2e6a15fc 2620 ;; Fontify all constants.
8acf2292 2621 '("\\<\\(false\\|null\\|true\\)\\>" . font-lock-constant-face)
2e6a15fc
SM
2622 ;;
2623 ;; Javadoc tags within comments.
32038c7a
GM
2624 (list
2625 (concat "@\\("
2626 "author\\|deprecated\\|exception"
2627 "\\|link\\|return\\|see\\|serial\\|serialData\\|serialField"
2628 "\\|since\\|throws"
2629 "\\|version"
1bc7654a
GM
2630 "\\)\\>")
2631 '(1 font-lock-constant-face prepend))
2e6a15fc 2632 '("@\\(param\\)\\>[ \t]*\\(\\sw+\\)?"
8acf2292 2633 (1 font-lock-constant-face prepend)
2e6a15fc 2634 (2 font-lock-variable-name-face prepend t))
340fe50f
GM
2635 '("@\\(exception\\|throws\\)\\>[ \t]*\\(\\S-+\\)?"
2636 (1 font-lock-constant-face prepend)
2637 (2 font-lock-type-face prepend t))
8259bf10
SM
2638 ))
2639 "Medium level highlighting for Java mode.
2640See also `java-font-lock-extra-types'.")
2e6a15fc 2641
8259bf10 2642 (defconst java-font-lock-keywords-3
2e6a15fc
SM
2643 (append java-font-lock-keywords-2
2644 ;;
2645 ;; More complicated regexps for more complete highlighting for types.
2646 ;; We still have to fontify type specifiers individually, as Java is hairy.
2647 (list
2648 ;;
2e6a15fc 2649 ;; Fontify random types immediately followed by an item or items.
c1f2ffc8 2650 `(eval .
d2251bbf 2651 (list (concat "\\<\\(" ,java-type-names "\\)\\>"
c1f2ffc8
SM
2652 "\\([ \t]*\\[[ \t]*\\]\\)*"
2653 "\\([ \t]*\\sw\\)")
2654 ;; Fontify each declaration item.
2d5eba0e
SM
2655 `(font-lock-match-c-style-declaration-item-and-skip-to-next
2656 ;; Start and finish with point after the type specifier.
2657 (prog1 (progn (skip-chars-forward "^;{}") (point))
2658 (goto-char (match-beginning ,(+ ,java-type-names-depth 3))))
2659 (goto-char (match-beginning ,(+ ,java-type-names-depth 3)))
2660 ;; Fontify as a variable or function name.
2661 (1 (if (match-beginning 2)
2662 font-lock-function-name-face
2663 font-lock-variable-name-face)))))
2e6a15fc 2664 ;;
2e6a15fc 2665 ;; Fontify those that are eventually followed by an item or items.
2d5eba0e
SM
2666 `(,(concat "\\<\\(" java-type-specs "\\)\\>"
2667 "\\([ \t]+\\sw+\\>"
2668 "\\([ \t]*\\[[ \t]*\\]\\)*"
2669 "\\)*")
2670 ;; Fontify each declaration item.
2671 (font-lock-match-c-style-declaration-item-and-skip-to-next
2672 ;; Start with point after all type specifiers.
2673 (prog1 (progn (skip-chars-forward "^;{}") (point))
2674 (goto-char (or (match-beginning 5) (match-end 1))))
2675 ;; Finish with point after first type specifier.
2676 (goto-char (match-end 1))
2677 ;; Fontify as a variable or function name.
2678 (1 (if (match-beginning 2)
2679 font-lock-function-name-face
2680 font-lock-variable-name-face))))
8259bf10
SM
2681 ))
2682 "Gaudy level highlighting for Java mode.
2683See also `java-font-lock-extra-types'.")
2684 )
2e6a15fc
SM
2685
2686(defvar java-font-lock-keywords java-font-lock-keywords-1
2687 "Default expressions to highlight in Java mode.
2688See also `java-font-lock-extra-types'.")
d46c21ec 2689\f
a1eb1cf1 2690;; Provide ourselves:
8f261d40 2691
9aa40401
SM
2692(defun java-font-lock-syntactic-face-function (state)
2693 (save-excursion
2694 (if (nth 3 state)
2695 ;; Check whether the string is properly terminated.
2696 (let ((nstate (parse-partial-sexp (point) (line-end-position)
2697 nil nil state 'syntax-table)))
2698 (if (and (eolp) (nth 3 nstate))
2699 ;; We're inside a string, at EOL. The JLS says that:
2700 ;; It is a compile-time error for a line terminator to
2701 ;; appear after the opening " and before the closing
2702 ;; matching ".
2703 font-lock-warning-face
2704 font-lock-string-face))
2705 (goto-char (nth 8 state))
2706 (if (looking-at "/\\*\\*")
2707 font-lock-doc-face
2708 font-lock-comment-face))))
2709
030f4a35 2710(provide 'font-lock)
54f73af3
GM
2711
2712(when (eq font-lock-support-mode 'jit-lock-mode)
2713 (require 'jit-lock))
030f4a35
RS
2714
2715;;; font-lock.el ends here