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