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