428
|
1 ;;; font-lock.el --- decorating source files with fonts/colors based on syntax
|
|
2
|
|
3 ;; Copyright (C) 1992-1995, 1997 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1995 Amdahl Corporation.
|
771
|
5 ;; Copyright (C) 1996, 2000, 2001, 2002 Ben Wing.
|
428
|
6
|
|
7 ;; Author: Jamie Zawinski <jwz@jwz.org>, for the LISPM Preservation Society.
|
|
8 ;; Minimally merged with FSF 19.34 by Barry Warsaw <bwarsaw@python.org>
|
|
9 ;; Then (partially) synched with FSF 19.30, leading to:
|
|
10 ;; Next Author: RMS
|
|
11 ;; Next Author: Simon Marshall <simon@gnu.ai.mit.edu>
|
|
12 ;; Latest XEmacs Author: Ben Wing
|
|
13 ;; Maintainer: XEmacs Development Team
|
|
14 ;; Keywords: languages, faces
|
|
15
|
|
16 ;; This file is part of XEmacs.
|
|
17
|
|
18 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
19 ;; under the terms of the GNU General Public License as published by
|
|
20 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
21 ;; any later version.
|
|
22
|
|
23 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
24 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
26 ;; General Public License for more details.
|
|
27
|
|
28 ;; You should have received a copy of the GNU General Public License
|
|
29 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
30 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
31 ;; Boston, MA 02111-1307, USA.
|
|
32
|
|
33 ;;; Synched up with: FSF 19.30 except for the code to initialize the faces.
|
|
34
|
|
35 ;;; Commentary:
|
|
36
|
|
37 ;; Font-lock-mode is a minor mode that causes your comments to be
|
|
38 ;; displayed in one face, strings in another, reserved words in another,
|
|
39 ;; documentation strings in another, and so on.
|
|
40 ;;
|
|
41 ;; Comments will be displayed in `font-lock-comment-face'.
|
|
42 ;; Strings will be displayed in `font-lock-string-face'.
|
|
43 ;; Doc strings will be displayed in `font-lock-doc-string-face'.
|
|
44 ;; Function and variable names (in their defining forms) will be
|
|
45 ;; displayed in `font-lock-function-name-face'.
|
|
46 ;; Reserved words will be displayed in `font-lock-keyword-face'.
|
|
47 ;;
|
|
48 ;; Don't let the name fool you: you can highlight things using different
|
|
49 ;; colors or background stipples instead of fonts, though that is not the
|
|
50 ;; default. See the variables `font-lock-use-colors' and
|
|
51 ;; `font-lock-use-fonts' for broad control over this, or see the
|
|
52 ;; documentation on faces and how to change their attributes for
|
|
53 ;; fine-grained control.
|
|
54 ;;
|
|
55 ;; To make the text you type be fontified, use M-x font-lock-mode. When
|
|
56 ;; this minor mode is on, the fonts of the current line will be updated
|
|
57 ;; with every insertion or deletion.
|
|
58 ;;
|
|
59 ;; By default, font-lock will automatically put newly loaded files
|
|
60 ;; into font-lock-mode if it knows about the file's mode. See the
|
|
61 ;; variables `font-lock-auto-fontify', `font-lock-mode-enable-list',
|
|
62 ;; and `font-lock-mode-disable-list' for control over this.
|
|
63 ;;
|
|
64 ;; The `font-lock-keywords' variable defines other patterns to highlight.
|
|
65 ;; The default font-lock-mode-hook sets it to the value of the variables
|
|
66 ;; lisp-font-lock-keywords, c-font-lock-keywords, etc, as appropriate.
|
|
67 ;; The easiest way to change the highlighting patterns is to change the
|
|
68 ;; values of c-font-lock-keywords and related variables. See the doc
|
|
69 ;; string of the variable `font-lock-keywords' for the appropriate syntax.
|
|
70 ;;
|
|
71 ;; The default value for `lisp-font-lock-keywords' is the value of the variable
|
|
72 ;; `lisp-font-lock-keywords-1'. You may like `lisp-font-lock-keywords-2'
|
|
73 ;; better; it highlights many more words, but is slower and makes your buffers
|
|
74 ;; be very visually noisy.
|
|
75 ;;
|
|
76 ;; The same is true of `c-font-lock-keywords-1' and `c-font-lock-keywords-2';
|
|
77 ;; the former is subdued, the latter is loud.
|
|
78 ;;
|
|
79 ;; You can make font-lock default to the gaudier variety of keyword
|
|
80 ;; highlighting by setting the variable `font-lock-maximum-decoration'
|
|
81 ;; before loading font-lock, or by calling the functions
|
|
82 ;; `font-lock-use-default-maximal-decoration' or
|
|
83 ;; `font-lock-use-default-minimal-decoration'.
|
|
84 ;;
|
|
85 ;; On a Sparc10, the initial fontification takes about 6 seconds for a typical
|
|
86 ;; 140k file of C code, using the default configuration. The actual speed
|
|
87 ;; depends heavily on the type of code in the file, and how many non-syntactic
|
|
88 ;; patterns match; for example, Xlib.h takes 23 seconds for 101k, because many
|
|
89 ;; patterns match in it. You can speed this up substantially by removing some
|
|
90 ;; of the patterns that are highlighted by default. Fontifying lisp code is
|
|
91 ;; significantly faster, because lisp has a more regular syntax than C, so the
|
|
92 ;; regular expressions don't have to be as complicated.
|
|
93 ;;
|
|
94 ;; It's called font-lock-mode here because on the Lispms it was called
|
|
95 ;; "Electric Font Lock Mode." It was called that because there was an older
|
|
96 ;; mode called "Electric Caps Lock Mode" which had the function of causing all
|
|
97 ;; of your source code to be in upper case except for strings and comments,
|
|
98 ;; without you having to blip the caps lock key by hand all the time (thus the
|
|
99 ;; "electric", as in `electric-c-brace'.)
|
|
100
|
|
101 ;; See also the related packages `fast-lock' and `lazy-lock'. Both
|
|
102 ;; attempt to speed up the initial fontification. `fast-lock' saves
|
|
103 ;; the fontification info when you exit Emacs and reloads it next time
|
|
104 ;; you load the file, so that the file doesn't have to be fontified
|
|
105 ;; again. `lazy-lock' does "lazy" fontification -- i.e. it only
|
|
106 ;; fontifies the text as it becomes visible rather than fontifying
|
|
107 ;; the whole file when it's first loaded in.
|
|
108
|
|
109 ;; Further comments from the FSF:
|
|
110
|
|
111 ;; Nasty regexps of the form "bar\\(\\|lo\\)\\|f\\(oo\\|u\\(\\|bar\\)\\)\\|lo"
|
|
112 ;; are made thusly: (regexp-opt '("foo" "fu" "fubar" "bar" "barlo" "lo")) for
|
|
113 ;; efficiency.
|
|
114
|
|
115 ;; What is fontification for? You might say, "It's to make my code look nice."
|
|
116 ;; I think it should be for adding information in the form of cues. These cues
|
|
117 ;; should provide you with enough information to both (a) distinguish between
|
|
118 ;; different items, and (b) identify the item meanings, without having to read
|
|
119 ;; the items and think about it. Therefore, fontification allows you to think
|
|
120 ;; less about, say, the structure of code, and more about, say, why the code
|
|
121 ;; doesn't work. Or maybe it allows you to think less and drift off to sleep.
|
|
122 ;;
|
|
123 ;; So, here are my opinions/advice/guidelines:
|
|
124 ;;
|
|
125 ;; - Use the same face for the same conceptual object, across all modes.
|
|
126 ;; i.e., (b) above, all modes that have items that can be thought of as, say,
|
|
127 ;; keywords, should be highlighted with the same face, etc.
|
|
128 ;; - Keep the faces distinct from each other as far as possible.
|
|
129 ;; i.e., (a) above.
|
|
130 ;; - Make the face attributes fit the concept as far as possible.
|
|
131 ;; i.e., function names might be a bold color such as blue, comments might
|
|
132 ;; be a bright color such as red, character strings might be brown, because,
|
|
133 ;; err, strings are brown (that was not the reason, please believe me).
|
|
134 ;; - Don't use a non-nil OVERRIDE unless you have a good reason.
|
|
135 ;; Only use OVERRIDE for special things that are easy to define, such as the
|
|
136 ;; way `...' quotes are treated in strings and comments in Emacs Lisp mode.
|
|
137 ;; Don't use it to, say, highlight keywords in commented out code or strings.
|
|
138 ;; - Err, that's it.
|
|
139
|
|
140
|
|
141 ;;; Code:
|
|
142
|
|
143 (require 'fontl-hooks)
|
|
144
|
|
145 ;;;;;;;;;;;;;;;;;;;;;; user variables ;;;;;;;;;;;;;;;;;;;;;;
|
|
146
|
|
147 (defgroup font-lock nil
|
|
148 "Decorate source files with fonts/colors based on syntax.
|
|
149 Font-lock-mode is a minor mode that causes your comments to be
|
|
150 displayed in one face, strings in another, reserved words in another,
|
|
151 documentation strings in another, and so on.
|
|
152
|
|
153 Comments will be displayed in `font-lock-comment-face'.
|
|
154 Strings will be displayed in `font-lock-string-face'.
|
|
155 Doc strings will be displayed in `font-lock-doc-string-face'.
|
|
156 Function and variable names (in their defining forms) will be displayed
|
|
157 in `font-lock-function-name-face'.
|
|
158 Reserved words will be displayed in `font-lock-keyword-face'.
|
|
159 Preprocessor conditionals will be displayed in `font-lock-preprocessor-face'."
|
|
160 :group 'languages)
|
|
161
|
|
162 (defgroup font-lock-faces nil
|
|
163 "Faces used by the font-lock package."
|
|
164 :group 'font-lock
|
|
165 :group 'faces)
|
|
166
|
|
167
|
|
168 (defcustom font-lock-verbose t
|
|
169 "*If non-nil, means show status messages when fontifying.
|
|
170 See also `font-lock-message-threshold'."
|
|
171 :type 'boolean
|
|
172 :group 'font-lock)
|
|
173
|
|
174 (defcustom font-lock-message-threshold 6000
|
|
175 "*Minimum size of region being fontified for status messages to appear.
|
|
176
|
|
177 The size is measured in characters. This affects `font-lock-fontify-region'
|
|
178 but not `font-lock-fontify-buffer'. (In other words, when you first visit
|
|
179 a file and it gets fontified, you will see status messages no matter what
|
|
180 size the file is. However, if you do something else like paste a
|
442
|
181 chunk of text, you will see status messages only if the changed region is
|
|
182 large enough.)
|
428
|
183
|
|
184 Note that setting `font-lock-verbose' to nil disables the status
|
|
185 messages entirely."
|
|
186 :type 'integer
|
|
187 :group 'font-lock)
|
|
188
|
|
189 ;;;###autoload
|
|
190 (defcustom font-lock-auto-fontify t
|
|
191 "*Whether font-lock should automatically fontify files as they're loaded.
|
|
192 This will only happen if font-lock has fontifying keywords for the major
|
|
193 mode of the file. You can get finer-grained control over auto-fontification
|
|
194 by using this variable in combination with `font-lock-mode-enable-list' or
|
|
195 `font-lock-mode-disable-list'."
|
|
196 :type 'boolean
|
|
197 :group 'font-lock)
|
|
198
|
|
199 ;;;###autoload
|
|
200 (defcustom font-lock-mode-enable-list nil
|
|
201 "*List of modes to auto-fontify, if `font-lock-auto-fontify' is nil."
|
|
202 :type '(repeat (symbol :tag "Mode"))
|
|
203 :group 'font-lock)
|
|
204
|
|
205 ;;;###autoload
|
|
206 (defcustom font-lock-mode-disable-list nil
|
|
207 "*List of modes not to auto-fontify, if `font-lock-auto-fontify' is t."
|
|
208 :type '(repeat (symbol :tag "Mode"))
|
|
209 :group 'font-lock)
|
|
210
|
|
211 ;;;###autoload
|
|
212 (defcustom font-lock-use-colors '(color)
|
|
213 "*Specification for when Font Lock will set up color defaults.
|
|
214 Normally this should be '(color), meaning that Font Lock will set up
|
|
215 color defaults that are only used on color displays. Set this to nil
|
|
216 if you don't want Font Lock to set up color defaults at all. This
|
|
217 should be one of
|
|
218
|
|
219 -- a list of valid tags, meaning that the color defaults will be used
|
|
220 when all of the tags apply. (e.g. '(color x))
|
|
221 -- a list whose first element is 'or and whose remaining elements are
|
|
222 lists of valid tags, meaning that the defaults will be used when
|
|
223 any of the tag lists apply.
|
|
224 -- nil, meaning that the defaults should not be set up at all.
|
|
225
|
|
226 \(If you specify face values in your init file, they will override any
|
|
227 that Font Lock specifies, regardless of whether you specify the face
|
|
228 values before or after loading Font Lock.)
|
|
229
|
|
230 See also `font-lock-use-fonts'. If you want more control over the faces
|
|
231 used for fontification, see the documentation of `font-lock-mode' for
|
|
232 how to do it."
|
|
233 ;; Hard to do right.
|
|
234 :type 'sexp
|
|
235 :group 'font-lock)
|
|
236
|
|
237 ;;;###autoload
|
|
238 (defcustom font-lock-use-fonts '(or (mono) (grayscale))
|
|
239 "*Specification for when Font Lock will set up non-color defaults.
|
|
240
|
|
241 Normally this should be '(or (mono) (grayscale)), meaning that Font
|
|
242 Lock will set up non-color defaults that are only used on either mono
|
|
243 or grayscale displays. Set this to nil if you don't want Font Lock to
|
|
244 set up non-color defaults at all. This should be one of
|
|
245
|
|
246 -- a list of valid tags, meaning that the non-color defaults will be used
|
|
247 when all of the tags apply. (e.g. '(grayscale x))
|
|
248 -- a list whose first element is 'or and whose remaining elements are
|
|
249 lists of valid tags, meaning that the defaults will be used when
|
|
250 any of the tag lists apply.
|
|
251 -- nil, meaning that the defaults should not be set up at all.
|
|
252
|
|
253 \(If you specify face values in your init file, they will override any
|
|
254 that Font Lock specifies, regardless of whether you specify the face
|
|
255 values before or after loading Font Lock.)
|
|
256
|
|
257 See also `font-lock-use-colors'. If you want more control over the faces
|
|
258 used for fontification, see the documentation of `font-lock-mode' for
|
|
259 how to do it."
|
|
260 :type 'sexp
|
|
261 :group 'font-lock)
|
|
262
|
|
263 ;;;###autoload
|
|
264 (defcustom font-lock-maximum-decoration t
|
|
265 "*If non-nil, the maximum decoration level for fontifying.
|
|
266 If nil, use the minimum decoration (equivalent to level 0).
|
|
267 If t, use the maximum decoration available.
|
|
268 If a number, use that level of decoration (or if not available the maximum).
|
|
269 If a list, each element should be a cons pair of the form (MAJOR-MODE . LEVEL),
|
|
270 where MAJOR-MODE is a symbol or t (meaning the default). For example:
|
|
271 ((c++-mode . 2) (c-mode . t) (t . 1))
|
|
272 means use level 2 decoration for buffers in `c++-mode', the maximum decoration
|
|
273 available for buffers in `c-mode', and level 1 decoration otherwise."
|
|
274 :type '(choice (const :tag "default" nil)
|
|
275 (const :tag "maximum" t)
|
|
276 (integer :tag "level" 1)
|
|
277 (repeat :menu-tag "mode specific" :tag "mode specific"
|
|
278 :value ((t . t))
|
|
279 (cons :tag "Instance"
|
|
280 (radio :tag "Mode"
|
|
281 (const :tag "all" t)
|
|
282 (symbol :tag "name"))
|
|
283 (radio :tag "Decoration"
|
|
284 (const :tag "default" nil)
|
948
|
285 (const :tag "maximum" t)
|
428
|
286 (integer :tag "level" 1)))))
|
|
287 :group 'font-lock)
|
|
288
|
|
289 ;;;###autoload
|
|
290 (define-obsolete-variable-alias 'font-lock-use-maximal-decoration
|
|
291 'font-lock-maximum-decoration)
|
|
292
|
|
293 ;;;###autoload
|
|
294 (defcustom font-lock-maximum-size (* 250 1024)
|
|
295 "*If non-nil, the maximum size for buffers for fontifying.
|
|
296 Only buffers less than this can be fontified when Font Lock mode is turned on.
|
|
297 If nil, means size is irrelevant.
|
|
298 If a list, each element should be a cons pair of the form (MAJOR-MODE . SIZE),
|
|
299 where MAJOR-MODE is a symbol or t (meaning the default). For example:
|
|
300 ((c++-mode . 256000) (c-mode . 256000) (rmail-mode . 1048576))
|
|
301 means that the maximum size is 250K for buffers in `c++-mode' or `c-mode', one
|
|
302 megabyte for buffers in `rmail-mode', and size is irrelevant otherwise."
|
|
303 :type '(choice (const :tag "none" nil)
|
|
304 (integer :tag "size")
|
|
305 (repeat :menu-tag "mode specific" :tag "mode specific"
|
|
306 :value ((t . nil))
|
|
307 (cons :tag "Instance"
|
|
308 (radio :tag "Mode"
|
|
309 (const :tag "all" t)
|
|
310 (symbol :tag "name"))
|
|
311 (radio :tag "Size"
|
|
312 (const :tag "none" nil)
|
|
313 (integer :tag "size")))))
|
|
314 :group 'font-lock)
|
|
315
|
460
|
316 ;;;###autoload
|
|
317 (defcustom font-lock-fontify-string-delimiters nil
|
|
318 "*If non-nil, apply font-lock-string-face to string delimiters as well as
|
|
319 string text when fontifying."
|
|
320 :type 'boolean
|
|
321 :group 'font-lock)
|
692
|
322
|
|
323 ;;;###autoload
|
|
324 (defcustom font-lock-mode-line-string " Font"
|
|
325 "*String to display in the modeline when Font Lock mode is active.
|
|
326 Set this to nil if you don't want a modeline indicator."
|
|
327 :type '(choice string
|
|
328 (const :tag "none" nil))
|
|
329 :group 'font-lock)
|
428
|
330
|
|
331 ;; Fontification variables:
|
|
332
|
|
333 ;;;###autoload
|
|
334 (defvar font-lock-keywords nil
|
442
|
335 "A list defining the keywords for `font-lock-mode' to highlight.
|
|
336
|
|
337 FONT-LOCK-KEYWORDS := List of FONT-LOCK-FORM's.
|
|
338
|
|
339 FONT-LOCK-FORM :== MATCHER
|
|
340 | (MATCHER . MATCH)
|
|
341 | (MATCHER . FACE-FORM)
|
|
342 | (MATCHER . HIGHLIGHT)
|
|
343 | (MATCHER HIGHLIGHT ...)
|
|
344 | (eval . FORM)
|
|
345
|
|
346 MATCHER :== A string containing a regexp.
|
|
347 | A variable containing a regexp to search for.
|
|
348 | A function to call to make the search.
|
|
349 It is called with one arg, the limit of the search,
|
|
350 and should leave MATCH results in the XEmacs global
|
|
351 match data.
|
|
352
|
|
353 MATCH :== An integer match subexpression number from MATCHER.
|
|
354
|
|
355 FACE-FORM :== The symbol naming a defined face.
|
|
356 | Expression whos value is the face name to use. If you
|
|
357 want FACE-FORM to be a symbol that evaluates to a face,
|
|
358 use a form like \"(progn sym)\".
|
|
359
|
|
360 HIGHLIGHT :== MATCH-HIGHLIGHT
|
|
361 | MATCH-ANCHORED
|
|
362
|
|
363 FORM :== Expression returning a FONT-LOCK-FORM, evaluated when
|
|
364 the FONT-LOCK-FORM is first used in a buffer. This
|
|
365 feature can be used to provide a FONT-LOCK-FORM that
|
|
366 can only be generated when Font Lock mode is actually
|
|
367 turned on.
|
|
368
|
|
369 MATCH-HIGHLIGHT :== (MATCH FACE-FORM OVERRIDE LAXMATCH)
|
|
370
|
|
371 OVERRIDE :== t - overwrite existing fontification
|
|
372 | 'keep - only parts not already fontified are
|
|
373 highlighted.
|
|
374 | 'prepend - merge faces, this fontification has
|
|
375 precedence over existing
|
|
376 | 'append - merge faces, existing fontification has
|
|
377 precedence over
|
|
378 this face.
|
|
379
|
|
380 LAXMATCH :== If non-nil, no error is signalled if there is no MATCH
|
|
381 in MATCHER.
|
|
382
|
|
383 MATCH-ANCHORED :== (ANCHOR-MATCHER PRE-MATCH-FORM \\
|
|
384 POST-MATCH-FORM MATCH-HIGHLIGHT ...)
|
428
|
385
|
442
|
386 ANCHOR-MATCHER :== Like a MATCHER, except that the limit of the search
|
|
387 defaults to the end of the line after PRE-MATCH-FORM
|
|
388 is evaluated. However, if PRE-MATCH-FORM returns a
|
|
389 position greater than the end of the line, that
|
|
390 position is used as the limit of the search. It is
|
|
391 generally a bad idea to return a position greater than
|
|
392 the end of the line, i.e., cause the ANCHOR-MATCHER
|
|
393 search to span lines.
|
|
394
|
|
395 PRE-MATCH-FORM :== Evaluated before the ANCHOR-MATCHER is used, therefore
|
|
396 can be used to initialize before, ANCHOR-MATCHER is
|
|
397 used. Typically, PRE-MATCH-FORM is used to move to
|
|
398 some position relative to the original MATCHER, before
|
|
399 starting with the ANCHOR-MATCHER.
|
|
400
|
|
401 POST-MATCH-FORM :== Like PRE-MATCH-FORM, but used to clean up after the
|
|
402 ANCHOR-MATCHER. It might be used to move, before
|
|
403 resuming with MATCH-ANCHORED's parent's MATCHER.
|
|
404
|
|
405 For example, an element of the first form highlights (if not already highlighted):
|
|
406
|
444
|
407 \"\\\\\\=<foo\\\\\\=>\" Discrete occurrences of \"foo\" in the value
|
442
|
408 of the variable `font-lock-keyword-face'.
|
428
|
409
|
442
|
410 (\"fu\\\\(bar\\\\)\" . 1) Substring \"bar\" within all occurrences of
|
|
411 \"fubar\" in the value of
|
|
412 `font-lock-keyword-face'.
|
|
413
|
|
414 (\"fubar\" . fubar-face) Occurrences of \"fubar\" in the value of
|
|
415 `fubar-face'.
|
|
416
|
|
417 (\"foo\\\\|bar\" 0 foo-bar-face t) Occurrences of either \"foo\" or \"bar\" in the
|
|
418 value of `foo-bar-face', even if already
|
|
419 highlighted.
|
428
|
420
|
442
|
421 (fubar-match 1 fubar-face) The first subexpression within all
|
|
422 occurrences of whatever the function
|
|
423 `fubar-match' finds and matches in the value
|
|
424 of `fubar-face'.
|
|
425
|
444
|
426 (\"\\\\\\=<anchor\\\\\\=>\" (0 anchor-face) (\"\\\\\\=<item\\\\\\=>\" nil nil (0 item-face)))
|
442
|
427 -------------- --------------- ------------ --- --- -------------
|
|
428 | | | | | |
|
|
429 MATCHER | ANCHOR-MATCHER | +------+ MATCH-HIGHLIGHT
|
|
430 MATCH-HIGHLIGHT PRE-MATCH-FORM |
|
|
431 POST-MATCH-FORM
|
|
432
|
|
433 Discrete occurrences of \"anchor\" in the value of `anchor-face', and
|
|
434 subsequent discrete occurrences of \"item\" (on the same line) in the value
|
|
435 of `item-face'. (Here PRE-MATCH-FORM and POST-MATCH-FORM are nil.
|
|
436 Therefore \"item\" is initially searched for starting from the end of the
|
|
437 match of \"anchor\", and searching for subsequent instance of \"anchor\"
|
|
438 resumes from where searching for \"item\" concluded.)
|
428
|
439
|
|
440 For highlighting single items, typically only MATCH-HIGHLIGHT is required.
|
442
|
441 However, if an item or (typically) several items are to be highlighted
|
|
442 following the instance of another item (the anchor) then MATCH-ANCHORED may be
|
|
443 required.
|
428
|
444
|
|
445 These regular expressions should not match text which spans lines. While
|
442
|
446 \\[font-lock-fontify-buffer] handles multi-line patterns correctly, updating when you
|
|
447 edit the buffer does not, since it considers text one line at a time.
|
428
|
448
|
442
|
449 Be very careful composing regexps for this list; the wrong pattern can
|
|
450 dramatically slow things down!
|
|
451 ")
|
428
|
452 ;;;###autoload
|
|
453 (make-variable-buffer-local 'font-lock-keywords)
|
|
454
|
460
|
455 ;;;###autoload
|
|
456 (defvar font-lock-syntactic-keywords nil
|
|
457 "A list of the syntactic keywords to highlight.
|
|
458 Can be the list or the name of a function or variable whose value is the list.
|
|
459 See `font-lock-keywords' for a description of the form of this list;
|
|
460 the differences are listed below. MATCH-HIGHLIGHT should be of the form:
|
|
461
|
|
462 (MATCH SYNTAX OVERRIDE LAXMATCH)
|
|
463
|
|
464 where SYNTAX can be of the form (SYNTAX-CODE . MATCHING-CHAR), the name of a
|
|
465 syntax table, or an expression whose value is such a form or a syntax table.
|
|
466 OVERRIDE cannot be `prepend' or `append'.
|
|
467
|
|
468 For example, an element of the form highlights syntactically:
|
|
469
|
|
470 (\"\\\\$\\\\(#\\\\)\" 1 (1 . nil))
|
|
471
|
|
472 a hash character when following a dollar character, with a SYNTAX-CODE of
|
|
473 1 (meaning punctuation syntax). Assuming that the buffer syntax table does
|
|
474 specify hash characters to have comment start syntax, the element will only
|
|
475 highlight hash characters that do not follow dollar characters as comments
|
|
476 syntactically.
|
|
477
|
|
478 (\"\\\\('\\\\).\\\\('\\\\)\"
|
|
479 (1 (7 . ?'))
|
|
480 (2 (7 . ?')))
|
|
481
|
|
482 both single quotes which surround a single character, with a SYNTAX-CODE of
|
|
483 7 (meaning string quote syntax) and a MATCHING-CHAR of a single quote (meaning
|
|
484 a single quote matches a single quote). Assuming that the buffer syntax table
|
|
485 does not specify single quotes to have quote syntax, the element will only
|
|
486 highlight single quotes of the form 'c' as strings syntactically.
|
|
487 Other forms, such as foo'bar or 'fubar', will not be highlighted as strings.
|
|
488
|
|
489 This is normally set via `font-lock-defaults'."
|
|
490 )
|
|
491 ;;;###autoload
|
|
492 (make-variable-buffer-local 'font-lock-syntactic-keywords)
|
|
493
|
428
|
494 (defvar font-lock-defaults nil
|
|
495 "The defaults font Font Lock mode for the current buffer.
|
|
496 Normally, do not set this directly. If you are writing a major mode,
|
|
497 put a property of `font-lock-defaults' on the major-mode symbol with
|
|
498 the desired value.
|
|
499
|
|
500 It should be a list
|
|
501
|
|
502 \(KEYWORDS KEYWORDS-ONLY CASE-FOLD SYNTAX-ALIST SYNTAX-BEGIN)
|
|
503
|
|
504 KEYWORDS may be a symbol (a variable or function whose value is the keywords
|
|
505 to use for fontification) or a list of symbols. If KEYWORDS-ONLY is non-nil,
|
|
506 syntactic fontification (strings and comments) is not performed. If CASE-FOLD
|
|
507 is non-nil, the case of the keywords is ignored when fontifying. If
|
|
508 SYNTAX-ALIST is non-nil, it should be a list of cons pairs of the form (CHAR
|
|
509 . STRING) used to set the local Font Lock syntax table, for keyword and
|
|
510 syntactic fontification (see `modify-syntax-entry').
|
|
511
|
|
512 If SYNTAX-BEGIN is non-nil, it should be a function with no args used to move
|
|
513 backwards outside any enclosing syntactic block, for syntactic fontification.
|
|
514 Typical values are `beginning-of-line' (i.e., the start of the line is known to
|
|
515 be outside a syntactic block), or `beginning-of-defun' for programming modes or
|
|
516 `backward-paragraph' for textual modes (i.e., the mode-dependent function is
|
|
517 known to move outside a syntactic block). If nil, the beginning of the buffer
|
|
518 is used as a position outside of a syntactic block, in the worst case.
|
|
519
|
|
520 These item elements are used by Font Lock mode to set the variables
|
|
521 `font-lock-keywords', `font-lock-keywords-only',
|
|
522 `font-lock-keywords-case-fold-search', `font-lock-syntax-table' and
|
|
523 `font-lock-beginning-of-syntax-function', respectively.
|
|
524
|
|
525 Alternatively, if the value is a symbol, it should name a major mode,
|
|
526 and the defaults for that mode will apply.")
|
|
527 (make-variable-buffer-local 'font-lock-defaults)
|
|
528
|
|
529 ;; FSF uses `font-lock-defaults-alist' and expects the major mode to
|
|
530 ;; set a value for `font-lock-defaults', but I don't like either of
|
|
531 ;; these -- requiring the mode to set `font-lock-defaults' makes it
|
|
532 ;; impossible to have defaults for a minor mode, and using an alist is
|
|
533 ;; generally a bad idea for information that really should be
|
|
534 ;; decentralized. (Who knows what strange modes might want
|
|
535 ;; font-locking?)
|
|
536
|
|
537 (defvar font-lock-keywords-only nil
|
|
538 "Non-nil means Font Lock should not do syntactic fontification.
|
|
539 This is normally set via `font-lock-defaults'.
|
|
540
|
|
541 This should be nil for all ``language'' modes, but other modes, like
|
|
542 dired, do not have anything useful in the syntax tables (no comment
|
|
543 or string delimiters, etc) and so there is no need to use them and
|
|
544 this variable should have a value of t.
|
|
545
|
|
546 You should not set this variable directly; its value is computed
|
|
547 from `font-lock-defaults', or (if that does not specify anything)
|
|
548 by examining the syntax table to see whether it appears to contain
|
|
549 anything useful.")
|
|
550 (make-variable-buffer-local 'font-lock-keywords-only)
|
|
551
|
|
552 (defvar font-lock-keywords-case-fold-search nil
|
|
553 "Whether the strings in `font-lock-keywords' should be case-folded.
|
|
554 This variable is automatically buffer-local, as the correct value depends
|
|
555 on the language in use.")
|
|
556 (make-variable-buffer-local 'font-lock-keywords-case-fold-search)
|
|
557
|
|
558 (defvar font-lock-after-fontify-buffer-hook nil
|
|
559 "Function or functions to run after completion of font-lock-fontify-buffer.")
|
|
560
|
|
561 (defvar font-lock-syntax-table nil
|
|
562 "Non-nil means use this syntax table for fontifying.
|
|
563 If this is nil, the major mode's syntax table is used.
|
|
564 This is normally set via `font-lock-defaults'.")
|
|
565 (make-variable-buffer-local 'font-lock-syntax-table)
|
|
566
|
460
|
567 ;; These record the parse state at a particular position, always the start of a
|
|
568 ;; line. Used to make `font-lock-fontify-syntactically-region' faster.
|
|
569 ;; Previously, `font-lock-cache-position' was just a buffer position. However,
|
|
570 ;; under certain situations, this occasionally resulted in mis-fontification.
|
|
571 ;; I think the "situations" were deletion with Lazy Lock mode's deferral. sm.
|
|
572 (defvar font-lock-cache-state nil)
|
|
573 (defvar font-lock-cache-position nil)
|
|
574 (make-variable-buffer-local 'font-lock-cache-state)
|
|
575 (make-variable-buffer-local 'font-lock-cache-position)
|
428
|
576
|
|
577 ;; If this is nil, we only use the beginning of the buffer if we can't use
|
|
578 ;; `font-lock-cache-position' and `font-lock-cache-state'.
|
|
579 (defvar font-lock-beginning-of-syntax-function nil
|
|
580 "Non-nil means use this function to move back outside of a syntactic block.
|
|
581 If this is nil, the beginning of the buffer is used (in the worst case).
|
|
582 This is normally set via `font-lock-defaults'.")
|
|
583 (make-variable-buffer-local 'font-lock-beginning-of-syntax-function)
|
|
584
|
|
585 (defvar font-lock-fontify-buffer-function 'font-lock-default-fontify-buffer
|
|
586 "Function to use for fontifying the buffer.
|
|
587 This is normally set via `font-lock-defaults'.")
|
|
588
|
|
589 (defvar font-lock-unfontify-buffer-function 'font-lock-default-unfontify-buffer
|
|
590 "Function to use for unfontifying the buffer.
|
|
591 This is used when turning off Font Lock mode.
|
|
592 This is normally set via `font-lock-defaults'.")
|
|
593
|
|
594 (defvar font-lock-fontify-region-function 'font-lock-default-fontify-region
|
|
595 "Function to use for fontifying a region.
|
|
596 It should take two args, the beginning and end of the region, and an optional
|
|
597 third arg VERBOSE. If non-nil, the function should print status messages.
|
|
598 This is normally set via `font-lock-defaults'.")
|
|
599
|
|
600 (defvar font-lock-unfontify-region-function 'font-lock-default-unfontify-region
|
|
601 "Function to use for unfontifying a region.
|
|
602 It should take two args, the beginning and end of the region.
|
|
603 This is normally set via `font-lock-defaults'.")
|
|
604
|
|
605 (defvar font-lock-inhibit-thing-lock nil
|
|
606 "List of Font Lock mode related modes that should not be turned on.
|
|
607 Currently, valid mode names as `fast-lock-mode' and `lazy-lock-mode'.
|
|
608 This is normally set via `font-lock-defaults'.")
|
|
609
|
|
610 ;;;###autoload
|
|
611 (defcustom font-lock-mode nil ;; customized for the option menu. dverna
|
|
612 "Non nil means `font-lock-mode' is on"
|
|
613 :group 'font-lock
|
|
614 :type 'boolean
|
|
615 :initialize 'custom-initialize-default
|
|
616 :require 'font-lock
|
|
617 :set #'(lambda (var val) (font-lock-mode (or val 0)))
|
|
618 )
|
|
619
|
|
620 (defvar font-lock-fontified nil) ; whether we have hacked this buffer
|
|
621 (put 'font-lock-fontified 'permanent-local t)
|
|
622
|
|
623 ;;;###autoload
|
|
624 (defvar font-lock-mode-hook nil
|
|
625 "Function or functions to run on entry to font-lock-mode.")
|
|
626
|
|
627 ; whether font-lock-set-defaults has already been run.
|
|
628 (defvar font-lock-defaults-computed nil)
|
|
629 (make-variable-buffer-local 'font-lock-defaults-computed)
|
|
630
|
|
631
|
|
632 ;;; Initialization of faces.
|
|
633
|
|
634 ;; #### barf gag retch. Horrid FSF lossage that we need to
|
|
635 ;; keep around for compatibility with font-lock-keywords that
|
442
|
636 ;; forget to properly quote their faces. I tried just let-binding
|
948
|
637 ;; them when we eval the face expression, but that fails because
|
442
|
638 ;; some files actually use the variables directly in their init code
|
|
639 ;; without quoting them. --ben
|
428
|
640 (defvar font-lock-comment-face 'font-lock-comment-face
|
442
|
641 "This variable should not be set.
|
|
642 It is present only for horrid FSF compatibility reasons.
|
|
643 The corresponding face should be set using `edit-faces' or the
|
|
644 `set-face-*' functions.")
|
428
|
645 (defvar font-lock-doc-string-face 'font-lock-doc-string-face
|
442
|
646 "This variable should not be set.
|
|
647 It is present only for horrid FSF compatibility reasons.
|
|
648 The corresponding face should be set using `edit-faces' or the
|
|
649 `set-face-*' functions.")
|
948
|
650 ;; GNU compatibility
|
|
651 (define-compatible-variable-alias
|
|
652 'font-lock-doc-face 'font-lock-doc-string-face)
|
428
|
653 (defvar font-lock-string-face 'font-lock-string-face
|
442
|
654 "This variable should not be set.
|
|
655 It is present only for horrid FSF compatibility reasons.
|
|
656 The corresponding face should be set using `edit-faces' or the
|
|
657 `set-face-*' functions.")
|
428
|
658 (defvar font-lock-keyword-face 'font-lock-keyword-face
|
442
|
659 "This variable should not be set.
|
|
660 It is present only for horrid FSF compatibility reasons.
|
|
661 The corresponding face should be set using `edit-faces' or the
|
|
662 `set-face-*' functions.")
|
948
|
663 (defvar font-lock-builtin-face 'font-lock-builtin-face
|
|
664 "This variable should not be set.
|
|
665 It is present only for horrid FSF compatibility reasons.
|
|
666 The corresponding face should be set using `edit-faces' or the
|
|
667 `set-face-*' functions.")
|
428
|
668 (defvar font-lock-function-name-face 'font-lock-function-name-face
|
442
|
669 "This variable should not be set.
|
|
670 It is present only for horrid FSF compatibility reasons.
|
|
671 The corresponding face should be set using `edit-faces' or the
|
|
672 `set-face-*' functions.")
|
428
|
673 (defvar font-lock-variable-name-face 'font-lock-variable-name-face
|
442
|
674 "This variable should not be set.
|
|
675 It is present only for horrid FSF compatibility reasons.
|
|
676 The corresponding face should be set using `edit-faces' or the
|
|
677 `set-face-*' functions.")
|
428
|
678 (defvar font-lock-type-face 'font-lock-type-face
|
442
|
679 "This variable should not be set.
|
|
680 It is present only for horrid FSF compatibility reasons.
|
|
681 The corresponding face should be set using `edit-faces' or the
|
|
682 `set-face-*' functions.")
|
948
|
683 (defvar font-lock-constant-face 'font-lock-constant-face
|
|
684 "This variable should not be set.
|
|
685 It is present only for horrid FSF compatibility reasons.
|
|
686 The corresponding face should be set using `edit-faces' or the
|
|
687 `set-face-*' functions.")
|
428
|
688 (defvar font-lock-reference-face 'font-lock-reference-face
|
442
|
689 "This variable should not be set.
|
|
690 It is present only for horrid FSF compatibility reasons.
|
|
691 The corresponding face should be set using `edit-faces' or the
|
|
692 `set-face-*' functions.")
|
428
|
693 (defvar font-lock-preprocessor-face 'font-lock-preprocessor-face
|
442
|
694 "This variable should not be set.
|
|
695 It is present only for horrid FSF compatibility reasons.
|
|
696 The corresponding face should be set using `edit-faces' or the
|
|
697 `set-face-*' functions.")
|
428
|
698
|
|
699 (defconst font-lock-face-list
|
|
700 '(font-lock-comment-face
|
|
701 font-lock-string-face
|
|
702 font-lock-doc-string-face
|
|
703 font-lock-keyword-face
|
948
|
704 font-lock-builtin-face
|
428
|
705 font-lock-function-name-face
|
|
706 font-lock-variable-name-face
|
|
707 font-lock-type-face
|
948
|
708 font-lock-constant-face
|
428
|
709 font-lock-reference-face
|
|
710 font-lock-preprocessor-face
|
|
711 font-lock-warning-face))
|
|
712
|
|
713 (defface font-lock-comment-face
|
|
714 '((((class color) (background dark)) (:foreground "gray80"))
|
442
|
715 ;; blue4 is hardly different from black on windows.
|
|
716 (((class color) (background light) (type mswindows)) (:foreground "blue"))
|
428
|
717 (((class color) (background light)) (:foreground "blue4"))
|
|
718 (((class grayscale) (background light))
|
|
719 (:foreground "DimGray" :bold t :italic t))
|
|
720 (((class grayscale) (background dark))
|
|
721 (:foreground "LightGray" :bold t :italic t))
|
|
722 (t (:bold t)))
|
|
723 "Font Lock mode face used to highlight comments."
|
|
724 :group 'font-lock-faces)
|
|
725
|
|
726 (defface font-lock-string-face
|
|
727 '((((class color) (background dark)) (:foreground "tan"))
|
|
728 (((class color) (background light)) (:foreground "green4"))
|
|
729 (((class grayscale) (background light)) (:foreground "DimGray" :italic t))
|
|
730 (((class grayscale) (background dark)) (:foreground "LightGray" :italic t))
|
|
731 (t (:bold t)))
|
|
732 "Font Lock mode face used to highlight strings."
|
|
733 :group 'font-lock-faces)
|
|
734
|
|
735 (defface font-lock-doc-string-face
|
|
736 '((((class color) (background dark)) (:foreground "light coral"))
|
|
737 (((class color) (background light)) (:foreground "green4"))
|
|
738 (t (:bold t)))
|
432
|
739 "Font Lock mode face used to highlight documentation strings.
|
|
740 This is currently supported only in Lisp-like modes, which are those
|
|
741 with \"lisp\" or \"scheme\" in their name. You can explicitly make
|
|
742 a mode Lisp-like by putting a non-nil `font-lock-lisp-like' property
|
|
743 on the major mode's symbol."
|
428
|
744 :group 'font-lock-faces)
|
|
745
|
|
746 (defface font-lock-keyword-face
|
|
747 '((((class color) (background dark)) (:foreground "cyan"))
|
442
|
748 ;; red4 is hardly different from black on windows.
|
|
749 (((class color) (background light) (type mswindows)) (:foreground "red"))
|
428
|
750 (((class color) (background light)) (:foreground "red4"))
|
|
751 (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
|
|
752 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
|
|
753 (t (:bold t)))
|
|
754 "Font Lock mode face used to highlight keywords."
|
|
755 :group 'font-lock-faces)
|
|
756
|
948
|
757 (defface font-lock-builtin-face
|
|
758 '((((class color) (background light)) (:foreground "Purple"))
|
|
759 (((class color) (background dark)) (:foreground "Cyan"))
|
|
760 (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
|
|
761 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
|
|
762 (t (:bold t)))
|
|
763 "Font Lock mode face used to highlight builtins."
|
|
764 :group 'font-lock-faces)
|
|
765
|
428
|
766 (defface font-lock-function-name-face
|
|
767 '((((class color) (background dark)) (:foreground "aquamarine"))
|
442
|
768 ;; brown4 is hardly different from black on windows.
|
|
769 ;; I changed it to red because IMO it's pointless and ugly to
|
|
770 ;; use a million slightly different colors for niggly syntactic
|
|
771 ;; differences. --ben
|
|
772 (((class color) (background light) (type mswindows)) (:foreground "red"))
|
428
|
773 (((class color) (background light)) (:foreground "brown4"))
|
|
774 (t (:bold t :underline t)))
|
|
775 "Font Lock mode face used to highlight function names."
|
|
776 :group 'font-lock-faces)
|
|
777
|
|
778 (defface font-lock-variable-name-face
|
|
779 '((((class color) (background dark)) (:foreground "cyan3"))
|
|
780 (((class color) (background light)) (:foreground "magenta4"))
|
|
781 (((class grayscale) (background light))
|
|
782 (:foreground "Gray90" :bold t :italic t))
|
|
783 (((class grayscale) (background dark))
|
|
784 (:foreground "DimGray" :bold t :italic t))
|
|
785 (t (:underline t)))
|
|
786 "Font Lock mode face used to highlight variable names."
|
|
787 :group 'font-lock-faces)
|
|
788
|
|
789 (defface font-lock-type-face
|
|
790 '((((class color) (background dark)) (:foreground "wheat"))
|
|
791 (((class color) (background light)) (:foreground "steelblue"))
|
|
792 (((class grayscale) (background light)) (:foreground "Gray90" :bold t))
|
|
793 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
|
|
794 (t (:bold t)))
|
|
795 "Font Lock mode face used to highlight types."
|
|
796 :group 'font-lock-faces)
|
|
797
|
948
|
798 (defface font-lock-constant-face
|
|
799 '((((class color) (background light)) (:foreground "CadetBlue"))
|
|
800 (((class color) (background dark)) (:foreground "Aquamarine"))
|
|
801 (((class grayscale) (background light))
|
|
802 (:foreground "LightGray" :bold t :underline t))
|
|
803 (((class grayscale) (background dark))
|
|
804 (:foreground "Gray50" :bold t :underline t))
|
|
805 (t (:bold t :underline t)))
|
|
806 "Font Lock mode face used to highlight constants and labels."
|
|
807 :group 'font-lock-faces)
|
|
808
|
428
|
809 (defface font-lock-reference-face
|
|
810 '((((class color) (background dark)) (:foreground "cadetblue2"))
|
|
811 (((class color) (background light)) (:foreground "red3"))
|
|
812 (((class grayscale) (background light))
|
|
813 (:foreground "LightGray" :bold t :underline t))
|
|
814 (((class grayscale) (background dark))
|
|
815 (:foreground "Gray50" :bold t :underline t)))
|
|
816 "Font Lock mode face used to highlight references."
|
|
817 :group 'font-lock-faces)
|
|
818
|
|
819 (defface font-lock-preprocessor-face
|
|
820 '((((class color) (background dark)) (:foreground "steelblue1"))
|
|
821 (((class color) (background light)) (:foreground "blue3"))
|
|
822 (t (:underline t)))
|
|
823 "Font Lock Mode face used to highlight preprocessor conditionals."
|
|
824 :group 'font-lock-faces)
|
|
825
|
|
826 (defface font-lock-warning-face
|
|
827 '((((class color) (background light)) (:foreground "Red" :bold t))
|
|
828 (((class color) (background dark)) (:foreground "Pink" :bold t))
|
|
829 (t (:inverse-video t :bold t)))
|
|
830 "Font Lock mode face used to highlight warnings."
|
|
831 :group 'font-lock-faces)
|
|
832
|
|
833 (defun font-lock-recompute-variables ()
|
|
834 ;; Is this a Draconian thing to do?
|
|
835 (mapc #'(lambda (buffer)
|
|
836 (with-current-buffer buffer
|
|
837 (font-lock-mode 0)
|
|
838 (font-lock-set-defaults t)))
|
|
839 (buffer-list)))
|
|
840
|
|
841 ;; Backwards-compatible crud.
|
|
842
|
|
843 (defun font-lock-reset-all-faces ()
|
|
844 (dolist (face font-lock-face-list)
|
|
845 (face-spec-set face (get face 'face-defface-spec))))
|
|
846
|
|
847 (defun font-lock-use-default-fonts ()
|
|
848 "Reset the font-lock faces to a default set of fonts."
|
|
849 (interactive)
|
|
850 ;; #### !!!!
|
|
851 (font-lock-reset-all-faces))
|
|
852
|
|
853 (defun font-lock-use-default-colors ()
|
|
854 "Reset the font-lock faces to a default set of colors."
|
|
855 (interactive)
|
|
856 ;; #### !!!!
|
|
857 (font-lock-reset-all-faces))
|
|
858
|
|
859 (defun font-lock-use-default-minimal-decoration ()
|
|
860 "Reset the font-lock patterns to a fast, minimal set of decorations."
|
|
861 (and font-lock-maximum-decoration
|
|
862 (setq font-lock-maximum-decoration nil)
|
|
863 (font-lock-recompute-variables)))
|
|
864
|
|
865 (defun font-lock-use-default-maximal-decoration ()
|
|
866 "Reset the font-lock patterns to a larger set of decorations."
|
|
867 (and (not (eq t font-lock-maximum-decoration))
|
|
868 (setq font-lock-maximum-decoration t)
|
|
869 (font-lock-recompute-variables)))
|
|
870
|
|
871
|
|
872 ;;;;;;;;;;;;;;;;;;;;;; actual code ;;;;;;;;;;;;;;;;;;;;;;
|
|
873
|
|
874 ;;; To fontify the whole buffer by language syntax, we go through it a
|
|
875 ;;; character at a time, creating extents on the boundary of each syntactic
|
|
876 ;;; unit (that is, one extent for each block comment, one for each line
|
|
877 ;;; comment, one for each string, etc.) This is done with the C function
|
|
878 ;;; syntactically-sectionize. It's in C for speed (the speed of lisp function
|
|
879 ;;; calls was a real bottleneck for this task since it involves examining each
|
|
880 ;;; character in turn.)
|
|
881 ;;;
|
|
882 ;;; Then we make a second pass, to fontify the buffer based on other patterns
|
|
883 ;;; specified by regexp. When we find a match for a region of text, we need
|
|
884 ;;; to change the fonts on those characters. This is done with the
|
|
885 ;;; put-text-property function, which knows how to efficiently share extents.
|
|
886 ;;; Conceptually, we are attaching some particular face to each of the
|
|
887 ;;; characters in a range, but the implementation of this involves creating
|
|
888 ;;; extents, or resizing existing ones.
|
|
889 ;;;
|
|
890 ;;; Each time a modification happens to a line, we re-fontify the entire line.
|
|
891 ;;; We do this by first removing the extents (text properties) on the line,
|
|
892 ;;; and then doing the syntactic and keyword passes again on that line. (More
|
|
893 ;;; generally, each modified region is extended to include the preceding and
|
|
894 ;;; following BOL or EOL.)
|
|
895 ;;;
|
|
896 ;;; This means that, as the user types, we repeatedly go back to the beginning
|
|
897 ;;; of the line, doing more work the longer the line gets. This doesn't cost
|
|
898 ;;; much in practice, and if we don't, then we incorrectly fontify things when,
|
|
899 ;;; for example, inserting spaces into `intfoo () {}'.
|
|
900 ;;;
|
|
901
|
|
902
|
|
903 ;; The user level functions
|
|
904
|
|
905 ;;;###autoload
|
|
906 (defun font-lock-mode (&optional arg)
|
|
907 "Toggle Font Lock Mode.
|
|
908 With arg, turn font-lock mode on if and only if arg is positive.
|
|
909
|
|
910 When Font Lock mode is enabled, text is fontified as you type it:
|
|
911
|
|
912 - Comments are displayed in `font-lock-comment-face';
|
|
913 - Strings are displayed in `font-lock-string-face';
|
|
914 - Documentation strings (in Lisp-like languages) are displayed in
|
|
915 `font-lock-doc-string-face';
|
|
916 - Language keywords (\"reserved words\") are displayed in
|
|
917 `font-lock-keyword-face';
|
|
918 - Function names in their defining form are displayed in
|
|
919 `font-lock-function-name-face';
|
|
920 - Variable names in their defining form are displayed in
|
|
921 `font-lock-variable-name-face';
|
|
922 - Type names are displayed in `font-lock-type-face';
|
|
923 - References appearing in help files and the like are displayed
|
|
924 in `font-lock-reference-face';
|
|
925 - Preprocessor declarations are displayed in
|
|
926 `font-lock-preprocessor-face';
|
|
927
|
|
928 and
|
|
929
|
|
930 - Certain other expressions are displayed in other faces according
|
|
931 to the value of the variable `font-lock-keywords'.
|
|
932
|
|
933 Where modes support different levels of fontification, you can use the variable
|
|
934 `font-lock-maximum-decoration' to specify which level you generally prefer.
|
|
935 When you turn Font Lock mode on/off the buffer is fontified/defontified, though
|
|
936 fontification occurs only if the buffer is less than `font-lock-maximum-size'.
|
|
937 To fontify a buffer without turning on Font Lock mode, and regardless of buffer
|
|
938 size, you can use \\[font-lock-fontify-buffer].
|
|
939
|
|
940 See the variable `font-lock-keywords' for customization."
|
|
941 (interactive "P")
|
|
942 (let ((on-p (if arg (> (prefix-numeric-value arg) 0) (not font-lock-mode)))
|
|
943 (maximum-size (if (not (consp font-lock-maximum-size))
|
|
944 font-lock-maximum-size
|
|
945 (cdr (or (assq major-mode font-lock-maximum-size)
|
|
946 (assq t font-lock-maximum-size))))))
|
531
|
947 ;; Font-lock mode will refuse to turn itself on if in batch mode
|
|
948 ;; to avoid potential (probably not actual, though) slowdown. We
|
|
949 ;; used to try to "be nice" by avoiding doing this in temporary
|
|
950 ;; buffers. But with the deferral code we don't need this, and it
|
|
951 ;; definitely screws some things up.
|
|
952 (if (noninteractive)
|
428
|
953 (setq on-p nil))
|
|
954 (cond (on-p
|
|
955 (make-local-hook 'after-change-functions)
|
|
956 (add-hook 'after-change-functions
|
|
957 'font-lock-after-change-function nil t)
|
|
958 (add-hook 'pre-idle-hook 'font-lock-pre-idle-hook))
|
|
959 (t
|
|
960 (remove-hook 'after-change-functions
|
|
961 'font-lock-after-change-function t)
|
|
962 (setq font-lock-defaults-computed nil
|
|
963 font-lock-keywords nil)
|
|
964 ;; We have no business doing this here, since
|
|
965 ;; pre-idle-hook is global. Other buffers may
|
|
966 ;; still be in font-lock mode. -dkindred@cs.cmu.edu
|
|
967 ;; (remove-hook 'pre-idle-hook 'font-lock-pre-idle-hook)
|
|
968 ))
|
|
969 (set (make-local-variable 'font-lock-mode) on-p)
|
|
970 (cond (on-p
|
|
971 (font-lock-set-defaults-1)
|
|
972 (run-hooks 'font-lock-mode-hook)
|
|
973 (cond (font-lock-fontified
|
|
974 nil)
|
|
975 ((or (null maximum-size) (<= (buffer-size) maximum-size))
|
|
976 (font-lock-fontify-buffer))
|
|
977 (font-lock-verbose
|
442
|
978 (progress-feedback-with-label
|
|
979 'font-lock
|
|
980 "Fontifying %s... buffer too big." 'abort
|
|
981 (buffer-name)))))
|
428
|
982 (font-lock-fontified
|
|
983 (setq font-lock-fontified nil)
|
|
984 (font-lock-unfontify-region (point-min) (point-max))
|
|
985 (font-lock-thing-lock-cleanup))
|
|
986 (t
|
|
987 (font-lock-thing-lock-cleanup)))
|
|
988 (redraw-modeline)))
|
|
989
|
|
990 ;; For init-file hooks
|
|
991 ;;;###autoload
|
|
992 (defun turn-on-font-lock ()
|
|
993 "Unconditionally turn on Font Lock mode."
|
444
|
994 (interactive)
|
428
|
995 (font-lock-mode 1))
|
|
996
|
|
997 ;;;###autoload
|
|
998 (defun turn-off-font-lock ()
|
|
999 "Unconditionally turn off Font Lock mode."
|
444
|
1000 (interactive)
|
428
|
1001 (font-lock-mode 0))
|
|
1002
|
|
1003 ;;; FSF has here:
|
|
1004
|
|
1005 ;; support for add-keywords, global-font-lock-mode and
|
|
1006 ;; font-lock-support-mode (unified support for various *-lock modes).
|
|
1007
|
|
1008
|
|
1009 ;; Fontification functions.
|
|
1010
|
|
1011 ;; We first define some defsubsts to encapsulate the way we add
|
|
1012 ;; faces to a region of text. I am planning on modifying the
|
|
1013 ;; text-property mechanism so that multiple independent classes
|
|
1014 ;; of text properties can exist. That way, for example, ediff's
|
|
1015 ;; face text properties don't interfere with font lock's face
|
|
1016 ;; text properties. Due to the XEmacs implementation of text
|
|
1017 ;; properties in terms of extents, doing this is fairly trivial:
|
|
1018 ;; instead of using the `text-prop' property, you just use a
|
|
1019 ;; specified property.
|
|
1020
|
|
1021 (defsubst font-lock-set-face (start end face)
|
|
1022 ;; Set the face on the characters in the range.
|
|
1023 (put-nonduplicable-text-property start end 'face face)
|
|
1024 (put-nonduplicable-text-property start end 'font-lock t))
|
|
1025
|
|
1026 (defsubst font-lock-remove-face (start end)
|
|
1027 ;; Remove any syntax highlighting on the characters in the range.
|
|
1028 (put-nonduplicable-text-property start end 'face nil)
|
460
|
1029 (put-nonduplicable-text-property start end 'font-lock nil)
|
|
1030 (if lookup-syntax-properties
|
|
1031 (put-nonduplicable-text-property start end 'syntax-table nil)))
|
|
1032
|
|
1033 (defsubst font-lock-set-syntax (start end syntax)
|
|
1034 ;; Set the face on the characters in the range.
|
|
1035 (put-nonduplicable-text-property start end 'syntax-table syntax)
|
|
1036 (put-nonduplicable-text-property start end 'font-lock t))
|
428
|
1037
|
|
1038 (defsubst font-lock-any-faces-p (start end)
|
|
1039 ;; Return non-nil if we've put any syntax highlighting on
|
|
1040 ;; the characters in the range.
|
|
1041 ;;
|
|
1042 ;; used to look for 'text-prop property, but this has problems if
|
|
1043 ;; you put any other text properties in the vicinity. Simon
|
|
1044 ;; Marshall suggested looking for the 'face property (this is what
|
|
1045 ;; FSF Emacs does) but that's equally bogus. Only reliable way is
|
|
1046 ;; for font-lock to specially mark its extents.
|
|
1047 ;;
|
|
1048 ;; FSF's (equivalent) definition of this defsubst would be
|
|
1049 ;; (text-property-not-all start end 'font-lock nil)
|
|
1050 ;;
|
|
1051 ;; Perhaps our `map-extents' is faster than our definition
|
|
1052 ;; of `text-property-not-all'. #### If so, `text-property-not-all'
|
|
1053 ;; should be fixed ...
|
|
1054 ;;
|
|
1055 (map-extents 'extent-property (current-buffer) start (1- end) 'font-lock))
|
|
1056
|
|
1057
|
|
1058 ;; Fontification functions.
|
|
1059
|
|
1060 ;; Rather than the function, e.g., `font-lock-fontify-region' containing the
|
|
1061 ;; code to fontify a region, the function runs the function whose name is the
|
|
1062 ;; value of the variable, e.g., `font-lock-fontify-region-function'. Normally,
|
|
1063 ;; the value of this variable is, e.g., `font-lock-default-fontify-region'
|
|
1064 ;; which does contain the code to fontify a region. However, the value of the
|
|
1065 ;; variable could be anything and thus, e.g., `font-lock-fontify-region' could
|
|
1066 ;; do anything. The indirection of the fontification functions gives major
|
|
1067 ;; modes the capability of modifying the way font-lock.el fontifies. Major
|
|
1068 ;; modes can modify the values of, e.g., `font-lock-fontify-region-function',
|
|
1069 ;; via the variable `font-lock-defaults'.
|
|
1070 ;;
|
|
1071 ;; For example, Rmail mode sets the variable `font-lock-defaults' so that
|
|
1072 ;; font-lock.el uses its own function for buffer fontification. This function
|
|
1073 ;; makes fontification be on a message-by-message basis and so visiting an
|
|
1074 ;; RMAIL file is much faster. A clever implementation of the function might
|
|
1075 ;; fontify the headers differently than the message body. (It should, and
|
|
1076 ;; correspondingly for Mail mode, but I can't be bothered to do the work. Can
|
|
1077 ;; you?) This hints at a more interesting use...
|
|
1078 ;;
|
|
1079 ;; Languages that contain text normally contained in different major modes
|
|
1080 ;; could define their own fontification functions that treat text differently
|
|
1081 ;; depending on its context. For example, Perl mode could arrange that here
|
|
1082 ;; docs are fontified differently than Perl code. Or Yacc mode could fontify
|
|
1083 ;; rules one way and C code another. Neat!
|
|
1084 ;;
|
|
1085 ;; A further reason to use the fontification indirection feature is when the
|
|
1086 ;; default syntactual fontification, or the default fontification in general,
|
|
1087 ;; is not flexible enough for a particular major mode. For example, perhaps
|
|
1088 ;; comments are just too hairy for `font-lock-fontify-syntactically-region' to
|
|
1089 ;; cope with. You need to write your own version of that function, e.g.,
|
|
1090 ;; `hairy-fontify-syntactically-region', and make your own version of
|
|
1091 ;; `hairy-fontify-region' call that function before calling
|
|
1092 ;; `font-lock-fontify-keywords-region' for the normal regexp fontification
|
|
1093 ;; pass. And Hairy mode would set `font-lock-defaults' so that font-lock.el
|
|
1094 ;; would call your region fontification function instead of its own. For
|
|
1095 ;; example, TeX modes could fontify {\foo ...} and \bar{...} etc. multi-line
|
|
1096 ;; directives correctly and cleanly. (It is the same problem as fontifying
|
|
1097 ;; multi-line strings and comments; regexps are not appropriate for the job.)
|
|
1098
|
|
1099 ;;;###autoload
|
|
1100 (defun font-lock-fontify-buffer ()
|
|
1101 "Fontify the current buffer the way `font-lock-mode' would.
|
|
1102 See `font-lock-mode' for details.
|
|
1103
|
|
1104 This can take a while for large buffers."
|
|
1105 (interactive)
|
|
1106 (let ((font-lock-verbose (or font-lock-verbose (interactive-p))))
|
|
1107 (funcall font-lock-fontify-buffer-function)))
|
|
1108
|
|
1109 (defun font-lock-unfontify-buffer ()
|
|
1110 (funcall font-lock-unfontify-buffer-function))
|
|
1111
|
|
1112 (defun font-lock-fontify-region (beg end &optional loudly)
|
|
1113 (funcall font-lock-fontify-region-function beg end loudly))
|
|
1114
|
|
1115 (defun font-lock-unfontify-region (beg end &optional loudly)
|
|
1116 (funcall font-lock-unfontify-region-function beg end loudly))
|
|
1117
|
|
1118 (defun font-lock-default-fontify-buffer ()
|
|
1119 (interactive)
|
442
|
1120 ;; if we don't widen, then the C code will fail to
|
|
1121 ;; realize that we're inside a comment.
|
|
1122 (save-restriction
|
|
1123 (widen)
|
|
1124 (let ((was-on font-lock-mode)
|
|
1125 (font-lock-verbose (or font-lock-verbose (interactive-p)))
|
|
1126 (font-lock-message-threshold 0)
|
|
1127 (aborted nil))
|
|
1128 ;; Turn it on to run hooks and get the right font-lock-keywords.
|
|
1129 (or was-on (font-lock-mode 1))
|
|
1130 (font-lock-unfontify-region (point-min) (point-max) t)
|
|
1131 ;; (buffer-syntactic-context-flush-cache)
|
428
|
1132
|
442
|
1133 ;; If a ^G is typed during fontification, abort the fontification, but
|
|
1134 ;; return normally (do not signal.) This is to make it easy to abort
|
|
1135 ;; fontification if it's taking a long time, without also causing the
|
|
1136 ;; buffer not to pop up. If a real abort is desired, the user can ^G
|
|
1137 ;; again.
|
|
1138 ;;
|
|
1139 ;; Possibly this should happen down in font-lock-fontify-region instead
|
|
1140 ;; of here, but since that happens from the after-change-hook (meaning
|
|
1141 ;; much more frequently) I'm afraid of the bad consequences of stealing
|
|
1142 ;; the interrupt character at inopportune times.
|
|
1143 ;;
|
|
1144 (condition-case nil
|
|
1145 (save-excursion
|
|
1146 (font-lock-fontify-region (point-min) (point-max)))
|
|
1147 (t
|
|
1148 (setq aborted t)))
|
428
|
1149
|
442
|
1150 (or was-on ; turn it off if it was off.
|
|
1151 (let ((font-lock-fontified nil)) ; kludge to prevent defontification
|
|
1152 (font-lock-mode 0)))
|
|
1153 (set (make-local-variable 'font-lock-fontified) t)
|
|
1154 (when (and aborted font-lock-verbose)
|
|
1155 (progress-feedback-with-label 'font-lock "Fontifying %s... aborted."
|
|
1156 'abort (buffer-name))))
|
|
1157 (run-hooks 'font-lock-after-fontify-buffer-hook)))
|
428
|
1158
|
|
1159 (defun font-lock-default-unfontify-buffer ()
|
|
1160 (font-lock-unfontify-region (point-min) (point-max))
|
|
1161 (set (make-local-variable 'font-lock-fontified) nil))
|
|
1162
|
|
1163 ;; This used to be `font-lock-fontify-region', and before that,
|
|
1164 ;; `font-lock-fontify-region' used to be the name used for what is now
|
|
1165 ;; `font-lock-fontify-syntactically-region'.
|
|
1166 (defun font-lock-default-fontify-region (beg end &optional loudly)
|
|
1167 (let ((modified (buffer-modified-p))
|
|
1168 (buffer-undo-list t) (inhibit-read-only t)
|
|
1169 (old-syntax-table (syntax-table))
|
|
1170 buffer-file-name buffer-file-truename)
|
|
1171 (unwind-protect
|
|
1172 (progn
|
|
1173 ;; Use the fontification syntax table, if any.
|
|
1174 (if font-lock-syntax-table (set-syntax-table font-lock-syntax-table))
|
|
1175 ;; Now do the fontification.
|
460
|
1176 (font-lock-unfontify-region beg end)
|
|
1177 (when font-lock-syntactic-keywords
|
|
1178 (font-lock-fontify-syntactic-keywords-region beg end))
|
|
1179 (unless font-lock-keywords-only
|
428
|
1180 (font-lock-fontify-syntactically-region beg end loudly))
|
|
1181 (font-lock-fontify-keywords-region beg end loudly))
|
|
1182 ;; Clean up.
|
|
1183 (set-syntax-table old-syntax-table)
|
|
1184 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil)))))
|
|
1185
|
|
1186 ;; The following must be rethought, since keywords can override fontification.
|
|
1187 ; ;; Now scan for keywords, but not if we are inside a comment now.
|
|
1188 ; (or (and (not font-lock-keywords-only)
|
|
1189 ; (let ((state (parse-partial-sexp beg end nil nil
|
|
1190 ; font-lock-cache-state)))
|
|
1191 ; (or (nth 4 state) (nth 7 state))))
|
|
1192 ; (font-lock-fontify-keywords-region beg end))
|
|
1193
|
|
1194 (defun font-lock-default-unfontify-region (beg end &optional maybe-loudly)
|
|
1195 (when (and maybe-loudly font-lock-verbose
|
|
1196 (>= (- end beg) font-lock-message-threshold))
|
442
|
1197 (progress-feedback-with-label 'font-lock "Fontifying %s..." 0
|
|
1198 (buffer-name)))
|
428
|
1199 (let ((modified (buffer-modified-p))
|
|
1200 (buffer-undo-list t) (inhibit-read-only t)
|
|
1201 buffer-file-name buffer-file-truename)
|
|
1202 (font-lock-remove-face beg end)
|
|
1203 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil))))
|
|
1204
|
|
1205 ;; Following is the original FSF version (similar to our original
|
442
|
1206 ;; version, before the deferred stuff was added).
|
428
|
1207 ;;
|
|
1208 ;; I think that lazy-lock v2 tries to do something similar.
|
|
1209 ;; Those efforts should be merged.
|
|
1210
|
|
1211 ;; Called when any modification is made to buffer text.
|
|
1212 ;(defun font-lock-after-change-function (beg end old-len)
|
|
1213 ; (save-excursion
|
|
1214 ; (save-match-data
|
|
1215 ; ;; Rescan between start of line from `beg' and start of line after `end'.
|
|
1216 ; (font-lock-fontify-region
|
|
1217 ; (progn (goto-char beg) (beginning-of-line) (point))
|
|
1218 ; (progn (goto-char end) (forward-line 1) (point))))))
|
|
1219
|
442
|
1220 (defvar font-lock-always-fontify-immediately nil
|
|
1221 "Set this to non-nil to disable font-lock deferral.
|
|
1222 Otherwise, changes to existing text will not be processed until the
|
|
1223 next redisplay cycle, avoiding excessive fontification when many
|
|
1224 buffer modifications are performed or a buffer is reverted.")
|
428
|
1225
|
462
|
1226 ;; list of buffers in which there is a pending change.
|
|
1227 (defvar font-lock-pending-buffer-table (make-hash-table :weakness 'key))
|
|
1228 ;; table used to keep track of ranges needing fontification.
|
442
|
1229 (defvar font-lock-range-table (make-range-table))
|
428
|
1230
|
|
1231 (defun font-lock-pre-idle-hook ()
|
793
|
1232 (with-trapping-errors 'font-lock-pre-idle-hook
|
|
1233 (if (> (hash-table-count font-lock-pending-buffer-table) 0)
|
|
1234 (font-lock-fontify-pending-extents))))
|
428
|
1235
|
|
1236 ;;; called when any modification is made to buffer text. This function
|
442
|
1237 ;;; remembers the changed ranges until the next redisplay, at which point
|
|
1238 ;;; the extents are merged and pruned, and the resulting ranges fontified.
|
|
1239 ;;; This function could easily be adapted to other after-change-functions.
|
428
|
1240
|
|
1241 (defun font-lock-after-change-function (beg end old-len)
|
442
|
1242 (when font-lock-mode
|
462
|
1243 ;; treat deletions as if the following character (or previous, if
|
664
|
1244 ;; there is no following) were inserted. (also use the previous
|
|
1245 ;; character at end of line. this avoids a problem when you
|
|
1246 ;; insert a comment on the line before a line of code: if we use
|
|
1247 ;; the following char, then when you hit backspace, the following
|
|
1248 ;; line of code turns the comment color.) this is a bit of a hack
|
462
|
1249 ;; but allows us to use text properties for everything.
|
|
1250 (if (= beg end)
|
670
|
1251 (cond ((not (save-excursion (goto-char end) (eolp)))
|
|
1252 (setq end (1+ end)))
|
462
|
1253 ((/= beg (point-min)) (setq beg (1- beg)))
|
|
1254 (t nil)))
|
|
1255 (put-text-property beg end 'font-lock-pending t)
|
|
1256 (puthash (current-buffer) t font-lock-pending-buffer-table)
|
442
|
1257 (if font-lock-always-fontify-immediately
|
|
1258 (font-lock-fontify-pending-extents))))
|
428
|
1259
|
442
|
1260 (defun font-lock-fontify-pending-extents ()
|
|
1261 ;; ah, the beauty of mapping functions.
|
|
1262 ;; this function is actually shorter than the old version, which handled
|
|
1263 ;; only one buffer and one contiguous region!
|
|
1264 (save-match-data
|
|
1265 (maphash
|
462
|
1266 #'(lambda (buffer dummy)
|
442
|
1267 ;; remove first, to avoid infinite reprocessing if error
|
462
|
1268 (remhash buffer font-lock-pending-buffer-table)
|
442
|
1269 (when (buffer-live-p buffer)
|
|
1270 (clear-range-table font-lock-range-table)
|
|
1271 (with-current-buffer buffer
|
|
1272 (save-excursion
|
|
1273 (save-restriction
|
462
|
1274 ;; if we don't widen, then the C code in
|
|
1275 ;; syntactically-sectionize will fail to realize that
|
|
1276 ;; we're inside a comment. #### We don't actually use
|
|
1277 ;; syntactically-sectionize any more. Do we still
|
|
1278 ;; need the widen?
|
442
|
1279 (widen)
|
502
|
1280 (map-extents
|
|
1281 #'(lambda (ex dummy-maparg)
|
|
1282 ;; first expand the ranges to full lines,
|
|
1283 ;; because that is what will be fontified;
|
|
1284 ;; then use a range table to merge the
|
|
1285 ;; ranges. (we could also do this simply using
|
|
1286 ;; text properties. the range table code was
|
|
1287 ;; here from a previous version of this code
|
|
1288 ;; and works just as well.)
|
|
1289 (let* ((beg (extent-start-position ex))
|
|
1290 (end (extent-end-position ex))
|
|
1291 (beg (progn (goto-char beg)
|
|
1292 (beginning-of-line)
|
|
1293 (point)))
|
|
1294 (end (progn (goto-char end)
|
|
1295 (forward-line 1)
|
|
1296 (point))))
|
|
1297 (put-range-table beg end t
|
|
1298 font-lock-range-table)))
|
|
1299 nil nil nil nil nil 'font-lock-pending t)
|
|
1300 ;; clear all pending extents first in case of error below.
|
|
1301 (put-text-property (point-min) (point-max)
|
|
1302 'font-lock-pending nil)
|
|
1303 (map-range-table
|
|
1304 #'(lambda (beg end val)
|
462
|
1305 ;; This creates some unnecessary progress gauges.
|
442
|
1306 ;; (if (and (= beg (point-min))
|
|
1307 ;; (= end (point-max)))
|
|
1308 ;; (font-lock-fontify-buffer)
|
|
1309 ;; (font-lock-fontify-region beg end)))
|
502
|
1310 (font-lock-fontify-region beg end))
|
|
1311 font-lock-range-table))))))
|
462
|
1312 font-lock-pending-buffer-table)))
|
428
|
1313
|
|
1314 ;; Syntactic fontification functions.
|
|
1315
|
430
|
1316 (defun font-lock-lisp-like (mode)
|
|
1317 ;; Note: (or (get mode 'font-lock-lisp-like) (string-match ...)) is
|
|
1318 ;; not enough because the property needs to be able to specify a nil
|
|
1319 ;; value.
|
|
1320 (if (plist-member (symbol-plist mode) 'font-lock-lisp-like)
|
|
1321 (get mode 'font-lock-lisp-like)
|
|
1322 ;; If the property is not specified, guess. Similar logic exists
|
|
1323 ;; in add-log, but I think this encompasses more modes.
|
|
1324 (string-match "lisp\\|scheme" (symbol-name mode))))
|
|
1325
|
460
|
1326 ;; fontify-syntactically-region used to use syntactically-sectionize, which
|
|
1327 ;; was supposedly much faster than the FSF version because it was written in
|
|
1328 ;; C. However, the FSF version uses parse-partial-sexp, which is also
|
|
1329 ;; written in C, and the benchmarking I did showed the
|
|
1330 ;; syntactically-sectionize code to be slower overall. So here's the FSF
|
|
1331 ;; version, modified to support font-lock-doc-string-face.
|
|
1332 ;; -- mct 2000-12-29
|
428
|
1333 (defun font-lock-fontify-syntactically-region (start end &optional loudly)
|
|
1334 "Put proper face on each string and comment between START and END.
|
|
1335 START should be at the beginning of a line."
|
|
1336 (if font-lock-keywords-only
|
|
1337 nil
|
460
|
1338
|
|
1339 ;; #### Shouldn't this just be using 'loudly??
|
428
|
1340 (when (and font-lock-verbose
|
|
1341 (>= (- end start) font-lock-message-threshold))
|
442
|
1342 (progress-feedback-with-label 'font-lock
|
|
1343 "Fontifying %s... (syntactically)" 5
|
|
1344 (buffer-name)))
|
428
|
1345 (goto-char start)
|
460
|
1346
|
|
1347 (let ((lisp-like (font-lock-lisp-like major-mode))
|
|
1348 (cache (marker-position font-lock-cache-position))
|
|
1349 state string beg depth)
|
|
1350 ;;
|
|
1351 ;; Find the state at the `beginning-of-line' before `start'.
|
|
1352 (if (eq start cache)
|
|
1353 ;; Use the cache for the state of `start'.
|
|
1354 (setq state font-lock-cache-state)
|
|
1355 ;; Find the state of `start'.
|
|
1356 (if (null font-lock-beginning-of-syntax-function)
|
|
1357 ;; Use the state at the previous cache position, if any, or
|
|
1358 ;; otherwise calculate from `point-min'.
|
|
1359 (if (or (null cache) (< start cache))
|
|
1360 (setq state (parse-partial-sexp (point-min) start))
|
|
1361 (setq state (parse-partial-sexp cache start nil nil
|
|
1362 font-lock-cache-state)))
|
|
1363 ;; Call the function to move outside any syntactic block.
|
|
1364 (funcall font-lock-beginning-of-syntax-function)
|
|
1365 (setq state (parse-partial-sexp (point) start)))
|
|
1366 ;; Cache the state and position of `start'.
|
|
1367 (setq font-lock-cache-state state)
|
|
1368 (set-marker font-lock-cache-position start))
|
|
1369 ;;
|
|
1370 ;; If the region starts inside a string or comment, show the extent of it.
|
|
1371 (when (or (nth 3 state) (nth 4 state))
|
|
1372 (setq string (nth 3 state) beg (point))
|
|
1373 (setq state (parse-partial-sexp (point) end nil nil state 'syntax-table))
|
|
1374 (font-lock-set-face beg (point) (if string
|
|
1375 font-lock-string-face
|
|
1376 font-lock-comment-face)))
|
|
1377 ;;
|
|
1378 ;; Find each interesting place between here and `end'.
|
|
1379 (while (and (< (point) end)
|
|
1380 (progn
|
|
1381 (setq state (parse-partial-sexp (point) end nil nil state
|
|
1382 'syntax-table))
|
|
1383 (or (nth 3 state) (nth 4 state))))
|
|
1384 (setq depth (nth 0 state) string (nth 3 state) beg (nth 8 state))
|
|
1385 (setq state (parse-partial-sexp (point) end nil nil state 'syntax-table))
|
|
1386 (if string
|
|
1387 ;; #### It would be nice if we handled Python and other
|
|
1388 ;; non-Lisp languages with docstrings correctly.
|
|
1389 (let ((face (if (and lisp-like (= depth 1))
|
|
1390 'font-lock-doc-string-face
|
|
1391 'font-lock-string-face)))
|
|
1392 (if font-lock-fontify-string-delimiters
|
|
1393 (font-lock-set-face beg (point) face)
|
|
1394 (font-lock-set-face (+ beg 1) (- (point) 1) face)))
|
|
1395 (font-lock-set-face beg (point)
|
|
1396 font-lock-comment-face))))))
|
428
|
1397
|
|
1398 ;;; Additional text property functions.
|
|
1399
|
|
1400 ;; The following three text property functions are not generally available (and
|
|
1401 ;; it's not certain that they should be) so they are inlined for speed.
|
|
1402 ;; The case for `fillin-text-property' is simple; it may or not be generally
|
|
1403 ;; useful. (Since it is used here, it is useful in at least one place.;-)
|
|
1404 ;; However, the case for `append-text-property' and `prepend-text-property' is
|
|
1405 ;; more complicated. Should they remove duplicate property values or not? If
|
|
1406 ;; so, should the first or last duplicate item remain? Or the one that was
|
|
1407 ;; added? In our implementation, the first duplicate remains.
|
|
1408
|
|
1409 ;; XEmacs: modified all these functions to use
|
|
1410 ;; `put-nonduplicable-text-property' instead of `put-text-property', and
|
|
1411 ;; the first one to take both SETPROP and MARKPROP, in accordance with the
|
|
1412 ;; changed definitions of `font-lock-any-faces-p' and `font-lock-set-face'.
|
|
1413
|
|
1414 (defsubst font-lock-fillin-text-property (start end setprop markprop value &optional object)
|
|
1415 "Fill in one property of the text from START to END.
|
|
1416 Arguments PROP and VALUE specify the property and value to put where none are
|
|
1417 already in place. Therefore existing property values are not overwritten.
|
|
1418 Optional argument OBJECT is the string or buffer containing the text."
|
|
1419 (let ((start (text-property-any start end markprop nil object)) next)
|
|
1420 (while start
|
|
1421 (setq next (next-single-property-change start markprop object end))
|
|
1422 (put-nonduplicable-text-property start next setprop value object)
|
|
1423 (put-nonduplicable-text-property start next markprop value object)
|
|
1424 (setq start (text-property-any next end markprop nil object)))))
|
|
1425
|
|
1426 ;; This function (from simon's unique.el) is rewritten and inlined for speed.
|
|
1427 ;(defun unique (list function)
|
|
1428 ; "Uniquify LIST, deleting elements using FUNCTION.
|
|
1429 ;Return the list with subsequent duplicate items removed by side effects.
|
|
1430 ;FUNCTION is called with an element of LIST and a list of elements from LIST,
|
|
1431 ;and should return the list of elements with occurrences of the element removed,
|
|
1432 ;i.e., a function such as `delete' or `delq'.
|
|
1433 ;This function will work even if LIST is unsorted. See also `uniq'."
|
|
1434 ; (let ((list list))
|
|
1435 ; (while list
|
|
1436 ; (setq list (setcdr list (funcall function (car list) (cdr list))))))
|
|
1437 ; list)
|
|
1438
|
|
1439 (defsubst font-lock-unique (list)
|
|
1440 "Uniquify LIST, deleting elements using `delq'.
|
|
1441 Return the list with subsequent duplicate items removed by side effects."
|
|
1442 (let ((list list))
|
|
1443 (while list
|
|
1444 (setq list (setcdr list (delq (car list) (cdr list))))))
|
|
1445 list)
|
|
1446
|
|
1447 ;; A generalisation of `facemenu-add-face' for any property, but without the
|
|
1448 ;; removal of inactive faces via `facemenu-discard-redundant-faces' and special
|
|
1449 ;; treatment of `default'. Uses `unique' to remove duplicate property values.
|
|
1450 (defsubst font-lock-prepend-text-property (start end prop value &optional object)
|
|
1451 "Prepend to one property of the text from START to END.
|
|
1452 Arguments PROP and VALUE specify the property and value to prepend to the value
|
|
1453 already in place. The resulting property values are always lists, and unique.
|
|
1454 Optional argument OBJECT is the string or buffer containing the text."
|
|
1455 (let ((val (if (listp value) value (list value))) next prev)
|
|
1456 (while (/= start end)
|
|
1457 (setq next (next-single-property-change start prop object end)
|
|
1458 prev (get-text-property start prop object))
|
|
1459 (put-text-property
|
|
1460 start next prop
|
|
1461 (font-lock-unique (append val (if (listp prev) prev (list prev))))
|
|
1462 object)
|
|
1463 (setq start next))))
|
|
1464
|
|
1465 (defsubst font-lock-append-text-property (start end prop value &optional object)
|
|
1466 "Append to one property of the text from START to END.
|
|
1467 Arguments PROP and VALUE specify the property and value to append to the value
|
|
1468 already in place. The resulting property values are always lists, and unique.
|
|
1469 Optional argument OBJECT is the string or buffer containing the text."
|
|
1470 (let ((val (if (listp value) value (list value))) next prev)
|
|
1471 (while (/= start end)
|
|
1472 (setq next (next-single-property-change start prop object end)
|
|
1473 prev (get-text-property start prop object))
|
|
1474 (put-text-property
|
|
1475 start next prop
|
|
1476 (font-lock-unique (append (if (listp prev) prev (list prev)) val))
|
|
1477 object)
|
|
1478 (setq start next))))
|
|
1479
|
460
|
1480 ;;; Syntactic regexp fontification functions (taken from FSF Emacs 20.7.1)
|
|
1481
|
|
1482 ;; These syntactic keyword pass functions are identical to those keyword pass
|
|
1483 ;; functions below, with the following exceptions; (a) they operate on
|
|
1484 ;; `font-lock-syntactic-keywords' of course, (b) they are all `defun' as speed
|
|
1485 ;; is less of an issue, (c) eval of property value does not occur JIT as speed
|
|
1486 ;; is less of an issue, (d) OVERRIDE cannot be `prepend' or `append' as it
|
|
1487 ;; makes no sense for `syntax-table' property values, (e) they do not do it
|
|
1488 ;; LOUDLY as it is not likely to be intensive.
|
|
1489
|
|
1490 (defun font-lock-apply-syntactic-highlight (highlight)
|
|
1491 "Apply HIGHLIGHT following a match.
|
948
|
1492 HIGHLIGHT should be of the form MATCH-HIGHLIGHT,
|
|
1493 see `font-lock-syntactic-keywords'."
|
460
|
1494 (let* ((match (nth 0 highlight))
|
|
1495 (start (match-beginning match)) (end (match-end match))
|
|
1496 (value (nth 1 highlight))
|
|
1497 (override (nth 2 highlight)))
|
|
1498 (unless (numberp (car-safe value))
|
|
1499 (setq value (eval value)))
|
|
1500 (cond ((not start)
|
|
1501 ;; No match but we might not signal an error.
|
|
1502 (or (nth 3 highlight)
|
|
1503 (error "No match %d in highlight %S" match highlight)))
|
|
1504 ((not override)
|
|
1505 ;; Cannot override existing fontification.
|
|
1506 (or (map-extents 'extent-property (current-buffer)
|
|
1507 start end 'syntax-table)
|
|
1508 (font-lock-set-syntax start end value)))
|
|
1509 ((eq override t)
|
|
1510 ;; Override existing fontification.
|
|
1511 (font-lock-set-syntax start end value))
|
|
1512 ((eq override 'keep)
|
|
1513 ;; Keep existing fontification.
|
|
1514 (font-lock-fillin-text-property start end
|
|
1515 'syntax-table 'font-lock value)))))
|
|
1516
|
|
1517 (defun font-lock-fontify-syntactic-anchored-keywords (keywords limit)
|
|
1518 "Fontify according to KEYWORDS until LIMIT.
|
|
1519 KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords',
|
|
1520 LIMIT can be modified by the value of its PRE-MATCH-FORM."
|
|
1521 (let ((matcher (nth 0 keywords)) (lowdarks (nthcdr 3 keywords)) highlights
|
|
1522 ;; Evaluate PRE-MATCH-FORM.
|
|
1523 (pre-match-value (eval (nth 1 keywords))))
|
|
1524 ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line.
|
|
1525 (if (and (numberp pre-match-value) (> pre-match-value (point)))
|
|
1526 (setq limit pre-match-value)
|
|
1527 (save-excursion (end-of-line) (setq limit (point))))
|
|
1528 (save-match-data
|
|
1529 ;; Find an occurrence of `matcher' before `limit'.
|
|
1530 (while (if (stringp matcher)
|
|
1531 (re-search-forward matcher limit t)
|
|
1532 (funcall matcher limit))
|
|
1533 ;; Apply each highlight to this instance of `matcher'.
|
|
1534 (setq highlights lowdarks)
|
|
1535 (while highlights
|
|
1536 (font-lock-apply-syntactic-highlight (car highlights))
|
|
1537 (setq highlights (cdr highlights)))))
|
|
1538 ;; Evaluate POST-MATCH-FORM.
|
|
1539 (eval (nth 2 keywords))))
|
|
1540
|
|
1541 (defun font-lock-fontify-syntactic-keywords-region (start end)
|
|
1542 "Fontify according to `font-lock-syntactic-keywords' between START and END.
|
|
1543 START should be at the beginning of a line."
|
|
1544 ;; ;; If `font-lock-syntactic-keywords' is a symbol, get the real keywords.
|
|
1545 (when (symbolp font-lock-syntactic-keywords)
|
|
1546 (setq font-lock-syntactic-keywords (font-lock-eval-keywords
|
|
1547 font-lock-syntactic-keywords)))
|
|
1548 ;; If `font-lock-syntactic-keywords' is not compiled, compile it.
|
|
1549 (unless (eq (car font-lock-syntactic-keywords) t)
|
|
1550 (setq font-lock-syntactic-keywords (font-lock-compile-keywords
|
|
1551 font-lock-syntactic-keywords)))
|
|
1552 ;; Get down to business.
|
|
1553 (let ((case-fold-search font-lock-keywords-case-fold-search)
|
|
1554 (keywords (cdr font-lock-syntactic-keywords))
|
|
1555 keyword matcher highlights)
|
|
1556 (while keywords
|
|
1557 ;; Find an occurrence of `matcher' from `start' to `end'.
|
|
1558 (setq keyword (car keywords) matcher (car keyword))
|
|
1559 (goto-char start)
|
|
1560 (while (if (stringp matcher)
|
|
1561 (re-search-forward matcher end t)
|
|
1562 (funcall matcher end))
|
|
1563 ;; Apply each highlight to this instance of `matcher', which may be
|
|
1564 ;; specific highlights or more keywords anchored to `matcher'.
|
|
1565 (setq highlights (cdr keyword))
|
|
1566 (while highlights
|
|
1567 (if (numberp (car (car highlights)))
|
|
1568 (font-lock-apply-syntactic-highlight (car highlights))
|
|
1569 (font-lock-fontify-syntactic-anchored-keywords (car highlights)
|
|
1570 end))
|
948
|
1571 (setq highlights (cdr highlights))))
|
460
|
1572 (setq keywords (cdr keywords)))))
|
|
1573
|
428
|
1574 ;;; Regexp fontification functions.
|
|
1575
|
|
1576 (defsubst font-lock-apply-highlight (highlight)
|
|
1577 "Apply HIGHLIGHT following a match.
|
|
1578 HIGHLIGHT should be of the form MATCH-HIGHLIGHT, see `font-lock-keywords'."
|
|
1579 (let* ((match (nth 0 highlight))
|
|
1580 (start (match-beginning match)) (end (match-end match))
|
|
1581 (override (nth 2 highlight)))
|
|
1582 (let ((newface (nth 1 highlight)))
|
|
1583 (or (symbolp newface)
|
|
1584 (setq newface (eval newface)))
|
|
1585 (cond ((not start)
|
|
1586 ;; No match but we might not signal an error.
|
|
1587 (or (nth 3 highlight)
|
|
1588 (error "No match %d in highlight %S" match highlight)))
|
|
1589 ((= start end) nil)
|
|
1590 ((not override)
|
|
1591 ;; Cannot override existing fontification.
|
|
1592 (or (font-lock-any-faces-p start end)
|
|
1593 (font-lock-set-face start end newface)))
|
|
1594 ((eq override t)
|
|
1595 ;; Override existing fontification.
|
|
1596 (font-lock-set-face start end newface))
|
|
1597 ((eq override 'keep)
|
|
1598 ;; Keep existing fontification.
|
|
1599 (font-lock-fillin-text-property start end 'face 'font-lock
|
|
1600 newface))
|
|
1601 ((eq override 'prepend)
|
|
1602 ;; Prepend to existing fontification.
|
|
1603 (font-lock-prepend-text-property start end 'face newface))
|
|
1604 ((eq override 'append)
|
|
1605 ;; Append to existing fontification.
|
|
1606 (font-lock-append-text-property start end 'face newface))))))
|
|
1607
|
|
1608 (defsubst font-lock-fontify-anchored-keywords (keywords limit)
|
|
1609 "Fontify according to KEYWORDS until LIMIT.
|
|
1610 KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords',
|
|
1611 LIMIT can be modified by the value of its PRE-MATCH-FORM."
|
|
1612 (let ((matcher (nth 0 keywords)) (lowdarks (nthcdr 3 keywords)) highlights
|
|
1613 ;; Evaluate PRE-MATCH-FORM.
|
|
1614 (pre-match-value (eval (nth 1 keywords))))
|
|
1615 ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line.
|
|
1616 (if (and (numberp pre-match-value) (> pre-match-value (point)))
|
|
1617 (setq limit pre-match-value)
|
|
1618 (save-excursion (end-of-line) (setq limit (point))))
|
|
1619 (save-match-data
|
|
1620 ;; Find an occurrence of `matcher' before `limit'.
|
|
1621 (while (if (stringp matcher)
|
|
1622 (re-search-forward matcher limit t)
|
|
1623 (funcall matcher limit))
|
|
1624 ;; Apply each highlight to this instance of `matcher'.
|
|
1625 (setq highlights lowdarks)
|
|
1626 (while highlights
|
|
1627 (font-lock-apply-highlight (car highlights))
|
|
1628 (setq highlights (cdr highlights)))))
|
|
1629 ;; Evaluate POST-MATCH-FORM.
|
|
1630 (eval (nth 2 keywords))))
|
|
1631
|
|
1632 (defun font-lock-fontify-keywords-region (start end &optional loudvar)
|
|
1633 "Fontify according to `font-lock-keywords' between START and END.
|
|
1634 START should be at the beginning of a line."
|
|
1635 (let ((loudly (and font-lock-verbose
|
|
1636 (>= (- end start) font-lock-message-threshold))))
|
566
|
1637 ;; If `font-lock-keywords' is not compiled, compile it.
|
|
1638 (unless (eq (car-safe font-lock-keywords) t)
|
|
1639 (setq font-lock-keywords (font-lock-compile-keywords
|
|
1640 font-lock-keywords)))
|
442
|
1641 (let* ((case-fold-search font-lock-keywords-case-fold-search)
|
566
|
1642 (keywords (cdr font-lock-keywords))
|
442
|
1643 (bufname (buffer-name))
|
|
1644 (progress 5) (old-progress 5)
|
|
1645 (iter 0)
|
|
1646 (nkeywords (length keywords))
|
|
1647 keyword matcher highlights)
|
428
|
1648 ;;
|
|
1649 ;; Fontify each item in `font-lock-keywords' from `start' to `end'.
|
442
|
1650 ;; In order to measure progress accurately we need to know how
|
|
1651 ;; many keywords we have and how big the region is. Then progress
|
|
1652 ;; is ((pos - start)/ (end - start) * nkeywords
|
|
1653 ;; + iteration / nkeywords) * 100
|
428
|
1654 (while keywords
|
|
1655 ;;
|
|
1656 ;; Find an occurrence of `matcher' from `start' to `end'.
|
|
1657 (setq keyword (car keywords) matcher (car keyword))
|
|
1658 (goto-char start)
|
|
1659 (while (and (< (point) end)
|
|
1660 (if (stringp matcher)
|
|
1661 (re-search-forward matcher end t)
|
|
1662 (funcall matcher end)))
|
442
|
1663 ;; calculate progress
|
|
1664 (setq progress
|
|
1665 (+ (/ (* (- (point) start) 95) (* (- end start) nkeywords))
|
|
1666 (/ (* iter 95) nkeywords) 5))
|
|
1667 (when (and loudly (> progress old-progress))
|
|
1668 (progress-feedback-with-label 'font-lock
|
|
1669 "Fontifying %s... (regexps)"
|
|
1670 progress bufname))
|
|
1671 (setq old-progress progress)
|
428
|
1672 ;; Apply each highlight to this instance of `matcher', which may be
|
|
1673 ;; specific highlights or more keywords anchored to `matcher'.
|
|
1674 (setq highlights (cdr keyword))
|
|
1675 (while highlights
|
|
1676 (if (numberp (car (car highlights)))
|
|
1677 (let ((end (match-end (car (car highlights)))))
|
|
1678 (font-lock-apply-highlight (car highlights))
|
|
1679 ;; restart search just after the end of the
|
|
1680 ;; keyword so keywords can share bracketing
|
|
1681 ;; expressions.
|
|
1682 (and end (goto-char end)))
|
|
1683 (font-lock-fontify-anchored-keywords (car highlights) end))
|
|
1684 (setq highlights (cdr highlights))))
|
442
|
1685 (setq iter (1+ iter))
|
428
|
1686 (setq keywords (cdr keywords))))
|
442
|
1687 (if loudly
|
|
1688 (progress-feedback-with-label 'font-lock "Fontifying %s... " 100
|
|
1689 (buffer-name)))))
|
428
|
1690
|
|
1691
|
|
1692 ;; Various functions.
|
|
1693
|
|
1694 ;; Turn off other related packages if they're on. I prefer a hook. --sm.
|
|
1695 ;; These explicit calls are easier to understand
|
|
1696 ;; because people know what they will do.
|
|
1697 ;; A hook is a mystery because it might do anything whatever. --rms.
|
|
1698 (defun font-lock-thing-lock-cleanup ()
|
776
|
1699 (cond ((and-boundp 'fast-lock-mode fast-lock-mode)
|
|
1700 (declare-fboundp (fast-lock-mode -1)))
|
|
1701 ((and-boundp 'lazy-lock-mode lazy-lock-mode)
|
|
1702 (declare-fboundp (lazy-lock-mode -1)))
|
|
1703 ((and-boundp 'lazy-shot-mode lazy-shot-mode)
|
|
1704 (declare-fboundp (lazy-shot-mode -1)))))
|
428
|
1705
|
502
|
1706 ; Do something special for these packages after fontifying. I prefer a hook.
|
428
|
1707 (defun font-lock-after-fontify-buffer ()
|
776
|
1708 (cond ((and-boundp 'fast-lock-mode fast-lock-mode)
|
502
|
1709 (declare-fboundp (fast-lock-after-fontify-buffer)))
|
776
|
1710 ((and-boundp 'lazy-lock-mode lazy-lock-mode)
|
502
|
1711 (declare-fboundp (lazy-lock-after-fontify-buffer)))))
|
428
|
1712
|
|
1713
|
|
1714 ;; Various functions.
|
|
1715
|
566
|
1716 (defun font-lock-compile-keywords (keywords)
|
948
|
1717 "Compile KEYWORDS into the form (t KEYWORD ...).
|
|
1718 Here KEYWORD is of the form (MATCHER HIGHLIGHT ...) as shown in the
|
|
1719 `font-lock-keywords' doc string."
|
566
|
1720 (if (eq (car-safe keywords) t)
|
|
1721 keywords
|
|
1722 (cons t (mapcar 'font-lock-compile-keyword keywords))))
|
428
|
1723
|
|
1724 (defun font-lock-compile-keyword (keyword)
|
|
1725 (cond ((nlistp keyword) ; Just MATCHER
|
|
1726 (list keyword '(0 font-lock-keyword-face)))
|
|
1727 ((eq (car keyword) 'eval) ; Specified (eval . FORM)
|
|
1728 (font-lock-compile-keyword (eval (cdr keyword))))
|
|
1729 ((numberp (cdr keyword)) ; Specified (MATCHER . MATCH)
|
|
1730 (list (car keyword) (list (cdr keyword) 'font-lock-keyword-face)))
|
|
1731 ((symbolp (cdr keyword)) ; Specified (MATCHER . FACENAME)
|
|
1732 (list (car keyword) (list 0 (cdr keyword))))
|
|
1733 ((nlistp (nth 1 keyword)) ; Specified (MATCHER . HIGHLIGHT)
|
|
1734 (list (car keyword) (cdr keyword)))
|
|
1735 (t ; Hopefully (MATCHER HIGHLIGHT ...)
|
|
1736 keyword)))
|
|
1737
|
460
|
1738 (defun font-lock-eval-keywords (keywords)
|
948
|
1739 "Evaluate KEYWORDS if a function (funcall) or variable (eval) name."
|
460
|
1740 (if (listp keywords)
|
|
1741 keywords
|
|
1742 (font-lock-eval-keywords (if (fboundp keywords)
|
|
1743 (funcall keywords)
|
|
1744 (eval keywords)))))
|
|
1745
|
428
|
1746 (defun font-lock-choose-keywords (keywords level)
|
|
1747 ;; Return LEVELth element of KEYWORDS. A LEVEL of nil is equal to a
|
|
1748 ;; LEVEL of 0, a LEVEL of t is equal to (1- (length KEYWORDS)).
|
|
1749 (let ((level (if (not (consp level))
|
|
1750 level
|
|
1751 (cdr (or (assq major-mode level) (assq t level))))))
|
|
1752 (cond ((symbolp keywords)
|
|
1753 keywords)
|
|
1754 ((numberp level)
|
|
1755 (or (nth level keywords) (car (reverse keywords))))
|
|
1756 ((eq level t)
|
|
1757 (car (reverse keywords)))
|
|
1758 (t
|
|
1759 (car keywords)))))
|
|
1760
|
|
1761
|
|
1762 ;;; Determining which set of font-lock keywords to use.
|
|
1763
|
|
1764 (defun font-lock-find-font-lock-defaults (modesym)
|
|
1765 ;; Get the defaults based on the major mode.
|
|
1766 (let (raw-defaults)
|
|
1767 ;; I want a do-while loop!
|
|
1768 (while (progn
|
|
1769 (setq raw-defaults (get modesym 'font-lock-defaults))
|
|
1770 (and raw-defaults (symbolp raw-defaults)
|
|
1771 (setq modesym raw-defaults)))
|
|
1772 )
|
|
1773 raw-defaults))
|
|
1774
|
|
1775 (defun font-lock-examine-syntax-table ()
|
|
1776 ; Computes the value of font-lock-keywords-only for this buffer.
|
|
1777 (if (eq (syntax-table) (standard-syntax-table))
|
|
1778 ;; Assume that modes which haven't bothered to install their own
|
|
1779 ;; syntax table don't do anything syntactically interesting.
|
|
1780 ;; Really, the standard-syntax-table shouldn't have comments and
|
|
1781 ;; strings in it, but changing that now might break things.
|
|
1782 nil
|
|
1783 ;; else map over the syntax table looking for strings or comments.
|
|
1784 (let (got-one)
|
|
1785 ;; XEmacs 20.0 ...
|
|
1786 (if (fboundp 'map-syntax-table)
|
|
1787 (setq got-one
|
|
1788 (map-syntax-table
|
|
1789 #'(lambda (key value)
|
|
1790 (memq (char-syntax-from-code value)
|
|
1791 '(?\" ?\< ?\> ?\$)))
|
|
1792 (syntax-table)))
|
|
1793 ;; older Emacsen.
|
|
1794 (let ((i (1- (length (syntax-table)))))
|
|
1795 (while (>= i 0)
|
|
1796 (if (memq (char-syntax i) '(?\" ?\< ?\> ?\$))
|
|
1797 (setq got-one t i 0))
|
|
1798 (setq i (1- i)))))
|
|
1799 (set (make-local-variable 'font-lock-keywords-only) (not got-one)))))
|
|
1800
|
|
1801 ;; font-lock-set-defaults is in fontl-hooks.el.
|
|
1802
|
|
1803 ;;;###autoload
|
|
1804 (defun font-lock-set-defaults-1 (&optional explicit-defaults)
|
|
1805 ;; does everything that font-lock-set-defaults does except
|
|
1806 ;; enable font-lock-mode. This is called by `font-lock-mode'.
|
|
1807 ;; Note that the return value is used!
|
|
1808
|
|
1809 (if (and font-lock-defaults-computed (not explicit-defaults))
|
|
1810 ;; nothing to do.
|
|
1811 nil
|
|
1812
|
|
1813 (or font-lock-keywords
|
|
1814 (let* ((defaults (or (and (not (eq t explicit-defaults))
|
|
1815 explicit-defaults)
|
|
1816 ;; in case modes decide to set
|
|
1817 ;; `font-lock-defaults' themselves,
|
|
1818 ;; as in FSF Emacs.
|
|
1819 font-lock-defaults
|
|
1820 (font-lock-find-font-lock-defaults major-mode)))
|
|
1821 (keywords (font-lock-choose-keywords
|
|
1822 (nth 0 defaults) font-lock-maximum-decoration)))
|
460
|
1823
|
428
|
1824 ;; Keywords?
|
|
1825 (setq font-lock-keywords (if (fboundp keywords)
|
|
1826 (funcall keywords)
|
|
1827 (eval keywords)))
|
|
1828 (or font-lock-keywords
|
|
1829 ;; older way:
|
|
1830 ;; try to look for a variable `foo-mode-font-lock-keywords',
|
|
1831 ;; or similar.
|
|
1832 (let ((major (symbol-name major-mode))
|
|
1833 (try #'(lambda (n)
|
|
1834 (if (stringp n) (setq n (intern-soft n)))
|
|
1835 (if (and n
|
|
1836 (boundp n))
|
|
1837 n
|
|
1838 nil))))
|
|
1839 (setq font-lock-keywords
|
|
1840 (symbol-value
|
|
1841 (or (funcall try (get major-mode 'font-lock-keywords))
|
|
1842 (funcall try (concat major "-font-lock-keywords"))
|
|
1843 (funcall try (and (string-match "-mode\\'" major)
|
|
1844 (concat (substring
|
|
1845 major 0
|
|
1846 (match-beginning 0))
|
|
1847 "-font-lock-keywords")))
|
|
1848 'font-lock-keywords)))))
|
|
1849
|
|
1850 ;; Case fold?
|
|
1851 (if (>= (length defaults) 3)
|
|
1852 (setq font-lock-keywords-case-fold-search (nth 2 defaults))
|
|
1853 ;; older way:
|
|
1854 ;; look for a property 'font-lock-keywords-case-fold-search on
|
|
1855 ;; the major-mode symbol.
|
|
1856 (let* ((nonexist (make-symbol ""))
|
|
1857 (value (get major-mode 'font-lock-keywords-case-fold-search
|
|
1858 nonexist)))
|
|
1859 (if (not (eq nonexist value))
|
|
1860 (setq font-lock-keywords-case-fold-search value))))
|
|
1861
|
|
1862 ;; Syntactic?
|
|
1863 (if (>= (length defaults) 2)
|
|
1864 (setq font-lock-keywords-only (nth 1 defaults))
|
|
1865 ;; older way:
|
|
1866 ;; cleverly examine the syntax table.
|
|
1867 (font-lock-examine-syntax-table))
|
|
1868
|
|
1869 ;; Syntax table?
|
|
1870 (if (nth 3 defaults)
|
|
1871 (let ((slist (nth 3 defaults)))
|
|
1872 (setq font-lock-syntax-table
|
|
1873 (copy-syntax-table (syntax-table)))
|
|
1874 (while slist
|
|
1875 (modify-syntax-entry (car (car slist)) (cdr (car slist))
|
|
1876 font-lock-syntax-table)
|
|
1877 (setq slist (cdr slist)))))
|
|
1878
|
|
1879 ;; Syntax function?
|
|
1880 (cond (defaults
|
|
1881 (setq font-lock-beginning-of-syntax-function
|
|
1882 (nth 4 defaults)))
|
|
1883 (t
|
|
1884 ;; older way:
|
|
1885 ;; defaults not specified at all, so use `beginning-of-defun'.
|
|
1886 (setq font-lock-beginning-of-syntax-function
|
|
1887 'beginning-of-defun)))))
|
|
1888
|
460
|
1889 (setq font-lock-cache-position (make-marker))
|
428
|
1890 (setq font-lock-defaults-computed t)))
|
|
1891
|
|
1892
|
|
1893 ;;;;;;;;;;;;;;;;;;;;;; keywords ;;;;;;;;;;;;;;;;;;;;;;
|
|
1894
|
|
1895 ;;; Various major-mode interfaces.
|
|
1896 ;;; Probably these should go in with the source of the respective major modes.
|
|
1897
|
|
1898 ;; The defaults and keywords listed here should perhaps be moved into
|
|
1899 ;; mode-specific files.
|
|
1900
|
|
1901 ;; For C and Lisp modes we use `beginning-of-defun', rather than nil,
|
|
1902 ;; for SYNTAX-BEGIN. Thus the calculation of the cache is usually
|
|
1903 ;; faster but not infallible, so we risk mis-fontification. --sm.
|
|
1904
|
|
1905 (put 'c-mode 'font-lock-defaults
|
|
1906 '((c-font-lock-keywords
|
|
1907 c-font-lock-keywords-1 c-font-lock-keywords-2 c-font-lock-keywords-3)
|
|
1908 nil nil ((?_ . "w")) beginning-of-defun))
|
|
1909 (put 'c++-c-mode 'font-lock-defaults 'c-mode)
|
|
1910 (put 'elec-c-mode 'font-lock-defaults 'c-mode)
|
|
1911
|
|
1912 (put 'c++-mode 'font-lock-defaults
|
|
1913 '((c++-font-lock-keywords
|
|
1914 c++-font-lock-keywords-1 c++-font-lock-keywords-2
|
|
1915 c++-font-lock-keywords-3)
|
|
1916 nil nil ((?_ . "w") (?~ . "w")) beginning-of-defun))
|
|
1917
|
|
1918 (put 'java-mode 'font-lock-defaults
|
|
1919 '((java-font-lock-keywords
|
|
1920 java-font-lock-keywords-1 java-font-lock-keywords-2
|
|
1921 java-font-lock-keywords-3)
|
|
1922 nil nil ((?_ . "w")) beginning-of-defun
|
|
1923 (font-lock-mark-block-function . mark-defun)))
|
|
1924
|
|
1925 (put 'lisp-mode 'font-lock-defaults
|
|
1926 '((lisp-font-lock-keywords
|
|
1927 lisp-font-lock-keywords-1 lisp-font-lock-keywords-2)
|
|
1928 nil nil
|
|
1929 ((?: . "w") (?- . "w") (?* . "w") (?+ . "w") (?. . "w") (?< . "w")
|
|
1930 (?> . "w") (?= . "w") (?! . "w") (?? . "w") (?$ . "w") (?% . "w")
|
|
1931 (?_ . "w") (?& . "w") (?~ . "w") (?^ . "w") (?/ . "w"))
|
|
1932 beginning-of-defun))
|
|
1933 (put 'emacs-lisp-mode 'font-lock-defaults 'lisp-mode)
|
|
1934 (put 'lisp-interaction-mode 'font-lock-defaults 'lisp-mode)
|
|
1935
|
|
1936 (put 'scheme-mode 'font-lock-defaults
|
|
1937 '(scheme-font-lock-keywords
|
|
1938 nil t
|
|
1939 ((?: . "w") (?- . "w") (?* . "w") (?+ . "w") (?. . "w") (?< . "w")
|
|
1940 (?> . "w") (?= . "w") (?! . "w") (?? . "w") (?$ . "w") (?% . "w")
|
|
1941 (?_ . "w") (?& . "w") (?~ . "w") (?^ . "w") (?/ . "w"))
|
|
1942 beginning-of-defun))
|
|
1943 (put 'inferior-scheme-mode 'font-lock-defaults 'scheme-mode)
|
|
1944 (put 'scheme-interaction-mode 'font-lock-defaults 'scheme-mode)
|
|
1945
|
|
1946 (put 'tex-mode 'font-lock-defaults
|
|
1947 ;; For TeX modes we could use `backward-paragraph' for the same reason.
|
|
1948 '(tex-font-lock-keywords nil nil ((?$ . "\""))))
|
|
1949 ;; the nine billion names of TeX mode...
|
|
1950 (put 'bibtex-mode 'font-lock-defaults 'tex-mode)
|
|
1951 (put 'plain-tex-mode 'font-lock-defaults 'tex-mode)
|
|
1952 (put 'slitex-tex-mode 'font-lock-defaults 'tex-mode)
|
|
1953 (put 'SliTeX-mode 'font-lock-defaults 'tex-mode)
|
|
1954 (put 'slitex-mode 'font-lock-defaults 'tex-mode)
|
|
1955 (put 'latex-tex-mode 'font-lock-defaults 'tex-mode)
|
|
1956 (put 'LaTex-tex-mode 'font-lock-defaults 'tex-mode)
|
|
1957 (put 'latex-mode 'font-lock-defaults 'tex-mode)
|
|
1958 (put 'LaTeX-mode 'font-lock-defaults 'tex-mode)
|
|
1959 (put 'japanese-LaTeX-mode 'font-lock-defaults 'tex-mode)
|
|
1960 (put 'japanese-SliTeX-mode 'font-lock-defaults 'tex-mode)
|
|
1961 (put 'FoilTeX-mode 'font-lock-defaults 'tex-mode)
|
|
1962 (put 'LATeX-MoDe 'font-lock-defaults 'tex-mode)
|
|
1963 (put 'lATEx-mODe 'font-lock-defaults 'tex-mode)
|
|
1964 ;; ok, this is getting a bit silly ...
|
|
1965 (put 'eDOm-xETAl 'font-lock-defaults 'tex-mode)
|
|
1966
|
|
1967 ;;; Various regexp information shared by several modes.
|
|
1968 ;;; Information specific to a single mode should go in its load library.
|
|
1969
|
|
1970 (defconst lisp-font-lock-keywords-1
|
|
1971 (list
|
771
|
1972 ;; Anything not a function or type declaration is fontified as a
|
|
1973 ;; variable. It would be cleaner to allow preceding whitespace, but it
|
|
1974 ;; would also be about five times slower. We used to fontify unknown
|
|
1975 ;; stuff as functions, rather than variables, but random things are
|
|
1976 ;; generally more like variables (no parameters), and the function and
|
|
1977 ;; keyword colors are currently the same, while the variable color is
|
|
1978 ;; different, which looks better.
|
872
|
1979 (list (concat
|
|
1980 "^(\\(" lisp-function-and-type-regexp
|
|
1981 ;; Former variable declarations, but woefully inadequate.
|
|
1982 ;; "\\|def\\(const\\(\\|ant\\)\\|ine-key\\(\\|-after\\)\\|"
|
|
1983 ;; "var\\|custom\\)"
|
|
1984 ;; Everything else is a variable declaration.
|
|
1985 ;; anything else is a variable
|
|
1986 "\\|def\\([^ \t\n\(\)]+\\)"
|
|
1987 ;; make sure we are at end of word.
|
|
1988 "\\)\\>"
|
|
1989 ;; Any whitespace following and declared object.
|
|
1990 "[ \t'\(]*"
|
|
1991 "\\([^ \t\n\)]+\\)?")
|
|
1992 ;; Note about numbering: #1 is the grouping around the whole
|
|
1993 ;; keyword. #2 - #4 are in lisp-function-and-type-regexp.
|
|
1994 ;; #5 is for variables. (Must be set if neither #3 nor #4 are.)
|
|
1995 ;; #6 for the following object.
|
|
1996 '(1 font-lock-keyword-face)
|
|
1997 '(6 (cond ((match-beginning 3) 'font-lock-function-name-face)
|
|
1998 ((match-beginning 4) 'font-lock-type-face)
|
|
1999 (t 'font-lock-variable-name-face))
|
|
2000 nil t))
|
428
|
2001 )
|
|
2002 "Subdued level highlighting Lisp modes.")
|
|
2003
|
|
2004 (defconst lisp-font-lock-keywords-2
|
|
2005 (append lisp-font-lock-keywords-1
|
|
2006 (list
|
|
2007 ;;
|
|
2008 ;; Control structures. ELisp and CLisp combined.
|
|
2009 ;;
|
|
2010 (cons
|
|
2011 (concat
|
|
2012 "(\\("
|
442
|
2013 ;; beginning of generated stuff
|
|
2014 ;; to regenerate, use the regexp-opt below, then delete the outermost
|
|
2015 ;; grouping, then use the macro below to break up the string.
|
|
2016 ;; (regexp-opt
|
|
2017 ;; '("cond" "if" "while" "let" "let*" "prog" "progn" "prog1"
|
|
2018 ;; "prog2" "progv" "catch" "throw" "save-restriction"
|
|
2019 ;; "save-excursion" "save-window-excursion"
|
|
2020 ;; "save-current-buffer" "with-current-buffer"
|
|
2021 ;; "save-selected-window" "with-selected-window"
|
|
2022 ;; "save-selected-frame" "with-selected-frame"
|
|
2023 ;; "with-temp-file" "with-temp-buffer" "with-output-to-string"
|
|
2024 ;; "with-string-as-buffer-contents"
|
|
2025 ;; "save-match-data" "unwind-protect" "call-with-condition-handler"
|
|
2026 ;; "condition-case" "track-mouse" "autoload"
|
|
2027 ;; "eval-after-load" "eval-and-compile" "eval-when-compile"
|
|
2028 ;; "when" "unless" "do" "dolist" "dotimes" "flet" "labels"
|
|
2029 ;; "lambda" "block" "return" "return-from" "loop") t)
|
|
2030 ;; (setq last-kbd-macro
|
|
2031 ;; (read-kbd-macro "\" C-7 C-1 <right> C-r \\\\| 3*<right> \" RET"))
|
|
2032 "autoload\\|block\\|c\\(?:a\\(?:ll-with-condition-handler\\|tch\\)\\|"
|
|
2033 "ond\\(?:ition-case\\)?\\)\\|do\\(?:list\\|times\\)?\\|"
|
|
2034 "eval-\\(?:a\\(?:fter-load\\|nd-compile\\)\\|when-compile\\)\\|flet\\|"
|
|
2035 "if\\|l\\(?:a\\(?:bels\\|mbda\\)\\|et\\*?\\|oop\\)\\|prog[12nv]?\\|"
|
|
2036 "return\\(?:-from\\)?\\|save-\\(?:current-buffer\\|excursion\\|"
|
|
2037 "match-data\\|restriction\\|selected-\\(?:frame\\|window\\)\\|"
|
|
2038 "window-excursion\\)\\|t\\(?:hrow\\|rack-mouse\\)\\|un\\(?:less\\|"
|
|
2039 "wind-protect\\)\\|w\\(?:h\\(?:en\\|ile\\)\\|ith-\\(?:current-buffer\\|"
|
|
2040 "output-to-string\\|s\\(?:elected-\\(?:frame\\|window\\)\\|"
|
|
2041 "tring-as-buffer-contents\\)\\|temp-\\(?:buffer\\|file\\)\\)\\)"
|
|
2042 ;; end of generated stuff
|
428
|
2043 "\\)\\>") 1)
|
|
2044 ;;
|
|
2045 ;; Feature symbols as references.
|
|
2046 '("(\\(featurep\\|provide\\|require\\)\\>[ \t']*\\(\\sw+\\)?"
|
|
2047 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
|
|
2048 ;;
|
|
2049 ;; Words inside \\[] tend to be for `substitute-command-keys'.
|
|
2050 '("\\\\\\\\\\[\\(\\sw+\\)]" 1 font-lock-reference-face prepend)
|
|
2051 ;;
|
|
2052 ;; Words inside `' tend to be symbol names.
|
|
2053 '("`\\(\\sw\\sw+\\)'" 1 font-lock-reference-face prepend)
|
|
2054 ;;
|
|
2055 ;; CLisp `:' keywords as references.
|
|
2056 '("\\<:\\sw+\\>" 0 font-lock-reference-face prepend)
|
|
2057 ;;
|
|
2058 ;; ELisp and CLisp `&' keywords as types.
|
|
2059 '("\\<\\&\\(optional\\|rest\\|whole\\)\\>" . font-lock-type-face)
|
|
2060 ))
|
|
2061 "Gaudy level highlighting for Lisp modes.")
|
|
2062
|
|
2063 (defvar lisp-font-lock-keywords lisp-font-lock-keywords-1
|
|
2064 "Default expressions to highlight in Lisp modes.")
|
|
2065
|
|
2066 ;; The previous version, before replacing it with the FSF version.
|
|
2067 ;(defconst lisp-font-lock-keywords-1 (purecopy
|
|
2068 ; '(;;
|
|
2069 ; ;; highlight defining forms. This doesn't work too nicely for
|
|
2070 ; ;; (defun (setf foo) ...) but it does work for (defvar foo) which
|
|
2071 ; ;; is more important.
|
|
2072 ; ("^(def[-a-z]+\\s +\\([^ \t\n\)]+\\)" 1 font-lock-function-name-face)
|
|
2073 ; ;;
|
|
2074 ; ;; highlight CL keywords (three clauses seems faster than one)
|
|
2075 ; ("\\s :\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1)
|
|
2076 ; ("(:\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1)
|
|
2077 ; ("':\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1)
|
|
2078 ; ;;
|
|
2079 ; ;; this is highlights things like (def* (setf foo) (bar baz)), but may
|
|
2080 ; ;; be slower (I haven't really thought about it)
|
|
2081 ;; ("^(def[-a-z]+\\s +\\(\\s(\\S)*\\s)\\|\\S(\\S *\\)"
|
|
2082 ;; 1 font-lock-function-name-face)
|
|
2083 ; ))
|
|
2084 ; "For consideration as a value of `lisp-font-lock-keywords'.
|
|
2085 ;This does fairly subdued highlighting.")
|
|
2086 ;
|
|
2087 ;(defconst lisp-font-lock-keywords-2 (purecopy
|
|
2088 ; (append lisp-font-lock-keywords-1
|
|
2089 ; '(;;
|
|
2090 ; ;; Highlight control structures
|
|
2091 ; ("(\\(cond\\|if\\|when\\|unless\\|[ec]?\\(type\\)?case\\)[ \t\n]" . 1)
|
|
2092 ; ("(\\(while\\|do\\|let\\*?\\|flet\\|labels\\|prog[nv12*]?\\)[ \t\n]" . 1)
|
|
2093 ; ("(\\(do\\*\\|dotimes\\|dolist\\|loop\\)[ \t\n]" . 1)
|
|
2094 ; ("(\\(catch\\|\\throw\\|block\\|return\\|return-from\\)[ \t\n]" . 1)
|
|
2095 ; ("(\\(save-restriction\\|save-window-restriction\\)[ \t\n]" . 1)
|
|
2096 ; ("(\\(save-excursion\\|unwind-protect\\|condition-case\\)[ \t\n]" . 1)
|
|
2097 ; ;;
|
|
2098 ; ;; highlight function names in emacs-lisp docstrings (in the syntax
|
|
2099 ; ;; that substitute-command-keys understands.)
|
|
2100 ; ("\\\\\\\\\\[\\([^]\\\n]+\\)]" 1 font-lock-keyword-face t)
|
|
2101 ; ;;
|
|
2102 ; ;; highlight words inside `' which tend to be function names
|
|
2103 ; ("`\\([-a-zA-Z0-9_][-a-zA-Z0-9_][-a-zA-Z0-9_.]+\\)'"
|
|
2104 ; 1 font-lock-keyword-face t)
|
|
2105 ; )))
|
|
2106 ; "For consideration as a value of `lisp-font-lock-keywords'.
|
|
2107 ;
|
|
2108 ;This does a lot more highlighting.")
|
|
2109
|
|
2110 (defvar scheme-font-lock-keywords
|
|
2111 (eval-when-compile
|
|
2112 (list
|
|
2113 ;;
|
|
2114 ;; Declarations. Hannes Haug <hannes.haug@student.uni-tuebingen.de> says
|
|
2115 ;; this works for SOS, STklos, SCOOPS, Meroon and Tiny CLOS.
|
|
2116 (list (concat "(\\(define\\("
|
|
2117 ;; Function names.
|
|
2118 "\\(\\|-\\(generic\\(\\|-procedure\\)\\|method\\)\\)\\|"
|
|
2119 ;; Macro names, as variable names. A bit dubious, this.
|
|
2120 "\\(-syntax\\)\\|"
|
|
2121 ;; Class names.
|
|
2122 "\\(-class\\)"
|
|
2123 "\\)\\)\\>"
|
|
2124 ;; Any whitespace and declared object.
|
|
2125 "[ \t]*(?"
|
|
2126 "\\(\\sw+\\)?")
|
|
2127 '(1 font-lock-keyword-face)
|
|
2128 '(8 (cond ((match-beginning 3) 'font-lock-function-name-face)
|
|
2129 ((match-beginning 6) 'font-lock-variable-name-face)
|
|
2130 (t 'font-lock-type-face))
|
|
2131 nil t))
|
|
2132 ;;
|
|
2133 ;; Control structures.
|
|
2134 ;(regexp-opt '("begin" "call-with-current-continuation" "call/cc"
|
|
2135 ; "call-with-input-file" "call-with-output-file" "case" "cond"
|
|
2136 ; "do" "else" "for-each" "if" "lambda"
|
|
2137 ; "let\\*?" "let-syntax" "letrec" "letrec-syntax"
|
|
2138 ; ;; Hannes Haug <hannes.haug@student.uni-tuebingen.de> wants:
|
|
2139 ; "and" "or" "delay"
|
|
2140 ; ;; Stefan Monnier <stefan.monnier@epfl.ch> says don't bother:
|
|
2141 ; ;;"quasiquote" "quote" "unquote" "unquote-splicing"
|
|
2142 ; "map" "syntax" "syntax-rules"))
|
|
2143 (cons
|
|
2144 (concat "(\\("
|
|
2145 "and\\|begin\\|c\\(a\\(ll\\(-with-\\(current-continuation\\|"
|
|
2146 "input-file\\|output-file\\)\\|/cc\\)\\|se\\)\\|ond\\)\\|"
|
|
2147 "d\\(elay\\|o\\)\\|else\\|for-each\\|if\\|"
|
|
2148 "l\\(ambda\\|et\\(-syntax\\|\\*?\\|rec\\(\\|-syntax\\)\\)\\)\\|"
|
|
2149 "map\\|or\\|syntax\\(\\|-rules\\)"
|
|
2150 "\\)\\>") 1)
|
|
2151 ;;
|
|
2152 ;; David Fox <fox@graphics.cs.nyu.edu> for SOS/STklos class specifiers.
|
|
2153 '("\\<<\\sw+>\\>" . font-lock-type-face)
|
|
2154 ;;
|
|
2155 ;; Scheme `:' keywords as references.
|
|
2156 '("\\<:\\sw+\\>" . font-lock-reference-face)
|
|
2157 ))
|
|
2158 "Default expressions to highlight in Scheme modes.")
|
|
2159
|
|
2160 ;; The previous version, before replacing it with the FSF version.
|
|
2161 ;(defconst scheme-font-lock-keywords (purecopy
|
|
2162 ; '(("(define[ \t]+(?\\([^ \t\n\)]+\\)" 1 font-lock-function-name-face)
|
|
2163 ; ("(\\(cond\\|lambda\\|begin\\|if\\|else\\|case\\|do\\)[ \t\n]" . 1)
|
|
2164 ; ("(\\(\\|letrec\\|let\\*?\\|set!\\|and\\|or\\)[ \t\n]" . 1)
|
|
2165 ; ("(\\(quote\\|unquote\\|quasiquote\\|unquote-splicing\\)[ \t\n]" . 1)
|
|
2166 ; ("(\\(syntax\\|syntax-rules\\|define-syntax\\|let-syntax\\|letrec-syntax\\)[ \t\n]" . 1)))
|
|
2167 ; "Expressions to highlight in Scheme buffers.")
|
|
2168
|
|
2169 (defconst c-font-lock-keywords-1 nil
|
|
2170 "Subdued level highlighting for C modes.")
|
|
2171
|
|
2172 (defconst c-font-lock-keywords-2 nil
|
|
2173 "Medium level highlighting for C modes.")
|
|
2174
|
|
2175 (defconst c-font-lock-keywords-3 nil
|
|
2176 "Gaudy level highlighting for C modes.")
|
|
2177
|
|
2178 (defconst c++-font-lock-keywords-1 nil
|
|
2179 "Subdued level highlighting for C++ modes.")
|
|
2180
|
|
2181 (defconst c++-font-lock-keywords-2 nil
|
|
2182 "Medium level highlighting for C++ modes.")
|
|
2183
|
|
2184 (defconst c++-font-lock-keywords-3 nil
|
|
2185 "Gaudy level highlighting for C++ modes.")
|
|
2186
|
|
2187 (defun font-lock-match-c++-style-declaration-item-and-skip-to-next (limit)
|
|
2188 ;; Match, and move over, any declaration/definition item after point.
|
|
2189 ;; The expect syntax of an item is "word" or "word::word", possibly ending
|
|
2190 ;; with optional whitespace and a "(". Everything following the item (but
|
|
2191 ;; belonging to it) is expected to by skip-able by `forward-sexp', and items
|
|
2192 ;; are expected to be separated with a "," or ";".
|
|
2193 (if (looking-at "[ \t*&]*\\(\\(?:\\sw\\|\\s_\\)+\\)\\(::\\(\\(?:\\sw\\|\\s_\\)+\\)\\)?[ \t]*\\((\\)?")
|
|
2194 (save-match-data
|
|
2195 (condition-case nil
|
|
2196 (save-restriction
|
|
2197 ;; Restrict to the end of line, currently guaranteed to be LIMIT.
|
|
2198 (narrow-to-region (point-min) limit)
|
|
2199 (goto-char (match-end 1))
|
|
2200 ;; Move over any item value, etc., to the next item.
|
|
2201 (while (not (looking-at "[ \t]*\\([,;]\\|$\\)"))
|
|
2202 (goto-char (or (scan-sexps (point) 1) (point-max))))
|
|
2203 (goto-char (match-end 0)))
|
|
2204 (error t)))))
|
|
2205
|
|
2206 (let ((c-keywords
|
|
2207 ; ("break" "continue" "do" "else" "for" "if" "return" "switch" "while")
|
|
2208 "break\\|continue\\|do\\|else\\|for\\|if\\|return\\|switch\\|while")
|
|
2209 (c-type-types
|
|
2210 ; ("auto" "extern" "register" "static" "typedef" "struct" "union" "enum"
|
|
2211 ; "signed" "unsigned" "short" "long" "int" "char" "float" "double"
|
|
2212 ; "void" "volatile" "const")
|
|
2213 (concat "auto\\|c\\(har\\|onst\\)\\|double\\|e\\(num\\|xtern\\)\\|"
|
|
2214 "float\\|int\\|long\\|register\\|"
|
|
2215 "s\\(hort\\|igned\\|t\\(atic\\|ruct\\)\\)\\|typedef\\|"
|
|
2216 "un\\(ion\\|signed\\)\\|vo\\(id\\|latile\\)")) ; 6 ()s deep.
|
|
2217 (c++-keywords
|
|
2218 ; ("break" "continue" "do" "else" "for" "if" "return" "switch" "while"
|
|
2219 ; "asm" "catch" "delete" "new" "operator" "sizeof" "this" "throw" "try"
|
448
|
2220 ; "protected" "private" "public" "const_cast" "dynamic_cast" "reinterpret_cast"
|
|
2221 ; "static_cast" "and" "bitor" "or" "xor" "compl" "bitand" "and_eq"
|
|
2222 ; "or_eq" "xor_eq" "not" "not_eq" "typeid" "false" "true")
|
|
2223 (concat "a\\(nd\\(\\|_eq\\)\\|sm\\)\\|"
|
|
2224 "b\\(it\\(or\\|and\\)\\|reak\\)\\|"
|
|
2225 "c\\(atch\\|o\\(mpl\\|n\\(tinue\\|st_cast\\)\\)\\)\\|"
|
|
2226 "d\\(elete\\|o\\|ynamic_cast\\)\\|"
|
|
2227 "else\\|"
|
|
2228 "f\\(alse\\|or\\)\\|if\\|"
|
|
2229 "n\\(ew\\|ot\\(\\|_eq\\)\\)\\|"
|
|
2230 "p\\(r\\(ivate\\|otected\\)\\|ublic\\)\\|"
|
|
2231 "or\\(\\|_eq\\)\\|"
|
|
2232 "re\\(interpret_cast\\|turn\\)\\|"
|
|
2233 "s\\(izeof\\|tatic_cast\\|witch\\)\\|"
|
|
2234 "t\\(h\\(is\\|row\\)\\|r\\(ue\\|y\\)\\|ypeid\\)\\|"
|
|
2235 "xor\\(\\|_eq\\)\\|while"))
|
428
|
2236 (c++-type-types
|
|
2237 ; ("auto" "extern" "register" "static" "typedef" "struct" "union" "enum"
|
|
2238 ; "signed" "unsigned" "short" "long" "int" "char" "float" "double"
|
|
2239 ; "void" "volatile" "const" "class" "inline" "friend" "bool"
|
448
|
2240 ; "virtual" "complex" "template" "explicit" "mutable" "export" "namespace"
|
|
2241 ; "using" "typename" "wchar_t")
|
428
|
2242 (concat "auto\\|bool\\|c\\(har\\|lass\\|o\\(mplex\\|nst\\)\\)\\|"
|
448
|
2243 "double\\|"
|
|
2244 "e\\(num\\|x\\(p\\(licit\\|ort\\)\\|tern\\)\\)\\|"
|
|
2245 "f\\(loat\\|riend\\)\\|"
|
|
2246 "in\\(line\\|t\\)\\|long\\|mutable\\|namespace\\|register\\|"
|
428
|
2247 "s\\(hort\\|igned\\|t\\(atic\\|ruct\\)\\)\\|"
|
448
|
2248 "t\\(emplate\\|ype\\(def\\|name\\)\\)\\|"
|
|
2249 "u\\(\\(n\\(ion\\|signed\\)\\|sing\\)\\)\\|"
|
|
2250 "v\\(irtual\\|o\\(id\\|latile\\)\\)\\|"
|
|
2251 "wchar_t")) ; 11 ()s deep.
|
428
|
2252 (ctoken "\\(\\sw\\|\\s_\\|[:~*&]\\)+")
|
|
2253 )
|
|
2254 (setq c-font-lock-keywords-1
|
|
2255 (list
|
|
2256 ;;
|
|
2257 ;; These are all anchored at the beginning of line for speed.
|
|
2258 ;;
|
|
2259 ;; Fontify function name definitions (GNU style; without type on line).
|
|
2260
|
|
2261 ;; In FSF this has the simpler definition of "\\sw+" for ctoken.
|
|
2262 ;; I'm not sure if ours is more correct.
|
|
2263 ;; This is a subset of the next rule, and is slower when present. --dmoore
|
|
2264 ;; (list (concat "^\\(" ctoken "\\)[ \t]*(") 1 'font-lock-function-name-face)
|
|
2265 ;;
|
|
2266 ;; fontify the names of functions being defined.
|
|
2267 ;; FSF doesn't have this but I think it should be fast for us because
|
|
2268 ;; our regexp routines are more intelligent than FSF's about handling
|
|
2269 ;; anchored-at-newline. (When I added this hack in regex.c, it halved
|
|
2270 ;; the time to do the regexp phase of font-lock for a C file!) Not
|
|
2271 ;; including this discriminates against those who don't follow the
|
|
2272 ;; GNU coding style. --ben
|
|
2273 ;; x?x?x?y?z should always be: (x(xx?)?)?y?z --dmoore
|
|
2274 (list (concat
|
|
2275 "^\\("
|
|
2276 "\\(" ctoken "[ \t]+\\)" ; type specs; there can be no
|
|
2277 "\\("
|
|
2278 "\\(" ctoken "[ \t]+\\)" ; more than 3 tokens, right?
|
|
2279 "\\(" ctoken "[ \t]+\\)"
|
|
2280 "?\\)?\\)?"
|
|
2281 "\\([*&]+[ \t]*\\)?" ; pointer
|
|
2282 "\\(" ctoken "\\)[ \t]*(") ; name
|
|
2283 10 'font-lock-function-name-face)
|
|
2284 ;;
|
|
2285 ;; This is faster but not by much. I don't see why not.
|
|
2286 ;(list (concat "^\\(" ctoken "\\)[ \t]*(") 1 'font-lock-function-name-face)
|
|
2287 ;;
|
|
2288 ;; Added next two; they're both jolly-good fastmatch candidates so
|
|
2289 ;; should be fast. --ben
|
|
2290 ;;
|
|
2291 ;; Fontify structure names (in structure definition form).
|
|
2292 (list (concat "^\\(typedef[ \t]+struct\\|struct\\|static[ \t]+struct\\)"
|
|
2293 "[ \t]+\\(" ctoken "\\)[ \t]*\\(\{\\|$\\)")
|
|
2294 2 'font-lock-function-name-face)
|
|
2295 ;;
|
|
2296 ;; Fontify case clauses. This is fast because its anchored on the left.
|
|
2297 '("case[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)[ \t]+:". 1)
|
|
2298 ;;
|
|
2299 '("\\<\\(default\\):". 1)
|
|
2300 ;; Fontify filenames in #include <...> preprocessor directives as strings.
|
|
2301 '("^#[ \t]*include[ \t]+\\(<[^>\"\n]+>\\)" 1 font-lock-string-face)
|
|
2302 ;;
|
|
2303 ;; Fontify function macro names.
|
|
2304 '("^#[ \t]*define[ \t]+\\(\\(\\sw+\\)(\\)" 2 font-lock-function-name-face)
|
|
2305 ;;
|
|
2306 ;; Fontify symbol names in #if ... defined preprocessor directives.
|
|
2307 '("^#[ \t]*if\\>"
|
|
2308 ("\\<\\(defined\\)\\>[ \t]*(?\\(\\sw+\\)?" nil nil
|
|
2309 (1 font-lock-preprocessor-face) (2 font-lock-variable-name-face nil t)))
|
|
2310 ;;
|
|
2311 ;; Fontify symbol names in #elif ... defined preprocessor directives.
|
|
2312 '("^#[ \t]*elif\\>"
|
|
2313 ("\\<\\(defined\\)\\>[ \t]*(?\\(\\sw+\\)?" nil nil
|
|
2314 (1 font-lock-preprocessor-face) (2 font-lock-variable-name-face nil t)))
|
|
2315 ;;
|
|
2316 ;; Fontify otherwise as symbol names, and the preprocessor directive names.
|
|
2317 '("^\\(#[ \t]*[a-z]+\\)\\>[ \t]*\\(\\sw+\\)?"
|
|
2318 (1 font-lock-preprocessor-face) (2 font-lock-variable-name-face nil t))
|
|
2319 ))
|
|
2320
|
|
2321 (setq c-font-lock-keywords-2
|
|
2322 (append c-font-lock-keywords-1
|
|
2323 (list
|
|
2324 ;;
|
|
2325 ;; Simple regexps for speed.
|
|
2326 ;;
|
|
2327 ;; Fontify all type specifiers.
|
|
2328 (cons (concat "\\<\\(" c-type-types "\\)\\>") 'font-lock-type-face)
|
|
2329 ;;
|
|
2330 ;; Fontify all builtin keywords (except case, default and goto; see below).
|
|
2331 (cons (concat "\\<\\(" c-keywords "\\)\\>") 'font-lock-keyword-face)
|
|
2332 ;;
|
|
2333 ;; Fontify case/goto keywords and targets, and case default/goto tags.
|
|
2334 '("\\<\\(case\\|goto\\)\\>[ \t]*\\([^ \t\n:;]+\\)?"
|
|
2335 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
|
|
2336 '("^[ \t]*\\(\\sw+\\)[ \t]*:" 1 font-lock-reference-face)
|
|
2337 )))
|
|
2338
|
|
2339 (setq c-font-lock-keywords-3
|
|
2340 (append c-font-lock-keywords-2
|
|
2341 ;;
|
|
2342 ;; More complicated regexps for more complete highlighting for types.
|
|
2343 ;; We still have to fontify type specifiers individually, as C is so hairy.
|
|
2344 (list
|
|
2345 ;;
|
|
2346 ;; Fontify all storage classes and type specifiers, plus their items.
|
|
2347 (list (concat "\\<\\(" c-type-types "\\)\\>"
|
|
2348 "\\([ \t*&]+\\sw+\\>\\)*")
|
|
2349 ;; Fontify each declaration item.
|
|
2350 '(font-lock-match-c++-style-declaration-item-and-skip-to-next
|
|
2351 ;; Start with point after all type specifiers.
|
|
2352 (goto-char (or (match-beginning 8) (match-end 1)))
|
|
2353 ;; Finish with point after first type specifier.
|
|
2354 (goto-char (match-end 1))
|
|
2355 ;; Fontify as a variable or function name.
|
|
2356 (1 (if (match-beginning 4)
|
|
2357 font-lock-function-name-face
|
|
2358 font-lock-variable-name-face))))
|
|
2359 ;;
|
|
2360 ;; Fontify structures, or typedef names, plus their items.
|
|
2361 '("\\(}\\)[ \t*]*\\sw"
|
|
2362 (font-lock-match-c++-style-declaration-item-and-skip-to-next
|
|
2363 (goto-char (match-end 1)) nil
|
|
2364 (1 (if (match-beginning 4)
|
|
2365 font-lock-function-name-face
|
|
2366 font-lock-variable-name-face))))
|
|
2367 ;;
|
|
2368 ;; Fontify anything at beginning of line as a declaration or definition.
|
|
2369 '("^\\(\\sw+\\)\\>\\([ \t*]+\\sw+\\>\\)*"
|
|
2370 (1 font-lock-type-face)
|
|
2371 (font-lock-match-c++-style-declaration-item-and-skip-to-next
|
|
2372 (goto-char (or (match-beginning 2) (match-end 1))) nil
|
|
2373 (1 (if (match-beginning 4)
|
|
2374 font-lock-function-name-face
|
|
2375 font-lock-variable-name-face))))
|
|
2376 )))
|
|
2377
|
|
2378 (setq c++-font-lock-keywords-1
|
|
2379 (append
|
|
2380 ;;
|
|
2381 ;; The list `c-font-lock-keywords-1' less that for function names.
|
|
2382 ;; the simple function form regexp has been removed. --dmoore
|
|
2383 ;;(cdr c-font-lock-keywords-1)
|
|
2384 c-font-lock-keywords-1
|
|
2385 ;;
|
|
2386 ;; Fontify function name definitions, possibly incorporating class name.
|
|
2387 (list
|
|
2388 '("^\\(\\sw+\\)\\(::\\(\\sw+\\)\\)?[ \t]*("
|
|
2389 (1 (if (match-beginning 2)
|
|
2390 font-lock-type-face
|
|
2391 font-lock-function-name-face))
|
|
2392 (3 (if (match-beginning 2) font-lock-function-name-face) nil t))
|
|
2393 )))
|
|
2394
|
|
2395 (setq c++-font-lock-keywords-2
|
|
2396 (append c++-font-lock-keywords-1
|
|
2397 (list
|
|
2398 ;;
|
|
2399 ;; The list `c-font-lock-keywords-2' for C++ plus operator overloading.
|
|
2400 (cons (concat "\\<\\(" c++-type-types "\\)\\>") 'font-lock-type-face)
|
|
2401 ;;
|
|
2402 ;; Fontify operator function name overloading.
|
|
2403 '("\\<\\(operator\\)\\>[ \t]*\\([][)(><!=+-][][)(><!=+-]?\\)?"
|
|
2404 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t))
|
|
2405 ;;
|
|
2406 ;; Fontify case/goto keywords and targets, and case default/goto tags.
|
|
2407 '("\\<\\(case\\|goto\\)\\>[ \t]*\\([^ \t\n:;]+\\)?"
|
|
2408 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
|
|
2409 '("^[ \t]*\\(\\sw+\\)[ \t]*:[^:]" 1 font-lock-reference-face)
|
|
2410 ;;
|
|
2411 ;; Fontify other builtin keywords.
|
|
2412 (cons (concat "\\<\\(" c++-keywords "\\)\\>") 'font-lock-keyword-face)
|
|
2413 )))
|
|
2414
|
|
2415 (setq c++-font-lock-keywords-3
|
|
2416 (append c++-font-lock-keywords-2
|
|
2417 ;;
|
|
2418 ;; More complicated regexps for more complete highlighting for types.
|
|
2419 (list
|
|
2420 ;;
|
|
2421 ;; Fontify all storage classes and type specifiers, plus their items.
|
|
2422 (list (concat "\\<\\(" c++-type-types "\\)\\>"
|
|
2423 "\\([ \t*&]+\\sw+\\>\\)*")
|
|
2424 ;; Fontify each declaration item.
|
|
2425 '(font-lock-match-c++-style-declaration-item-and-skip-to-next
|
|
2426 ;; Start with point after all type specifiers.
|
|
2427 (goto-char (or (match-beginning 13) (match-end 1)))
|
|
2428 ;; Finish with point after first type specifier.
|
|
2429 (goto-char (match-end 1))
|
|
2430 ;; Fontify as a variable or function name.
|
|
2431 (1 (cond ((match-beginning 2) 'font-lock-type-face)
|
|
2432 ((match-beginning 4) 'font-lock-function-name-face)
|
|
2433 (t 'font-lock-variable-name-face)))
|
|
2434 (3 (if (match-beginning 4)
|
|
2435 'font-lock-function-name-face
|
|
2436 'font-lock-variable-name-face) nil t)))
|
|
2437 ;;
|
|
2438 ;; Fontify structures, or typedef names, plus their items.
|
|
2439 '("\\(}\\)[ \t*]*\\sw"
|
|
2440 (font-lock-match-c++-style-declaration-item-and-skip-to-next
|
|
2441 (goto-char (match-end 1)) nil
|
|
2442 (1 (if (match-beginning 4)
|
|
2443 font-lock-function-name-face
|
|
2444 font-lock-variable-name-face))))
|
|
2445 ;;
|
|
2446 ;; Fontify anything at beginning of line as a declaration or definition.
|
|
2447 '("^\\(\\sw+\\)\\>\\([ \t*]+\\sw+\\>\\)*"
|
|
2448 (1 font-lock-type-face)
|
|
2449 (font-lock-match-c++-style-declaration-item-and-skip-to-next
|
|
2450 (goto-char (or (match-beginning 2) (match-end 1))) nil
|
|
2451 (1 (cond ((match-beginning 2) 'font-lock-type-face)
|
|
2452 ((match-beginning 4) 'font-lock-function-name-face)
|
|
2453 (t 'font-lock-variable-name-face)))
|
|
2454 (3 (if (match-beginning 4)
|
|
2455 'font-lock-function-name-face
|
|
2456 'font-lock-variable-name-face) nil t)))
|
|
2457 )))
|
|
2458 )
|
|
2459
|
|
2460 (defvar c-font-lock-keywords c-font-lock-keywords-1
|
|
2461 "Default expressions to highlight in C mode.")
|
|
2462
|
|
2463 (defvar c++-font-lock-keywords c++-font-lock-keywords-1
|
|
2464 "Default expressions to highlight in C++ mode.")
|
|
2465
|
|
2466 ;;; Java.
|
|
2467
|
|
2468 ;; Java support has been written by XEmacs people, and it's apparently
|
|
2469 ;; totally divergent from the FSF. I don't know if it's better or
|
|
2470 ;; worse, so I'm leaving it in until someone convinces me the FSF
|
|
2471 ;; version is better. --hniksic
|
|
2472
|
|
2473 (defconst java-font-lock-keywords-1 nil
|
|
2474 "For consideration as a value of `java-font-lock-keywords'.
|
|
2475 This does fairly subdued highlighting.")
|
|
2476
|
|
2477 (defconst java-font-lock-keywords-2 nil
|
|
2478 "For consideration as a value of `java-font-lock-keywords'.
|
|
2479 This adds highlighting of types and identifier names.")
|
|
2480
|
|
2481 (defconst java-font-lock-keywords-3 nil
|
|
2482 "For consideration as a value of `java-font-lock-keywords'.
|
|
2483 This adds highlighting of Java documentation tags, such as @see.")
|
|
2484
|
|
2485 (defvar java-font-lock-type-regexp
|
|
2486 (concat "\\<\\(boolean\\|byte\\|char\\|double\\|float\\|int"
|
|
2487 "\\|long\\|short\\|void\\)\\>")
|
|
2488 "Regexp which should match a primitive type.")
|
|
2489
|
|
2490 (defvar java-font-lock-identifier-regexp
|
442
|
2491 (let ((letter "a-zA-Z_$\300-\326\330-\366\370-\377")
|
|
2492 (digit "0-9"))
|
|
2493 (concat "\\<\\([" letter "][" letter digit "]*\\)\\>"))
|
428
|
2494 "Regexp which should match all Java identifiers.")
|
|
2495
|
|
2496 (defvar java-font-lock-class-name-regexp
|
442
|
2497 (let ((capital-letter "A-Z\300-\326\330-\337")
|
|
2498 (letter "a-zA-Z_$\300-\326\330-\366\370-\377")
|
|
2499 (digit "0-9"))
|
|
2500 (concat "\\<\\([" capital-letter "][" letter digit "]*\\)\\>"))
|
428
|
2501 "Regexp which should match a class or an interface name.
|
|
2502 The name is assumed to begin with a capital letter.")
|
|
2503
|
|
2504 (let ((java-modifier-regexp
|
|
2505 (concat "\\<\\(abstract\\|const\\|final\\|native\\|"
|
|
2506 "private\\|protected\\|public\\|"
|
|
2507 "static\\|synchronized\\|transient\\|volatile\\)\\>")))
|
|
2508
|
|
2509 ;; Basic font-lock support:
|
|
2510 (setq java-font-lock-keywords-1
|
|
2511 (list
|
|
2512 ;; Keywords:
|
|
2513 (list
|
|
2514 (concat
|
|
2515 "\\<\\("
|
|
2516 "break\\|byvalue\\|"
|
|
2517 "case\\|cast\\|catch\\|class\\|continue\\|"
|
|
2518 "do\\|else\\|extends\\|"
|
|
2519 "finally\\|for\\|future\\|"
|
|
2520 "generic\\|goto\\|"
|
|
2521 "if\\|implements\\|import\\|"
|
|
2522 "instanceof\\|interface\\|"
|
|
2523 "new\\|package\\|return\\|switch\\|"
|
|
2524 "throws?\\|try\\|while\\)\\>")
|
|
2525 1 'font-lock-keyword-face)
|
|
2526
|
|
2527 ;; Modifiers:
|
|
2528 (list java-modifier-regexp 1 font-lock-type-face)
|
|
2529
|
|
2530 ;; Special constants:
|
|
2531 '("\\<\\(this\\|super\\)\\>" (1 font-lock-reference-face))
|
|
2532 '("\\<\\(false\\|null\\|true\\)\\>" (1 font-lock-keyword-face))
|
|
2533
|
|
2534 ;; Class names:
|
442
|
2535 (list (concat "\\<\\(class\\|interface\\)\\>\\s *"
|
|
2536 java-font-lock-identifier-regexp)
|
|
2537 2 'font-lock-function-name-face)
|
428
|
2538
|
|
2539 ;; Package declarations:
|
|
2540 (list (concat "\\<\\(package\\|import\\)\\>\\s *"
|
|
2541 java-font-lock-identifier-regexp)
|
|
2542 '(2 font-lock-reference-face)
|
|
2543 (list (concat
|
|
2544 "\\=\\.\\(" java-font-lock-identifier-regexp "\\)")
|
|
2545 nil nil '(1 (if (equal (char-after (match-end 0)) ?.)
|
|
2546 'font-lock-reference-face
|
|
2547 'font-lock-type-face))))
|
|
2548
|
|
2549 ;; Constructors:
|
|
2550 (list (concat
|
|
2551 "^\\s *\\(" java-modifier-regexp "\\s +\\)*"
|
|
2552 java-font-lock-class-name-regexp "\\s *\(")
|
|
2553 (list 3
|
|
2554 '(condition-case nil
|
|
2555 (save-excursion
|
|
2556 (goto-char (scan-sexps (- (match-end 0) 1) 1))
|
|
2557 (parse-partial-sexp (point) (point-max) nil t)
|
|
2558 (and (looking-at "\\($\\|\\<throws\\>\\|{\\)")
|
|
2559 'font-lock-function-name-face))
|
|
2560 (error 'font-lock-function-name-face))))
|
|
2561
|
|
2562 ;; Methods:
|
|
2563 (list (concat "\\(" java-font-lock-type-regexp "\\|"
|
|
2564 java-font-lock-class-name-regexp "\\)"
|
|
2565 "\\s *\\(\\[\\s *\\]\\s *\\)*"
|
|
2566 java-font-lock-identifier-regexp "\\s *\(")
|
|
2567 5
|
|
2568 'font-lock-function-name-face)
|
|
2569
|
|
2570 ;; Labels:
|
|
2571 (list ":"
|
|
2572 (list
|
|
2573 (concat "^\\s *" java-font-lock-identifier-regexp "\\s *:")
|
|
2574 '(beginning-of-line) '(end-of-line)
|
|
2575 '(1 font-lock-reference-face)))
|
|
2576
|
|
2577 ;; `break' and continue' destination labels:
|
|
2578 (list (concat "\\<\\(break\\|continue\\)\\>\\s *"
|
|
2579 java-font-lock-identifier-regexp)
|
|
2580 2 'font-lock-reference-face)
|
|
2581
|
|
2582 ;; Case statements:
|
|
2583 ;; In Java, any constant expression is allowed.
|
|
2584 '("\\<case\\>\\s *\\(.*\\):" 1 font-lock-reference-face)))
|
|
2585
|
|
2586 ;; Types and declared variable names:
|
|
2587 (setq java-font-lock-keywords-2
|
|
2588 (append
|
|
2589
|
|
2590 java-font-lock-keywords-1
|
|
2591 (list
|
|
2592 ;; Keywords followed by a type:
|
|
2593 (list (concat "\\<\\(extends\\|instanceof\\|new\\)\\>\\s *"
|
|
2594 java-font-lock-identifier-regexp)
|
|
2595 '(2 (if (equal (char-after (match-end 0)) ?.)
|
|
2596 'font-lock-reference-face 'font-lock-type-face))
|
|
2597 (list (concat "\\=\\." java-font-lock-identifier-regexp)
|
|
2598 '(goto-char (match-end 0)) nil
|
|
2599 '(1 (if (equal (char-after (match-end 0)) ?.)
|
|
2600 'font-lock-reference-face 'font-lock-type-face))))
|
|
2601
|
|
2602 ;; Keywords followed by a type list:
|
|
2603 (list (concat "\\<\\(implements\\|throws\\)\\>\\ s*"
|
|
2604 java-font-lock-identifier-regexp)
|
|
2605 '(2 (if (equal (char-after (match-end 0)) ?.)
|
|
2606 font-lock-reference-face font-lock-type-face))
|
|
2607 (list (concat "\\=\\(\\.\\|\\s *\\(,\\)\\s *\\)"
|
|
2608 java-font-lock-identifier-regexp)
|
|
2609 '(goto-char (match-end 0)) nil
|
|
2610 '(3 (if (equal (char-after (match-end 0)) ?.)
|
|
2611 font-lock-reference-face font-lock-type-face))))
|
|
2612
|
|
2613 ;; primitive types, can't be confused with anything else.
|
|
2614 (list java-font-lock-type-regexp
|
|
2615 '(1 font-lock-type-face)
|
|
2616 '(font-lock-match-java-declarations
|
|
2617 (goto-char (match-end 0))
|
|
2618 (goto-char (match-end 0))
|
|
2619 (0 font-lock-variable-name-face)))
|
|
2620
|
|
2621 ;; Declarations, class types and capitalized variables:
|
|
2622 ;;
|
|
2623 ;; Declarations are easy to recognize. Capitalized words
|
|
2624 ;; followed by a closing parenthesis are treated as casts if they
|
|
2625 ;; also are followed by an expression. Expressions beginning with
|
|
2626 ;; a unary numerical operator, e.g. +, can't be cast to an object
|
|
2627 ;; type.
|
|
2628 ;;
|
|
2629 ;; The path of a fully qualified type, e.g. java.lang.Foo, is
|
|
2630 ;; fontified in the reference face.
|
|
2631 ;;
|
|
2632 ;; An access to a static field, e.g. System.out.println, is
|
|
2633 ;; not fontified since it can't be distinguished from the
|
|
2634 ;; usage of a capitalized variable, e.g. Foo.out.println.
|
|
2635
|
|
2636 (list (concat java-font-lock-class-name-regexp
|
|
2637 "\\s *\\(\\[\\s *\\]\\s *\\)*"
|
|
2638 "\\(\\<\\|$\\|)\\s *\\([\(\"]\\|\\<\\)\\)")
|
|
2639 '(1 (save-match-data
|
|
2640 (save-excursion
|
|
2641 (goto-char
|
|
2642 (match-beginning 3))
|
|
2643 (if (not (looking-at "\\<instanceof\\>"))
|
|
2644 'font-lock-type-face))))
|
|
2645 (list (concat "\\=" java-font-lock-identifier-regexp "\\.")
|
|
2646 '(progn
|
|
2647 (goto-char (match-beginning 0))
|
|
2648 (while (or (= (preceding-char) ?.)
|
|
2649 (= (char-syntax (preceding-char)) ?w))
|
|
2650 (backward-char)))
|
|
2651 '(goto-char (match-end 0))
|
|
2652 '(1 font-lock-reference-face)
|
|
2653 '(0 nil)) ; Workaround for bug in XEmacs.
|
|
2654 '(font-lock-match-java-declarations
|
|
2655 (goto-char (match-end 1))
|
|
2656 (goto-char (match-end 0))
|
|
2657 (1 font-lock-variable-name-face))))))
|
|
2658
|
|
2659 ;; Modifier keywords and Java doc tags
|
|
2660 (setq java-font-lock-keywords-3
|
|
2661 (append
|
|
2662
|
|
2663 '(
|
|
2664 ;; Feature scoping:
|
|
2665 ;; These must come first or the Modifiers from keywords-1 will
|
|
2666 ;; catch them. We don't want to use override fontification here
|
|
2667 ;; because then these terms will be fontified within comments.
|
|
2668 ("\\<private\\>" 0 font-lock-string-face)
|
|
2669 ("\\<protected\\>" 0 font-lock-preprocessor-face)
|
|
2670 ("\\<public\\>" 0 font-lock-reference-face))
|
|
2671 java-font-lock-keywords-2
|
|
2672
|
|
2673 (list
|
|
2674
|
442
|
2675 ;; Javadoc tags
|
|
2676 '("@\\(author\\|deprecated\\|exception\\|throws\\|param\\|return\\|see\\|since\\|version\\|serial\\|serialData\\|serialField\\)\\s "
|
428
|
2677 0 font-lock-keyword-face t)
|
|
2678
|
|
2679 ;; Doc tag - Parameter identifiers
|
|
2680 (list (concat "@param\\s +" java-font-lock-identifier-regexp)
|
|
2681 1 'font-lock-variable-name-face t)
|
|
2682
|
|
2683 ;; Doc tag - Exception types
|
442
|
2684 (list (concat "@\\(exception\\|throws\\)\\s +"
|
428
|
2685 java-font-lock-identifier-regexp)
|
442
|
2686 '(2 (if (equal (char-after (match-end 0)) ?.)
|
428
|
2687 font-lock-reference-face font-lock-type-face) t)
|
|
2688 (list (concat "\\=\\." java-font-lock-identifier-regexp)
|
|
2689 '(goto-char (match-end 0)) nil
|
|
2690 '(1 (if (equal (char-after (match-end 0)) ?.)
|
|
2691 'font-lock-reference-face 'font-lock-type-face) t)))
|
|
2692
|
|
2693 ;; Doc tag - Cross-references, usually to methods
|
|
2694 '("@see\\s +\\(\\S *[^][ \t\n\r\f(){},.;:]\\)"
|
|
2695 1 font-lock-function-name-face t)
|
|
2696
|
442
|
2697 ;; Doc tag - docRoot (1.3)
|
|
2698 '("\\({ *@docRoot *}\\)"
|
|
2699 0 font-lock-keyword-face t)
|
|
2700 ;; Doc tag - beaninfo, unofficial but widely used, even by Sun
|
|
2701 '("\\(@beaninfo\\)"
|
428
|
2702 0 font-lock-keyword-face t)
|
|
2703 ;; Doc tag - Links
|
442
|
2704 '("{ *@link\\s +\\([^}]+\\)}"
|
|
2705 0 font-lock-keyword-face t)
|
|
2706 ;; Doc tag - Links
|
|
2707 '("{ *@link\\s +\\(\\(\\S +\\)\\|\\(\\S +\\s +\\S +\\)\\) *}"
|
428
|
2708 1 font-lock-function-name-face t)
|
|
2709
|
|
2710 )))
|
|
2711 )
|
|
2712
|
|
2713 (defvar java-font-lock-keywords java-font-lock-keywords-1
|
|
2714 "Additional expressions to highlight in Java mode.")
|
|
2715
|
|
2716 ;; Match and move over any declaration/definition item after
|
|
2717 ;; point. Does not match items which look like a type declaration
|
|
2718 ;; (primitive types and class names, i.e. capitalized words.)
|
|
2719 ;; Should the variable name be followed by a comma, we reposition
|
|
2720 ;; the cursor to fontify more identifiers.
|
|
2721 (defun font-lock-match-java-declarations (limit)
|
|
2722 "Match and skip over variable definitions."
|
|
2723 (if (looking-at "\\s *\\(\\[\\s *\\]\\s *\\)*")
|
|
2724 (goto-char (match-end 0)))
|
|
2725 (and
|
|
2726 (looking-at java-font-lock-identifier-regexp)
|
|
2727 (save-match-data
|
|
2728 (not (string-match java-font-lock-type-regexp
|
|
2729 (buffer-substring (match-beginning 1)
|
|
2730 (match-end 1)))))
|
|
2731 (save-match-data
|
|
2732 (save-excursion
|
|
2733 (goto-char (match-beginning 1))
|
|
2734 (not (looking-at
|
|
2735 (concat java-font-lock-class-name-regexp
|
|
2736 "\\s *\\(\\[\\s *\\]\\s *\\)*\\<")))))
|
|
2737 (save-match-data
|
|
2738 (condition-case nil
|
|
2739 (save-restriction
|
|
2740 (narrow-to-region (point-min) limit)
|
|
2741 (goto-char (match-end 0))
|
|
2742 ;; Note: Both `scan-sexps' and the second goto-char can
|
|
2743 ;; generate an error which is caught by the
|
|
2744 ;; `condition-case' expression.
|
|
2745 (while (not (looking-at "\\s *\\(\\(,\\)\\|;\\|$\\)"))
|
|
2746 (goto-char (or (scan-sexps (point) 1) (point-max))))
|
|
2747 (goto-char (match-end 2))) ; non-nil
|
|
2748 (error t)))))
|
|
2749
|
|
2750
|
|
2751 (defvar tex-font-lock-keywords
|
|
2752 ; ;; Regexps updated with help from Ulrik Dickow <dickow@nbi.dk>.
|
|
2753 ; '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
|
|
2754 ; 2 font-lock-function-name-face)
|
|
2755 ; ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
|
|
2756 ; 2 font-lock-reference-face)
|
|
2757 ; ;; It seems a bit dubious to use `bold' and `italic' faces since we might
|
|
2758 ; ;; not be able to display those fonts.
|
|
2759 ; ("{\\\\bf\\([^}]+\\)}" 1 'bold keep)
|
|
2760 ; ("{\\\\\\(em\\|it\\|sl\\)\\([^}]+\\)}" 2 'italic keep)
|
|
2761 ; ("\\\\\\([a-zA-Z@]+\\|.\\)" . font-lock-keyword-face)
|
|
2762 ; ("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face keep))
|
|
2763 ;; Rewritten and extended for LaTeX2e by Ulrik Dickow <dickow@nbi.dk>.
|
|
2764 '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
|
|
2765 2 font-lock-function-name-face)
|
|
2766 ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
|
|
2767 2 font-lock-reference-face)
|
|
2768 ("^[ \t]*\\\\def\\\\\\(\\(\\w\\|@\\)+\\)" 1 font-lock-function-name-face)
|
|
2769 "\\\\\\([a-zA-Z@]+\\|.\\)"
|
|
2770 ;; It seems a bit dubious to use `bold' and `italic' faces since we might
|
|
2771 ;; not be able to display those fonts.
|
|
2772 ;; LaTeX2e: \emph{This is emphasized}.
|
|
2773 ("\\\\emph{\\([^}]+\\)}" 1 'italic keep)
|
|
2774 ;; LaTeX2e: \textbf{This is bold}, \textit{...}, \textsl{...}
|
|
2775 ("\\\\text\\(\\(bf\\)\\|it\\|sl\\){\\([^}]+\\)}"
|
|
2776 3 (if (match-beginning 2) 'bold 'italic) keep)
|
|
2777 ;; Old-style bf/em/it/sl. Stop at `\\' and un-escaped `&', for good tables.
|
|
2778 ("\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)"
|
|
2779 3 (if (match-beginning 2) 'bold 'italic) keep))
|
|
2780 "Default expressions to highlight in TeX modes.")
|
|
2781
|
444
|
2782 (defconst ksh-font-lock-keywords
|
428
|
2783 (list
|
|
2784 '("\\(^\\|[^\$\\\]\\)#.*" . font-lock-comment-face)
|
|
2785 '("\\<\\(if\\|then\\|else\\|elif\\|fi\\|case\\|esac\\|for\\|do\\|done\\|foreach\\|in\\|end\\|select\\|while\\|repeat\\|time\\|function\\|until\\|exec\\|command\\|coproc\\|noglob\\|nohup\\|nocorrect\\|source\\|autoload\\|alias\\|unalias\\|export\\|set\\|echo\\|eval\\|cd\\|log\\|compctl\\)\\>" . font-lock-keyword-face)
|
|
2786 '("\\<\\[\\[.*\\]\\]\\>" . font-lock-type-face)
|
|
2787 '("\$\(.*\)" . font-lock-type-face)
|
444
|
2788 )
|
428
|
2789 "Additional expressions to highlight in ksh-mode.")
|
|
2790
|
444
|
2791 (defconst sh-font-lock-keywords
|
428
|
2792 (list
|
|
2793 '("\\(^\\|[^\$\\\]\\)#.*" . font-lock-comment-face)
|
|
2794 '("\\<\\(if\\|then\\|else\\|elif\\|fi\\|case\\|esac\\|for\\|do\\|done\\|in\\|while\\|exec\\|export\\|set\\|echo\\|eval\\|cd\\)\\>" . font-lock-keyword-face)
|
|
2795 '("\\[.*\\]" . font-lock-type-face)
|
|
2796 '("`.*`" . font-lock-type-face)
|
444
|
2797 )
|
428
|
2798 "Additional expressions to highlight in sh-mode.")
|
|
2799
|
|
2800
|
|
2801 ;; Install ourselves:
|
|
2802
|
|
2803 (add-hook 'find-file-hooks 'font-lock-set-defaults t)
|
|
2804
|
|
2805 ;;;###autoload
|
692
|
2806 (add-minor-mode 'font-lock-mode 'font-lock-mode-line-string)
|
428
|
2807
|
|
2808 ;; Provide ourselves:
|
|
2809
|
|
2810 (provide 'font-lock)
|
|
2811
|
|
2812 ;;; font-lock.el ends here
|