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)
|
|
285 (const :tag "maximum" t)
|
|
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
|
|
637 ;; them when we eval the face expression, but that failes because
|
|
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.")
|
428
|
650 (defvar font-lock-string-face 'font-lock-string-face
|
442
|
651 "This variable should not be set.
|
|
652 It is present only for horrid FSF compatibility reasons.
|
|
653 The corresponding face should be set using `edit-faces' or the
|
|
654 `set-face-*' functions.")
|
428
|
655 (defvar font-lock-keyword-face 'font-lock-keyword-face
|
442
|
656 "This variable should not be set.
|
|
657 It is present only for horrid FSF compatibility reasons.
|
|
658 The corresponding face should be set using `edit-faces' or the
|
|
659 `set-face-*' functions.")
|
428
|
660 (defvar font-lock-function-name-face 'font-lock-function-name-face
|
442
|
661 "This variable should not be set.
|
|
662 It is present only for horrid FSF compatibility reasons.
|
|
663 The corresponding face should be set using `edit-faces' or the
|
|
664 `set-face-*' functions.")
|
428
|
665 (defvar font-lock-variable-name-face 'font-lock-variable-name-face
|
442
|
666 "This variable should not be set.
|
|
667 It is present only for horrid FSF compatibility reasons.
|
|
668 The corresponding face should be set using `edit-faces' or the
|
|
669 `set-face-*' functions.")
|
428
|
670 (defvar font-lock-type-face 'font-lock-type-face
|
442
|
671 "This variable should not be set.
|
|
672 It is present only for horrid FSF compatibility reasons.
|
|
673 The corresponding face should be set using `edit-faces' or the
|
|
674 `set-face-*' functions.")
|
428
|
675 (defvar font-lock-reference-face 'font-lock-reference-face
|
442
|
676 "This variable should not be set.
|
|
677 It is present only for horrid FSF compatibility reasons.
|
|
678 The corresponding face should be set using `edit-faces' or the
|
|
679 `set-face-*' functions.")
|
428
|
680 (defvar font-lock-preprocessor-face 'font-lock-preprocessor-face
|
442
|
681 "This variable should not be set.
|
|
682 It is present only for horrid FSF compatibility reasons.
|
|
683 The corresponding face should be set using `edit-faces' or the
|
|
684 `set-face-*' functions.")
|
428
|
685
|
|
686 (defconst font-lock-face-list
|
|
687 '(font-lock-comment-face
|
|
688 font-lock-string-face
|
|
689 font-lock-doc-string-face
|
|
690 font-lock-keyword-face
|
|
691 font-lock-function-name-face
|
|
692 font-lock-variable-name-face
|
|
693 font-lock-type-face
|
|
694 font-lock-reference-face
|
|
695 font-lock-preprocessor-face
|
|
696 font-lock-warning-face))
|
|
697
|
|
698 (defface font-lock-comment-face
|
|
699 '((((class color) (background dark)) (:foreground "gray80"))
|
442
|
700 ;; blue4 is hardly different from black on windows.
|
|
701 (((class color) (background light) (type mswindows)) (:foreground "blue"))
|
428
|
702 (((class color) (background light)) (:foreground "blue4"))
|
|
703 (((class grayscale) (background light))
|
|
704 (:foreground "DimGray" :bold t :italic t))
|
|
705 (((class grayscale) (background dark))
|
|
706 (:foreground "LightGray" :bold t :italic t))
|
|
707 (t (:bold t)))
|
|
708 "Font Lock mode face used to highlight comments."
|
|
709 :group 'font-lock-faces)
|
|
710
|
|
711 (defface font-lock-string-face
|
|
712 '((((class color) (background dark)) (:foreground "tan"))
|
|
713 (((class color) (background light)) (:foreground "green4"))
|
|
714 (((class grayscale) (background light)) (:foreground "DimGray" :italic t))
|
|
715 (((class grayscale) (background dark)) (:foreground "LightGray" :italic t))
|
|
716 (t (:bold t)))
|
|
717 "Font Lock mode face used to highlight strings."
|
|
718 :group 'font-lock-faces)
|
|
719
|
|
720 (defface font-lock-doc-string-face
|
|
721 '((((class color) (background dark)) (:foreground "light coral"))
|
|
722 (((class color) (background light)) (:foreground "green4"))
|
|
723 (t (:bold t)))
|
432
|
724 "Font Lock mode face used to highlight documentation strings.
|
|
725 This is currently supported only in Lisp-like modes, which are those
|
|
726 with \"lisp\" or \"scheme\" in their name. You can explicitly make
|
|
727 a mode Lisp-like by putting a non-nil `font-lock-lisp-like' property
|
|
728 on the major mode's symbol."
|
428
|
729 :group 'font-lock-faces)
|
|
730
|
|
731 (defface font-lock-keyword-face
|
|
732 '((((class color) (background dark)) (:foreground "cyan"))
|
442
|
733 ;; red4 is hardly different from black on windows.
|
|
734 (((class color) (background light) (type mswindows)) (:foreground "red"))
|
428
|
735 (((class color) (background light)) (:foreground "red4"))
|
|
736 (((class grayscale) (background light)) (:foreground "LightGray" :bold t))
|
|
737 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
|
|
738 (t (:bold t)))
|
|
739 "Font Lock mode face used to highlight keywords."
|
|
740 :group 'font-lock-faces)
|
|
741
|
|
742 (defface font-lock-function-name-face
|
|
743 '((((class color) (background dark)) (:foreground "aquamarine"))
|
442
|
744 ;; brown4 is hardly different from black on windows.
|
|
745 ;; I changed it to red because IMO it's pointless and ugly to
|
|
746 ;; use a million slightly different colors for niggly syntactic
|
|
747 ;; differences. --ben
|
|
748 (((class color) (background light) (type mswindows)) (:foreground "red"))
|
428
|
749 (((class color) (background light)) (:foreground "brown4"))
|
|
750 (t (:bold t :underline t)))
|
|
751 "Font Lock mode face used to highlight function names."
|
|
752 :group 'font-lock-faces)
|
|
753
|
|
754 (defface font-lock-variable-name-face
|
|
755 '((((class color) (background dark)) (:foreground "cyan3"))
|
|
756 (((class color) (background light)) (:foreground "magenta4"))
|
|
757 (((class grayscale) (background light))
|
|
758 (:foreground "Gray90" :bold t :italic t))
|
|
759 (((class grayscale) (background dark))
|
|
760 (:foreground "DimGray" :bold t :italic t))
|
|
761 (t (:underline t)))
|
|
762 "Font Lock mode face used to highlight variable names."
|
|
763 :group 'font-lock-faces)
|
|
764
|
|
765 (defface font-lock-type-face
|
|
766 '((((class color) (background dark)) (:foreground "wheat"))
|
|
767 (((class color) (background light)) (:foreground "steelblue"))
|
|
768 (((class grayscale) (background light)) (:foreground "Gray90" :bold t))
|
|
769 (((class grayscale) (background dark)) (:foreground "DimGray" :bold t))
|
|
770 (t (:bold t)))
|
|
771 "Font Lock mode face used to highlight types."
|
|
772 :group 'font-lock-faces)
|
|
773
|
|
774 (defface font-lock-reference-face
|
|
775 '((((class color) (background dark)) (:foreground "cadetblue2"))
|
|
776 (((class color) (background light)) (:foreground "red3"))
|
|
777 (((class grayscale) (background light))
|
|
778 (:foreground "LightGray" :bold t :underline t))
|
|
779 (((class grayscale) (background dark))
|
|
780 (:foreground "Gray50" :bold t :underline t)))
|
|
781 "Font Lock mode face used to highlight references."
|
|
782 :group 'font-lock-faces)
|
|
783
|
|
784 ;; #### FSF has font-lock-builtin-face.
|
|
785
|
|
786 (defface font-lock-preprocessor-face
|
|
787 '((((class color) (background dark)) (:foreground "steelblue1"))
|
|
788 (((class color) (background light)) (:foreground "blue3"))
|
|
789 (t (:underline t)))
|
|
790 "Font Lock Mode face used to highlight preprocessor conditionals."
|
|
791 :group 'font-lock-faces)
|
|
792
|
|
793 ;; #### Currently unused
|
|
794 (defface font-lock-warning-face
|
|
795 '((((class color) (background light)) (:foreground "Red" :bold t))
|
|
796 (((class color) (background dark)) (:foreground "Pink" :bold t))
|
|
797 (t (:inverse-video t :bold t)))
|
|
798 "Font Lock mode face used to highlight warnings."
|
|
799 :group 'font-lock-faces)
|
|
800
|
|
801 (defun font-lock-recompute-variables ()
|
|
802 ;; Is this a Draconian thing to do?
|
|
803 (mapc #'(lambda (buffer)
|
|
804 (with-current-buffer buffer
|
|
805 (font-lock-mode 0)
|
|
806 (font-lock-set-defaults t)))
|
|
807 (buffer-list)))
|
|
808
|
|
809 ;; Backwards-compatible crud.
|
|
810
|
|
811 (defun font-lock-reset-all-faces ()
|
|
812 (dolist (face font-lock-face-list)
|
|
813 (face-spec-set face (get face 'face-defface-spec))))
|
|
814
|
|
815 (defun font-lock-use-default-fonts ()
|
|
816 "Reset the font-lock faces to a default set of fonts."
|
|
817 (interactive)
|
|
818 ;; #### !!!!
|
|
819 (font-lock-reset-all-faces))
|
|
820
|
|
821 (defun font-lock-use-default-colors ()
|
|
822 "Reset the font-lock faces to a default set of colors."
|
|
823 (interactive)
|
|
824 ;; #### !!!!
|
|
825 (font-lock-reset-all-faces))
|
|
826
|
|
827 (defun font-lock-use-default-minimal-decoration ()
|
|
828 "Reset the font-lock patterns to a fast, minimal set of decorations."
|
|
829 (and font-lock-maximum-decoration
|
|
830 (setq font-lock-maximum-decoration nil)
|
|
831 (font-lock-recompute-variables)))
|
|
832
|
|
833 (defun font-lock-use-default-maximal-decoration ()
|
|
834 "Reset the font-lock patterns to a larger set of decorations."
|
|
835 (and (not (eq t font-lock-maximum-decoration))
|
|
836 (setq font-lock-maximum-decoration t)
|
|
837 (font-lock-recompute-variables)))
|
|
838
|
|
839
|
|
840 ;;;;;;;;;;;;;;;;;;;;;; actual code ;;;;;;;;;;;;;;;;;;;;;;
|
|
841
|
|
842 ;;; To fontify the whole buffer by language syntax, we go through it a
|
|
843 ;;; character at a time, creating extents on the boundary of each syntactic
|
|
844 ;;; unit (that is, one extent for each block comment, one for each line
|
|
845 ;;; comment, one for each string, etc.) This is done with the C function
|
|
846 ;;; syntactically-sectionize. It's in C for speed (the speed of lisp function
|
|
847 ;;; calls was a real bottleneck for this task since it involves examining each
|
|
848 ;;; character in turn.)
|
|
849 ;;;
|
|
850 ;;; Then we make a second pass, to fontify the buffer based on other patterns
|
|
851 ;;; specified by regexp. When we find a match for a region of text, we need
|
|
852 ;;; to change the fonts on those characters. This is done with the
|
|
853 ;;; put-text-property function, which knows how to efficiently share extents.
|
|
854 ;;; Conceptually, we are attaching some particular face to each of the
|
|
855 ;;; characters in a range, but the implementation of this involves creating
|
|
856 ;;; extents, or resizing existing ones.
|
|
857 ;;;
|
|
858 ;;; Each time a modification happens to a line, we re-fontify the entire line.
|
|
859 ;;; We do this by first removing the extents (text properties) on the line,
|
|
860 ;;; and then doing the syntactic and keyword passes again on that line. (More
|
|
861 ;;; generally, each modified region is extended to include the preceding and
|
|
862 ;;; following BOL or EOL.)
|
|
863 ;;;
|
|
864 ;;; This means that, as the user types, we repeatedly go back to the beginning
|
|
865 ;;; of the line, doing more work the longer the line gets. This doesn't cost
|
|
866 ;;; much in practice, and if we don't, then we incorrectly fontify things when,
|
|
867 ;;; for example, inserting spaces into `intfoo () {}'.
|
|
868 ;;;
|
|
869
|
|
870
|
|
871 ;; The user level functions
|
|
872
|
|
873 ;;;###autoload
|
|
874 (defun font-lock-mode (&optional arg)
|
|
875 "Toggle Font Lock Mode.
|
|
876 With arg, turn font-lock mode on if and only if arg is positive.
|
|
877
|
|
878 When Font Lock mode is enabled, text is fontified as you type it:
|
|
879
|
|
880 - Comments are displayed in `font-lock-comment-face';
|
|
881 - Strings are displayed in `font-lock-string-face';
|
|
882 - Documentation strings (in Lisp-like languages) are displayed in
|
|
883 `font-lock-doc-string-face';
|
|
884 - Language keywords (\"reserved words\") are displayed in
|
|
885 `font-lock-keyword-face';
|
|
886 - Function names in their defining form are displayed in
|
|
887 `font-lock-function-name-face';
|
|
888 - Variable names in their defining form are displayed in
|
|
889 `font-lock-variable-name-face';
|
|
890 - Type names are displayed in `font-lock-type-face';
|
|
891 - References appearing in help files and the like are displayed
|
|
892 in `font-lock-reference-face';
|
|
893 - Preprocessor declarations are displayed in
|
|
894 `font-lock-preprocessor-face';
|
|
895
|
|
896 and
|
|
897
|
|
898 - Certain other expressions are displayed in other faces according
|
|
899 to the value of the variable `font-lock-keywords'.
|
|
900
|
|
901 Where modes support different levels of fontification, you can use the variable
|
|
902 `font-lock-maximum-decoration' to specify which level you generally prefer.
|
|
903 When you turn Font Lock mode on/off the buffer is fontified/defontified, though
|
|
904 fontification occurs only if the buffer is less than `font-lock-maximum-size'.
|
|
905 To fontify a buffer without turning on Font Lock mode, and regardless of buffer
|
|
906 size, you can use \\[font-lock-fontify-buffer].
|
|
907
|
|
908 See the variable `font-lock-keywords' for customization."
|
|
909 (interactive "P")
|
|
910 (let ((on-p (if arg (> (prefix-numeric-value arg) 0) (not font-lock-mode)))
|
|
911 (maximum-size (if (not (consp font-lock-maximum-size))
|
|
912 font-lock-maximum-size
|
|
913 (cdr (or (assq major-mode font-lock-maximum-size)
|
|
914 (assq t font-lock-maximum-size))))))
|
531
|
915 ;; Font-lock mode will refuse to turn itself on if in batch mode
|
|
916 ;; to avoid potential (probably not actual, though) slowdown. We
|
|
917 ;; used to try to "be nice" by avoiding doing this in temporary
|
|
918 ;; buffers. But with the deferral code we don't need this, and it
|
|
919 ;; definitely screws some things up.
|
|
920 (if (noninteractive)
|
428
|
921 (setq on-p nil))
|
|
922 (cond (on-p
|
|
923 (make-local-hook 'after-change-functions)
|
|
924 (add-hook 'after-change-functions
|
|
925 'font-lock-after-change-function nil t)
|
|
926 (add-hook 'pre-idle-hook 'font-lock-pre-idle-hook))
|
|
927 (t
|
|
928 (remove-hook 'after-change-functions
|
|
929 'font-lock-after-change-function t)
|
|
930 (setq font-lock-defaults-computed nil
|
|
931 font-lock-keywords nil)
|
|
932 ;; We have no business doing this here, since
|
|
933 ;; pre-idle-hook is global. Other buffers may
|
|
934 ;; still be in font-lock mode. -dkindred@cs.cmu.edu
|
|
935 ;; (remove-hook 'pre-idle-hook 'font-lock-pre-idle-hook)
|
|
936 ))
|
|
937 (set (make-local-variable 'font-lock-mode) on-p)
|
|
938 (cond (on-p
|
|
939 (font-lock-set-defaults-1)
|
|
940 (run-hooks 'font-lock-mode-hook)
|
|
941 (cond (font-lock-fontified
|
|
942 nil)
|
|
943 ((or (null maximum-size) (<= (buffer-size) maximum-size))
|
|
944 (font-lock-fontify-buffer))
|
|
945 (font-lock-verbose
|
442
|
946 (progress-feedback-with-label
|
|
947 'font-lock
|
|
948 "Fontifying %s... buffer too big." 'abort
|
|
949 (buffer-name)))))
|
428
|
950 (font-lock-fontified
|
|
951 (setq font-lock-fontified nil)
|
|
952 (font-lock-unfontify-region (point-min) (point-max))
|
|
953 (font-lock-thing-lock-cleanup))
|
|
954 (t
|
|
955 (font-lock-thing-lock-cleanup)))
|
|
956 (redraw-modeline)))
|
|
957
|
|
958 ;; For init-file hooks
|
|
959 ;;;###autoload
|
|
960 (defun turn-on-font-lock ()
|
|
961 "Unconditionally turn on Font Lock mode."
|
444
|
962 (interactive)
|
428
|
963 (font-lock-mode 1))
|
|
964
|
|
965 ;;;###autoload
|
|
966 (defun turn-off-font-lock ()
|
|
967 "Unconditionally turn off Font Lock mode."
|
444
|
968 (interactive)
|
428
|
969 (font-lock-mode 0))
|
|
970
|
|
971 ;;; FSF has here:
|
|
972
|
|
973 ;; support for add-keywords, global-font-lock-mode and
|
|
974 ;; font-lock-support-mode (unified support for various *-lock modes).
|
|
975
|
|
976
|
|
977 ;; Fontification functions.
|
|
978
|
|
979 ;; We first define some defsubsts to encapsulate the way we add
|
|
980 ;; faces to a region of text. I am planning on modifying the
|
|
981 ;; text-property mechanism so that multiple independent classes
|
|
982 ;; of text properties can exist. That way, for example, ediff's
|
|
983 ;; face text properties don't interfere with font lock's face
|
|
984 ;; text properties. Due to the XEmacs implementation of text
|
|
985 ;; properties in terms of extents, doing this is fairly trivial:
|
|
986 ;; instead of using the `text-prop' property, you just use a
|
|
987 ;; specified property.
|
|
988
|
|
989 (defsubst font-lock-set-face (start end face)
|
|
990 ;; Set the face on the characters in the range.
|
|
991 (put-nonduplicable-text-property start end 'face face)
|
|
992 (put-nonduplicable-text-property start end 'font-lock t))
|
|
993
|
|
994 (defsubst font-lock-remove-face (start end)
|
|
995 ;; Remove any syntax highlighting on the characters in the range.
|
|
996 (put-nonduplicable-text-property start end 'face nil)
|
460
|
997 (put-nonduplicable-text-property start end 'font-lock nil)
|
|
998 (if lookup-syntax-properties
|
|
999 (put-nonduplicable-text-property start end 'syntax-table nil)))
|
|
1000
|
|
1001 (defsubst font-lock-set-syntax (start end syntax)
|
|
1002 ;; Set the face on the characters in the range.
|
|
1003 (put-nonduplicable-text-property start end 'syntax-table syntax)
|
|
1004 (put-nonduplicable-text-property start end 'font-lock t))
|
428
|
1005
|
|
1006 (defsubst font-lock-any-faces-p (start end)
|
|
1007 ;; Return non-nil if we've put any syntax highlighting on
|
|
1008 ;; the characters in the range.
|
|
1009 ;;
|
|
1010 ;; used to look for 'text-prop property, but this has problems if
|
|
1011 ;; you put any other text properties in the vicinity. Simon
|
|
1012 ;; Marshall suggested looking for the 'face property (this is what
|
|
1013 ;; FSF Emacs does) but that's equally bogus. Only reliable way is
|
|
1014 ;; for font-lock to specially mark its extents.
|
|
1015 ;;
|
|
1016 ;; FSF's (equivalent) definition of this defsubst would be
|
|
1017 ;; (text-property-not-all start end 'font-lock nil)
|
|
1018 ;;
|
|
1019 ;; Perhaps our `map-extents' is faster than our definition
|
|
1020 ;; of `text-property-not-all'. #### If so, `text-property-not-all'
|
|
1021 ;; should be fixed ...
|
|
1022 ;;
|
|
1023 (map-extents 'extent-property (current-buffer) start (1- end) 'font-lock))
|
|
1024
|
|
1025
|
|
1026 ;; Fontification functions.
|
|
1027
|
|
1028 ;; Rather than the function, e.g., `font-lock-fontify-region' containing the
|
|
1029 ;; code to fontify a region, the function runs the function whose name is the
|
|
1030 ;; value of the variable, e.g., `font-lock-fontify-region-function'. Normally,
|
|
1031 ;; the value of this variable is, e.g., `font-lock-default-fontify-region'
|
|
1032 ;; which does contain the code to fontify a region. However, the value of the
|
|
1033 ;; variable could be anything and thus, e.g., `font-lock-fontify-region' could
|
|
1034 ;; do anything. The indirection of the fontification functions gives major
|
|
1035 ;; modes the capability of modifying the way font-lock.el fontifies. Major
|
|
1036 ;; modes can modify the values of, e.g., `font-lock-fontify-region-function',
|
|
1037 ;; via the variable `font-lock-defaults'.
|
|
1038 ;;
|
|
1039 ;; For example, Rmail mode sets the variable `font-lock-defaults' so that
|
|
1040 ;; font-lock.el uses its own function for buffer fontification. This function
|
|
1041 ;; makes fontification be on a message-by-message basis and so visiting an
|
|
1042 ;; RMAIL file is much faster. A clever implementation of the function might
|
|
1043 ;; fontify the headers differently than the message body. (It should, and
|
|
1044 ;; correspondingly for Mail mode, but I can't be bothered to do the work. Can
|
|
1045 ;; you?) This hints at a more interesting use...
|
|
1046 ;;
|
|
1047 ;; Languages that contain text normally contained in different major modes
|
|
1048 ;; could define their own fontification functions that treat text differently
|
|
1049 ;; depending on its context. For example, Perl mode could arrange that here
|
|
1050 ;; docs are fontified differently than Perl code. Or Yacc mode could fontify
|
|
1051 ;; rules one way and C code another. Neat!
|
|
1052 ;;
|
|
1053 ;; A further reason to use the fontification indirection feature is when the
|
|
1054 ;; default syntactual fontification, or the default fontification in general,
|
|
1055 ;; is not flexible enough for a particular major mode. For example, perhaps
|
|
1056 ;; comments are just too hairy for `font-lock-fontify-syntactically-region' to
|
|
1057 ;; cope with. You need to write your own version of that function, e.g.,
|
|
1058 ;; `hairy-fontify-syntactically-region', and make your own version of
|
|
1059 ;; `hairy-fontify-region' call that function before calling
|
|
1060 ;; `font-lock-fontify-keywords-region' for the normal regexp fontification
|
|
1061 ;; pass. And Hairy mode would set `font-lock-defaults' so that font-lock.el
|
|
1062 ;; would call your region fontification function instead of its own. For
|
|
1063 ;; example, TeX modes could fontify {\foo ...} and \bar{...} etc. multi-line
|
|
1064 ;; directives correctly and cleanly. (It is the same problem as fontifying
|
|
1065 ;; multi-line strings and comments; regexps are not appropriate for the job.)
|
|
1066
|
|
1067 ;;;###autoload
|
|
1068 (defun font-lock-fontify-buffer ()
|
|
1069 "Fontify the current buffer the way `font-lock-mode' would.
|
|
1070 See `font-lock-mode' for details.
|
|
1071
|
|
1072 This can take a while for large buffers."
|
|
1073 (interactive)
|
|
1074 (let ((font-lock-verbose (or font-lock-verbose (interactive-p))))
|
|
1075 (funcall font-lock-fontify-buffer-function)))
|
|
1076
|
|
1077 (defun font-lock-unfontify-buffer ()
|
|
1078 (funcall font-lock-unfontify-buffer-function))
|
|
1079
|
|
1080 (defun font-lock-fontify-region (beg end &optional loudly)
|
|
1081 (funcall font-lock-fontify-region-function beg end loudly))
|
|
1082
|
|
1083 (defun font-lock-unfontify-region (beg end &optional loudly)
|
|
1084 (funcall font-lock-unfontify-region-function beg end loudly))
|
|
1085
|
|
1086 (defun font-lock-default-fontify-buffer ()
|
|
1087 (interactive)
|
442
|
1088 ;; if we don't widen, then the C code will fail to
|
|
1089 ;; realize that we're inside a comment.
|
|
1090 (save-restriction
|
|
1091 (widen)
|
|
1092 (let ((was-on font-lock-mode)
|
|
1093 (font-lock-verbose (or font-lock-verbose (interactive-p)))
|
|
1094 (font-lock-message-threshold 0)
|
|
1095 (aborted nil))
|
|
1096 ;; Turn it on to run hooks and get the right font-lock-keywords.
|
|
1097 (or was-on (font-lock-mode 1))
|
|
1098 (font-lock-unfontify-region (point-min) (point-max) t)
|
|
1099 ;; (buffer-syntactic-context-flush-cache)
|
428
|
1100
|
442
|
1101 ;; If a ^G is typed during fontification, abort the fontification, but
|
|
1102 ;; return normally (do not signal.) This is to make it easy to abort
|
|
1103 ;; fontification if it's taking a long time, without also causing the
|
|
1104 ;; buffer not to pop up. If a real abort is desired, the user can ^G
|
|
1105 ;; again.
|
|
1106 ;;
|
|
1107 ;; Possibly this should happen down in font-lock-fontify-region instead
|
|
1108 ;; of here, but since that happens from the after-change-hook (meaning
|
|
1109 ;; much more frequently) I'm afraid of the bad consequences of stealing
|
|
1110 ;; the interrupt character at inopportune times.
|
|
1111 ;;
|
|
1112 (condition-case nil
|
|
1113 (save-excursion
|
|
1114 (font-lock-fontify-region (point-min) (point-max)))
|
|
1115 (t
|
|
1116 (setq aborted t)))
|
428
|
1117
|
442
|
1118 (or was-on ; turn it off if it was off.
|
|
1119 (let ((font-lock-fontified nil)) ; kludge to prevent defontification
|
|
1120 (font-lock-mode 0)))
|
|
1121 (set (make-local-variable 'font-lock-fontified) t)
|
|
1122 (when (and aborted font-lock-verbose)
|
|
1123 (progress-feedback-with-label 'font-lock "Fontifying %s... aborted."
|
|
1124 'abort (buffer-name))))
|
|
1125 (run-hooks 'font-lock-after-fontify-buffer-hook)))
|
428
|
1126
|
|
1127 (defun font-lock-default-unfontify-buffer ()
|
|
1128 (font-lock-unfontify-region (point-min) (point-max))
|
|
1129 (set (make-local-variable 'font-lock-fontified) nil))
|
|
1130
|
|
1131 ;; This used to be `font-lock-fontify-region', and before that,
|
|
1132 ;; `font-lock-fontify-region' used to be the name used for what is now
|
|
1133 ;; `font-lock-fontify-syntactically-region'.
|
|
1134 (defun font-lock-default-fontify-region (beg end &optional loudly)
|
|
1135 (let ((modified (buffer-modified-p))
|
|
1136 (buffer-undo-list t) (inhibit-read-only t)
|
|
1137 (old-syntax-table (syntax-table))
|
|
1138 buffer-file-name buffer-file-truename)
|
|
1139 (unwind-protect
|
|
1140 (progn
|
|
1141 ;; Use the fontification syntax table, if any.
|
|
1142 (if font-lock-syntax-table (set-syntax-table font-lock-syntax-table))
|
|
1143 ;; Now do the fontification.
|
460
|
1144 (font-lock-unfontify-region beg end)
|
|
1145 (when font-lock-syntactic-keywords
|
|
1146 (font-lock-fontify-syntactic-keywords-region beg end))
|
|
1147 (unless font-lock-keywords-only
|
428
|
1148 (font-lock-fontify-syntactically-region beg end loudly))
|
|
1149 (font-lock-fontify-keywords-region beg end loudly))
|
|
1150 ;; Clean up.
|
|
1151 (set-syntax-table old-syntax-table)
|
|
1152 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil)))))
|
|
1153
|
|
1154 ;; The following must be rethought, since keywords can override fontification.
|
|
1155 ; ;; Now scan for keywords, but not if we are inside a comment now.
|
|
1156 ; (or (and (not font-lock-keywords-only)
|
|
1157 ; (let ((state (parse-partial-sexp beg end nil nil
|
|
1158 ; font-lock-cache-state)))
|
|
1159 ; (or (nth 4 state) (nth 7 state))))
|
|
1160 ; (font-lock-fontify-keywords-region beg end))
|
|
1161
|
|
1162 (defun font-lock-default-unfontify-region (beg end &optional maybe-loudly)
|
|
1163 (when (and maybe-loudly font-lock-verbose
|
|
1164 (>= (- end beg) font-lock-message-threshold))
|
442
|
1165 (progress-feedback-with-label 'font-lock "Fontifying %s..." 0
|
|
1166 (buffer-name)))
|
428
|
1167 (let ((modified (buffer-modified-p))
|
|
1168 (buffer-undo-list t) (inhibit-read-only t)
|
|
1169 buffer-file-name buffer-file-truename)
|
|
1170 (font-lock-remove-face beg end)
|
|
1171 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil))))
|
|
1172
|
|
1173 ;; Following is the original FSF version (similar to our original
|
442
|
1174 ;; version, before the deferred stuff was added).
|
428
|
1175 ;;
|
|
1176 ;; I think that lazy-lock v2 tries to do something similar.
|
|
1177 ;; Those efforts should be merged.
|
|
1178
|
|
1179 ;; Called when any modification is made to buffer text.
|
|
1180 ;(defun font-lock-after-change-function (beg end old-len)
|
|
1181 ; (save-excursion
|
|
1182 ; (save-match-data
|
|
1183 ; ;; Rescan between start of line from `beg' and start of line after `end'.
|
|
1184 ; (font-lock-fontify-region
|
|
1185 ; (progn (goto-char beg) (beginning-of-line) (point))
|
|
1186 ; (progn (goto-char end) (forward-line 1) (point))))))
|
|
1187
|
442
|
1188 (defvar font-lock-always-fontify-immediately nil
|
|
1189 "Set this to non-nil to disable font-lock deferral.
|
|
1190 Otherwise, changes to existing text will not be processed until the
|
|
1191 next redisplay cycle, avoiding excessive fontification when many
|
|
1192 buffer modifications are performed or a buffer is reverted.")
|
428
|
1193
|
462
|
1194 ;; list of buffers in which there is a pending change.
|
|
1195 (defvar font-lock-pending-buffer-table (make-hash-table :weakness 'key))
|
|
1196 ;; table used to keep track of ranges needing fontification.
|
442
|
1197 (defvar font-lock-range-table (make-range-table))
|
428
|
1198
|
|
1199 (defun font-lock-pre-idle-hook ()
|
793
|
1200 (with-trapping-errors 'font-lock-pre-idle-hook
|
|
1201 (if (> (hash-table-count font-lock-pending-buffer-table) 0)
|
|
1202 (font-lock-fontify-pending-extents))))
|
428
|
1203
|
|
1204 ;;; called when any modification is made to buffer text. This function
|
442
|
1205 ;;; remembers the changed ranges until the next redisplay, at which point
|
|
1206 ;;; the extents are merged and pruned, and the resulting ranges fontified.
|
|
1207 ;;; This function could easily be adapted to other after-change-functions.
|
428
|
1208
|
|
1209 (defun font-lock-after-change-function (beg end old-len)
|
442
|
1210 (when font-lock-mode
|
462
|
1211 ;; treat deletions as if the following character (or previous, if
|
664
|
1212 ;; there is no following) were inserted. (also use the previous
|
|
1213 ;; character at end of line. this avoids a problem when you
|
|
1214 ;; insert a comment on the line before a line of code: if we use
|
|
1215 ;; the following char, then when you hit backspace, the following
|
|
1216 ;; line of code turns the comment color.) this is a bit of a hack
|
462
|
1217 ;; but allows us to use text properties for everything.
|
|
1218 (if (= beg end)
|
670
|
1219 (cond ((not (save-excursion (goto-char end) (eolp)))
|
|
1220 (setq end (1+ end)))
|
462
|
1221 ((/= beg (point-min)) (setq beg (1- beg)))
|
|
1222 (t nil)))
|
|
1223 (put-text-property beg end 'font-lock-pending t)
|
|
1224 (puthash (current-buffer) t font-lock-pending-buffer-table)
|
442
|
1225 (if font-lock-always-fontify-immediately
|
|
1226 (font-lock-fontify-pending-extents))))
|
428
|
1227
|
442
|
1228 (defun font-lock-fontify-pending-extents ()
|
|
1229 ;; ah, the beauty of mapping functions.
|
|
1230 ;; this function is actually shorter than the old version, which handled
|
|
1231 ;; only one buffer and one contiguous region!
|
|
1232 (save-match-data
|
|
1233 (maphash
|
462
|
1234 #'(lambda (buffer dummy)
|
442
|
1235 ;; remove first, to avoid infinite reprocessing if error
|
462
|
1236 (remhash buffer font-lock-pending-buffer-table)
|
442
|
1237 (when (buffer-live-p buffer)
|
|
1238 (clear-range-table font-lock-range-table)
|
|
1239 (with-current-buffer buffer
|
|
1240 (save-excursion
|
|
1241 (save-restriction
|
462
|
1242 ;; if we don't widen, then the C code in
|
|
1243 ;; syntactically-sectionize will fail to realize that
|
|
1244 ;; we're inside a comment. #### We don't actually use
|
|
1245 ;; syntactically-sectionize any more. Do we still
|
|
1246 ;; need the widen?
|
442
|
1247 (widen)
|
502
|
1248 (map-extents
|
|
1249 #'(lambda (ex dummy-maparg)
|
|
1250 ;; first expand the ranges to full lines,
|
|
1251 ;; because that is what will be fontified;
|
|
1252 ;; then use a range table to merge the
|
|
1253 ;; ranges. (we could also do this simply using
|
|
1254 ;; text properties. the range table code was
|
|
1255 ;; here from a previous version of this code
|
|
1256 ;; and works just as well.)
|
|
1257 (let* ((beg (extent-start-position ex))
|
|
1258 (end (extent-end-position ex))
|
|
1259 (beg (progn (goto-char beg)
|
|
1260 (beginning-of-line)
|
|
1261 (point)))
|
|
1262 (end (progn (goto-char end)
|
|
1263 (forward-line 1)
|
|
1264 (point))))
|
|
1265 (put-range-table beg end t
|
|
1266 font-lock-range-table)))
|
|
1267 nil nil nil nil nil 'font-lock-pending t)
|
|
1268 ;; clear all pending extents first in case of error below.
|
|
1269 (put-text-property (point-min) (point-max)
|
|
1270 'font-lock-pending nil)
|
|
1271 (map-range-table
|
|
1272 #'(lambda (beg end val)
|
462
|
1273 ;; This creates some unnecessary progress gauges.
|
442
|
1274 ;; (if (and (= beg (point-min))
|
|
1275 ;; (= end (point-max)))
|
|
1276 ;; (font-lock-fontify-buffer)
|
|
1277 ;; (font-lock-fontify-region beg end)))
|
502
|
1278 (font-lock-fontify-region beg end))
|
|
1279 font-lock-range-table))))))
|
462
|
1280 font-lock-pending-buffer-table)))
|
428
|
1281
|
|
1282 ;; Syntactic fontification functions.
|
|
1283
|
430
|
1284 (defun font-lock-lisp-like (mode)
|
|
1285 ;; Note: (or (get mode 'font-lock-lisp-like) (string-match ...)) is
|
|
1286 ;; not enough because the property needs to be able to specify a nil
|
|
1287 ;; value.
|
|
1288 (if (plist-member (symbol-plist mode) 'font-lock-lisp-like)
|
|
1289 (get mode 'font-lock-lisp-like)
|
|
1290 ;; If the property is not specified, guess. Similar logic exists
|
|
1291 ;; in add-log, but I think this encompasses more modes.
|
|
1292 (string-match "lisp\\|scheme" (symbol-name mode))))
|
|
1293
|
460
|
1294 ;; fontify-syntactically-region used to use syntactically-sectionize, which
|
|
1295 ;; was supposedly much faster than the FSF version because it was written in
|
|
1296 ;; C. However, the FSF version uses parse-partial-sexp, which is also
|
|
1297 ;; written in C, and the benchmarking I did showed the
|
|
1298 ;; syntactically-sectionize code to be slower overall. So here's the FSF
|
|
1299 ;; version, modified to support font-lock-doc-string-face.
|
|
1300 ;; -- mct 2000-12-29
|
428
|
1301 (defun font-lock-fontify-syntactically-region (start end &optional loudly)
|
|
1302 "Put proper face on each string and comment between START and END.
|
|
1303 START should be at the beginning of a line."
|
|
1304 (if font-lock-keywords-only
|
|
1305 nil
|
460
|
1306
|
|
1307 ;; #### Shouldn't this just be using 'loudly??
|
428
|
1308 (when (and font-lock-verbose
|
|
1309 (>= (- end start) font-lock-message-threshold))
|
442
|
1310 (progress-feedback-with-label 'font-lock
|
|
1311 "Fontifying %s... (syntactically)" 5
|
|
1312 (buffer-name)))
|
428
|
1313 (goto-char start)
|
460
|
1314
|
|
1315 (let ((lisp-like (font-lock-lisp-like major-mode))
|
|
1316 (cache (marker-position font-lock-cache-position))
|
|
1317 state string beg depth)
|
|
1318 ;;
|
|
1319 ;; Find the state at the `beginning-of-line' before `start'.
|
|
1320 (if (eq start cache)
|
|
1321 ;; Use the cache for the state of `start'.
|
|
1322 (setq state font-lock-cache-state)
|
|
1323 ;; Find the state of `start'.
|
|
1324 (if (null font-lock-beginning-of-syntax-function)
|
|
1325 ;; Use the state at the previous cache position, if any, or
|
|
1326 ;; otherwise calculate from `point-min'.
|
|
1327 (if (or (null cache) (< start cache))
|
|
1328 (setq state (parse-partial-sexp (point-min) start))
|
|
1329 (setq state (parse-partial-sexp cache start nil nil
|
|
1330 font-lock-cache-state)))
|
|
1331 ;; Call the function to move outside any syntactic block.
|
|
1332 (funcall font-lock-beginning-of-syntax-function)
|
|
1333 (setq state (parse-partial-sexp (point) start)))
|
|
1334 ;; Cache the state and position of `start'.
|
|
1335 (setq font-lock-cache-state state)
|
|
1336 (set-marker font-lock-cache-position start))
|
|
1337 ;;
|
|
1338 ;; If the region starts inside a string or comment, show the extent of it.
|
|
1339 (when (or (nth 3 state) (nth 4 state))
|
|
1340 (setq string (nth 3 state) beg (point))
|
|
1341 (setq state (parse-partial-sexp (point) end nil nil state 'syntax-table))
|
|
1342 (font-lock-set-face beg (point) (if string
|
|
1343 font-lock-string-face
|
|
1344 font-lock-comment-face)))
|
|
1345 ;;
|
|
1346 ;; Find each interesting place between here and `end'.
|
|
1347 (while (and (< (point) end)
|
|
1348 (progn
|
|
1349 (setq state (parse-partial-sexp (point) end nil nil state
|
|
1350 'syntax-table))
|
|
1351 (or (nth 3 state) (nth 4 state))))
|
|
1352 (setq depth (nth 0 state) string (nth 3 state) beg (nth 8 state))
|
|
1353 (setq state (parse-partial-sexp (point) end nil nil state 'syntax-table))
|
|
1354 (if string
|
|
1355 ;; #### It would be nice if we handled Python and other
|
|
1356 ;; non-Lisp languages with docstrings correctly.
|
|
1357 (let ((face (if (and lisp-like (= depth 1))
|
|
1358 'font-lock-doc-string-face
|
|
1359 'font-lock-string-face)))
|
|
1360 (if font-lock-fontify-string-delimiters
|
|
1361 (font-lock-set-face beg (point) face)
|
|
1362 (font-lock-set-face (+ beg 1) (- (point) 1) face)))
|
|
1363 (font-lock-set-face beg (point)
|
|
1364 font-lock-comment-face))))))
|
428
|
1365
|
|
1366 ;;; Additional text property functions.
|
|
1367
|
|
1368 ;; The following three text property functions are not generally available (and
|
|
1369 ;; it's not certain that they should be) so they are inlined for speed.
|
|
1370 ;; The case for `fillin-text-property' is simple; it may or not be generally
|
|
1371 ;; useful. (Since it is used here, it is useful in at least one place.;-)
|
|
1372 ;; However, the case for `append-text-property' and `prepend-text-property' is
|
|
1373 ;; more complicated. Should they remove duplicate property values or not? If
|
|
1374 ;; so, should the first or last duplicate item remain? Or the one that was
|
|
1375 ;; added? In our implementation, the first duplicate remains.
|
|
1376
|
|
1377 ;; XEmacs: modified all these functions to use
|
|
1378 ;; `put-nonduplicable-text-property' instead of `put-text-property', and
|
|
1379 ;; the first one to take both SETPROP and MARKPROP, in accordance with the
|
|
1380 ;; changed definitions of `font-lock-any-faces-p' and `font-lock-set-face'.
|
|
1381
|
|
1382 (defsubst font-lock-fillin-text-property (start end setprop markprop value &optional object)
|
|
1383 "Fill in one property of the text from START to END.
|
|
1384 Arguments PROP and VALUE specify the property and value to put where none are
|
|
1385 already in place. Therefore existing property values are not overwritten.
|
|
1386 Optional argument OBJECT is the string or buffer containing the text."
|
|
1387 (let ((start (text-property-any start end markprop nil object)) next)
|
|
1388 (while start
|
|
1389 (setq next (next-single-property-change start markprop object end))
|
|
1390 (put-nonduplicable-text-property start next setprop value object)
|
|
1391 (put-nonduplicable-text-property start next markprop value object)
|
|
1392 (setq start (text-property-any next end markprop nil object)))))
|
|
1393
|
|
1394 ;; This function (from simon's unique.el) is rewritten and inlined for speed.
|
|
1395 ;(defun unique (list function)
|
|
1396 ; "Uniquify LIST, deleting elements using FUNCTION.
|
|
1397 ;Return the list with subsequent duplicate items removed by side effects.
|
|
1398 ;FUNCTION is called with an element of LIST and a list of elements from LIST,
|
|
1399 ;and should return the list of elements with occurrences of the element removed,
|
|
1400 ;i.e., a function such as `delete' or `delq'.
|
|
1401 ;This function will work even if LIST is unsorted. See also `uniq'."
|
|
1402 ; (let ((list list))
|
|
1403 ; (while list
|
|
1404 ; (setq list (setcdr list (funcall function (car list) (cdr list))))))
|
|
1405 ; list)
|
|
1406
|
|
1407 (defsubst font-lock-unique (list)
|
|
1408 "Uniquify LIST, deleting elements using `delq'.
|
|
1409 Return the list with subsequent duplicate items removed by side effects."
|
|
1410 (let ((list list))
|
|
1411 (while list
|
|
1412 (setq list (setcdr list (delq (car list) (cdr list))))))
|
|
1413 list)
|
|
1414
|
|
1415 ;; A generalisation of `facemenu-add-face' for any property, but without the
|
|
1416 ;; removal of inactive faces via `facemenu-discard-redundant-faces' and special
|
|
1417 ;; treatment of `default'. Uses `unique' to remove duplicate property values.
|
|
1418 (defsubst font-lock-prepend-text-property (start end prop value &optional object)
|
|
1419 "Prepend to one property of the text from START to END.
|
|
1420 Arguments PROP and VALUE specify the property and value to prepend to the value
|
|
1421 already in place. The resulting property values are always lists, and unique.
|
|
1422 Optional argument OBJECT is the string or buffer containing the text."
|
|
1423 (let ((val (if (listp value) value (list value))) next prev)
|
|
1424 (while (/= start end)
|
|
1425 (setq next (next-single-property-change start prop object end)
|
|
1426 prev (get-text-property start prop object))
|
|
1427 (put-text-property
|
|
1428 start next prop
|
|
1429 (font-lock-unique (append val (if (listp prev) prev (list prev))))
|
|
1430 object)
|
|
1431 (setq start next))))
|
|
1432
|
|
1433 (defsubst font-lock-append-text-property (start end prop value &optional object)
|
|
1434 "Append to one property of the text from START to END.
|
|
1435 Arguments PROP and VALUE specify the property and value to append to the value
|
|
1436 already in place. The resulting property values are always lists, and unique.
|
|
1437 Optional argument OBJECT is the string or buffer containing the text."
|
|
1438 (let ((val (if (listp value) value (list value))) next prev)
|
|
1439 (while (/= start end)
|
|
1440 (setq next (next-single-property-change start prop object end)
|
|
1441 prev (get-text-property start prop object))
|
|
1442 (put-text-property
|
|
1443 start next prop
|
|
1444 (font-lock-unique (append (if (listp prev) prev (list prev)) val))
|
|
1445 object)
|
|
1446 (setq start next))))
|
|
1447
|
460
|
1448 ;;; Syntactic regexp fontification functions (taken from FSF Emacs 20.7.1)
|
|
1449
|
|
1450 ;; These syntactic keyword pass functions are identical to those keyword pass
|
|
1451 ;; functions below, with the following exceptions; (a) they operate on
|
|
1452 ;; `font-lock-syntactic-keywords' of course, (b) they are all `defun' as speed
|
|
1453 ;; is less of an issue, (c) eval of property value does not occur JIT as speed
|
|
1454 ;; is less of an issue, (d) OVERRIDE cannot be `prepend' or `append' as it
|
|
1455 ;; makes no sense for `syntax-table' property values, (e) they do not do it
|
|
1456 ;; LOUDLY as it is not likely to be intensive.
|
|
1457
|
|
1458 (defun font-lock-apply-syntactic-highlight (highlight)
|
|
1459 "Apply HIGHLIGHT following a match.
|
|
1460 HIGHLIGHT should be of the form MATCH-HIGHLIGHT,
|
|
1461 see `font-lock-syntactic-keywords'."
|
|
1462 (let* ((match (nth 0 highlight))
|
|
1463 (start (match-beginning match)) (end (match-end match))
|
|
1464 (value (nth 1 highlight))
|
|
1465 (override (nth 2 highlight)))
|
|
1466 (unless (numberp (car-safe value))
|
|
1467 (setq value (eval value)))
|
|
1468 (cond ((not start)
|
|
1469 ;; No match but we might not signal an error.
|
|
1470 (or (nth 3 highlight)
|
|
1471 (error "No match %d in highlight %S" match highlight)))
|
|
1472 ((not override)
|
|
1473 ;; Cannot override existing fontification.
|
|
1474 (or (map-extents 'extent-property (current-buffer)
|
|
1475 start end 'syntax-table)
|
|
1476 (font-lock-set-syntax start end value)))
|
|
1477 ((eq override t)
|
|
1478 ;; Override existing fontification.
|
|
1479 (font-lock-set-syntax start end value))
|
|
1480 ((eq override 'keep)
|
|
1481 ;; Keep existing fontification.
|
|
1482 (font-lock-fillin-text-property start end
|
|
1483 'syntax-table 'font-lock value)))))
|
|
1484
|
|
1485 (defun font-lock-fontify-syntactic-anchored-keywords (keywords limit)
|
|
1486 "Fontify according to KEYWORDS until LIMIT.
|
|
1487 KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords',
|
|
1488 LIMIT can be modified by the value of its PRE-MATCH-FORM."
|
|
1489 (let ((matcher (nth 0 keywords)) (lowdarks (nthcdr 3 keywords)) highlights
|
|
1490 ;; Evaluate PRE-MATCH-FORM.
|
|
1491 (pre-match-value (eval (nth 1 keywords))))
|
|
1492 ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line.
|
|
1493 (if (and (numberp pre-match-value) (> pre-match-value (point)))
|
|
1494 (setq limit pre-match-value)
|
|
1495 (save-excursion (end-of-line) (setq limit (point))))
|
|
1496 (save-match-data
|
|
1497 ;; Find an occurrence of `matcher' before `limit'.
|
|
1498 (while (if (stringp matcher)
|
|
1499 (re-search-forward matcher limit t)
|
|
1500 (funcall matcher limit))
|
|
1501 ;; Apply each highlight to this instance of `matcher'.
|
|
1502 (setq highlights lowdarks)
|
|
1503 (while highlights
|
|
1504 (font-lock-apply-syntactic-highlight (car highlights))
|
|
1505 (setq highlights (cdr highlights)))))
|
|
1506 ;; Evaluate POST-MATCH-FORM.
|
|
1507 (eval (nth 2 keywords))))
|
|
1508
|
|
1509 (defun font-lock-fontify-syntactic-keywords-region (start end)
|
|
1510 "Fontify according to `font-lock-syntactic-keywords' between START and END.
|
|
1511 START should be at the beginning of a line."
|
|
1512 ;; ;; If `font-lock-syntactic-keywords' is a symbol, get the real keywords.
|
|
1513 (when (symbolp font-lock-syntactic-keywords)
|
|
1514 (setq font-lock-syntactic-keywords (font-lock-eval-keywords
|
|
1515 font-lock-syntactic-keywords)))
|
|
1516 ;; If `font-lock-syntactic-keywords' is not compiled, compile it.
|
|
1517 (unless (eq (car font-lock-syntactic-keywords) t)
|
|
1518 (setq font-lock-syntactic-keywords (font-lock-compile-keywords
|
|
1519 font-lock-syntactic-keywords)))
|
|
1520 ;; Get down to business.
|
|
1521 (let ((case-fold-search font-lock-keywords-case-fold-search)
|
|
1522 (keywords (cdr font-lock-syntactic-keywords))
|
|
1523 keyword matcher highlights)
|
|
1524 (while keywords
|
|
1525 ;; Find an occurrence of `matcher' from `start' to `end'.
|
|
1526 (setq keyword (car keywords) matcher (car keyword))
|
|
1527 (goto-char start)
|
|
1528 (while (if (stringp matcher)
|
|
1529 (re-search-forward matcher end t)
|
|
1530 (funcall matcher end))
|
|
1531 ;; Apply each highlight to this instance of `matcher', which may be
|
|
1532 ;; specific highlights or more keywords anchored to `matcher'.
|
|
1533 (setq highlights (cdr keyword))
|
|
1534 (while highlights
|
|
1535 (if (numberp (car (car highlights)))
|
|
1536 (font-lock-apply-syntactic-highlight (car highlights))
|
|
1537 (font-lock-fontify-syntactic-anchored-keywords (car highlights)
|
|
1538 end))
|
|
1539 (setq highlights (cdr highlights)))
|
|
1540 )
|
|
1541 (setq keywords (cdr keywords)))))
|
|
1542
|
428
|
1543 ;;; Regexp fontification functions.
|
|
1544
|
|
1545 (defsubst font-lock-apply-highlight (highlight)
|
|
1546 "Apply HIGHLIGHT following a match.
|
|
1547 HIGHLIGHT should be of the form MATCH-HIGHLIGHT, see `font-lock-keywords'."
|
|
1548 (let* ((match (nth 0 highlight))
|
|
1549 (start (match-beginning match)) (end (match-end match))
|
|
1550 (override (nth 2 highlight)))
|
|
1551 (let ((newface (nth 1 highlight)))
|
|
1552 (or (symbolp newface)
|
|
1553 (setq newface (eval newface)))
|
|
1554 (cond ((not start)
|
|
1555 ;; No match but we might not signal an error.
|
|
1556 (or (nth 3 highlight)
|
|
1557 (error "No match %d in highlight %S" match highlight)))
|
|
1558 ((= start end) nil)
|
|
1559 ((not override)
|
|
1560 ;; Cannot override existing fontification.
|
|
1561 (or (font-lock-any-faces-p start end)
|
|
1562 (font-lock-set-face start end newface)))
|
|
1563 ((eq override t)
|
|
1564 ;; Override existing fontification.
|
|
1565 (font-lock-set-face start end newface))
|
|
1566 ((eq override 'keep)
|
|
1567 ;; Keep existing fontification.
|
|
1568 (font-lock-fillin-text-property start end 'face 'font-lock
|
|
1569 newface))
|
|
1570 ((eq override 'prepend)
|
|
1571 ;; Prepend to existing fontification.
|
|
1572 (font-lock-prepend-text-property start end 'face newface))
|
|
1573 ((eq override 'append)
|
|
1574 ;; Append to existing fontification.
|
|
1575 (font-lock-append-text-property start end 'face newface))))))
|
|
1576
|
|
1577 (defsubst font-lock-fontify-anchored-keywords (keywords limit)
|
|
1578 "Fontify according to KEYWORDS until LIMIT.
|
|
1579 KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords',
|
|
1580 LIMIT can be modified by the value of its PRE-MATCH-FORM."
|
|
1581 (let ((matcher (nth 0 keywords)) (lowdarks (nthcdr 3 keywords)) highlights
|
|
1582 ;; Evaluate PRE-MATCH-FORM.
|
|
1583 (pre-match-value (eval (nth 1 keywords))))
|
|
1584 ;; Set LIMIT to value of PRE-MATCH-FORM or the end of line.
|
|
1585 (if (and (numberp pre-match-value) (> pre-match-value (point)))
|
|
1586 (setq limit pre-match-value)
|
|
1587 (save-excursion (end-of-line) (setq limit (point))))
|
|
1588 (save-match-data
|
|
1589 ;; Find an occurrence of `matcher' before `limit'.
|
|
1590 (while (if (stringp matcher)
|
|
1591 (re-search-forward matcher limit t)
|
|
1592 (funcall matcher limit))
|
|
1593 ;; Apply each highlight to this instance of `matcher'.
|
|
1594 (setq highlights lowdarks)
|
|
1595 (while highlights
|
|
1596 (font-lock-apply-highlight (car highlights))
|
|
1597 (setq highlights (cdr highlights)))))
|
|
1598 ;; Evaluate POST-MATCH-FORM.
|
|
1599 (eval (nth 2 keywords))))
|
|
1600
|
|
1601 (defun font-lock-fontify-keywords-region (start end &optional loudvar)
|
|
1602 "Fontify according to `font-lock-keywords' between START and END.
|
|
1603 START should be at the beginning of a line."
|
|
1604 (let ((loudly (and font-lock-verbose
|
|
1605 (>= (- end start) font-lock-message-threshold))))
|
566
|
1606 ;; If `font-lock-keywords' is not compiled, compile it.
|
|
1607 (unless (eq (car-safe font-lock-keywords) t)
|
|
1608 (setq font-lock-keywords (font-lock-compile-keywords
|
|
1609 font-lock-keywords)))
|
442
|
1610 (let* ((case-fold-search font-lock-keywords-case-fold-search)
|
566
|
1611 (keywords (cdr font-lock-keywords))
|
442
|
1612 (bufname (buffer-name))
|
|
1613 (progress 5) (old-progress 5)
|
|
1614 (iter 0)
|
|
1615 (nkeywords (length keywords))
|
|
1616 keyword matcher highlights)
|
428
|
1617 ;;
|
|
1618 ;; Fontify each item in `font-lock-keywords' from `start' to `end'.
|
442
|
1619 ;; In order to measure progress accurately we need to know how
|
|
1620 ;; many keywords we have and how big the region is. Then progress
|
|
1621 ;; is ((pos - start)/ (end - start) * nkeywords
|
|
1622 ;; + iteration / nkeywords) * 100
|
428
|
1623 (while keywords
|
|
1624 ;;
|
|
1625 ;; Find an occurrence of `matcher' from `start' to `end'.
|
|
1626 (setq keyword (car keywords) matcher (car keyword))
|
|
1627 (goto-char start)
|
|
1628 (while (and (< (point) end)
|
|
1629 (if (stringp matcher)
|
|
1630 (re-search-forward matcher end t)
|
|
1631 (funcall matcher end)))
|
442
|
1632 ;; calculate progress
|
|
1633 (setq progress
|
|
1634 (+ (/ (* (- (point) start) 95) (* (- end start) nkeywords))
|
|
1635 (/ (* iter 95) nkeywords) 5))
|
|
1636 (when (and loudly (> progress old-progress))
|
|
1637 (progress-feedback-with-label 'font-lock
|
|
1638 "Fontifying %s... (regexps)"
|
|
1639 progress bufname))
|
|
1640 (setq old-progress progress)
|
428
|
1641 ;; Apply each highlight to this instance of `matcher', which may be
|
|
1642 ;; specific highlights or more keywords anchored to `matcher'.
|
|
1643 (setq highlights (cdr keyword))
|
|
1644 (while highlights
|
|
1645 (if (numberp (car (car highlights)))
|
|
1646 (let ((end (match-end (car (car highlights)))))
|
|
1647 (font-lock-apply-highlight (car highlights))
|
|
1648 ;; restart search just after the end of the
|
|
1649 ;; keyword so keywords can share bracketing
|
|
1650 ;; expressions.
|
|
1651 (and end (goto-char end)))
|
|
1652 (font-lock-fontify-anchored-keywords (car highlights) end))
|
|
1653 (setq highlights (cdr highlights))))
|
442
|
1654 (setq iter (1+ iter))
|
428
|
1655 (setq keywords (cdr keywords))))
|
442
|
1656 (if loudly
|
|
1657 (progress-feedback-with-label 'font-lock "Fontifying %s... " 100
|
|
1658 (buffer-name)))))
|
428
|
1659
|
|
1660
|
|
1661 ;; Various functions.
|
|
1662
|
|
1663 ;; Turn off other related packages if they're on. I prefer a hook. --sm.
|
|
1664 ;; These explicit calls are easier to understand
|
|
1665 ;; because people know what they will do.
|
|
1666 ;; A hook is a mystery because it might do anything whatever. --rms.
|
|
1667 (defun font-lock-thing-lock-cleanup ()
|
776
|
1668 (cond ((and-boundp 'fast-lock-mode fast-lock-mode)
|
|
1669 (declare-fboundp (fast-lock-mode -1)))
|
|
1670 ((and-boundp 'lazy-lock-mode lazy-lock-mode)
|
|
1671 (declare-fboundp (lazy-lock-mode -1)))
|
|
1672 ((and-boundp 'lazy-shot-mode lazy-shot-mode)
|
|
1673 (declare-fboundp (lazy-shot-mode -1)))))
|
428
|
1674
|
502
|
1675 ; Do something special for these packages after fontifying. I prefer a hook.
|
428
|
1676 (defun font-lock-after-fontify-buffer ()
|
776
|
1677 (cond ((and-boundp 'fast-lock-mode fast-lock-mode)
|
502
|
1678 (declare-fboundp (fast-lock-after-fontify-buffer)))
|
776
|
1679 ((and-boundp 'lazy-lock-mode lazy-lock-mode)
|
502
|
1680 (declare-fboundp (lazy-lock-after-fontify-buffer)))))
|
428
|
1681
|
|
1682
|
|
1683 ;; Various functions.
|
|
1684
|
566
|
1685 (defun font-lock-compile-keywords (keywords)
|
428
|
1686 ;; Compile `font-lock-keywords' into the form (t KEYWORD ...) where KEYWORD
|
|
1687 ;; is the (MATCHER HIGHLIGHT ...) shown in the variable's doc string.
|
566
|
1688 (if (eq (car-safe keywords) t)
|
|
1689 keywords
|
|
1690 (cons t (mapcar 'font-lock-compile-keyword keywords))))
|
428
|
1691
|
|
1692 (defun font-lock-compile-keyword (keyword)
|
|
1693 (cond ((nlistp keyword) ; Just MATCHER
|
|
1694 (list keyword '(0 font-lock-keyword-face)))
|
|
1695 ((eq (car keyword) 'eval) ; Specified (eval . FORM)
|
|
1696 (font-lock-compile-keyword (eval (cdr keyword))))
|
|
1697 ((numberp (cdr keyword)) ; Specified (MATCHER . MATCH)
|
|
1698 (list (car keyword) (list (cdr keyword) 'font-lock-keyword-face)))
|
|
1699 ((symbolp (cdr keyword)) ; Specified (MATCHER . FACENAME)
|
|
1700 (list (car keyword) (list 0 (cdr keyword))))
|
|
1701 ((nlistp (nth 1 keyword)) ; Specified (MATCHER . HIGHLIGHT)
|
|
1702 (list (car keyword) (cdr keyword)))
|
|
1703 (t ; Hopefully (MATCHER HIGHLIGHT ...)
|
|
1704 keyword)))
|
|
1705
|
460
|
1706 (defun font-lock-eval-keywords (keywords)
|
|
1707 ;; Evalulate KEYWORDS if a function (funcall) or variable (eval) name.
|
|
1708 (if (listp keywords)
|
|
1709 keywords
|
|
1710 (font-lock-eval-keywords (if (fboundp keywords)
|
|
1711 (funcall keywords)
|
|
1712 (eval keywords)))))
|
|
1713
|
428
|
1714 (defun font-lock-choose-keywords (keywords level)
|
|
1715 ;; Return LEVELth element of KEYWORDS. A LEVEL of nil is equal to a
|
|
1716 ;; LEVEL of 0, a LEVEL of t is equal to (1- (length KEYWORDS)).
|
|
1717 (let ((level (if (not (consp level))
|
|
1718 level
|
|
1719 (cdr (or (assq major-mode level) (assq t level))))))
|
|
1720 (cond ((symbolp keywords)
|
|
1721 keywords)
|
|
1722 ((numberp level)
|
|
1723 (or (nth level keywords) (car (reverse keywords))))
|
|
1724 ((eq level t)
|
|
1725 (car (reverse keywords)))
|
|
1726 (t
|
|
1727 (car keywords)))))
|
|
1728
|
|
1729
|
|
1730 ;;; Determining which set of font-lock keywords to use.
|
|
1731
|
|
1732 (defun font-lock-find-font-lock-defaults (modesym)
|
|
1733 ;; Get the defaults based on the major mode.
|
|
1734 (let (raw-defaults)
|
|
1735 ;; I want a do-while loop!
|
|
1736 (while (progn
|
|
1737 (setq raw-defaults (get modesym 'font-lock-defaults))
|
|
1738 (and raw-defaults (symbolp raw-defaults)
|
|
1739 (setq modesym raw-defaults)))
|
|
1740 )
|
|
1741 raw-defaults))
|
|
1742
|
|
1743 (defun font-lock-examine-syntax-table ()
|
|
1744 ; Computes the value of font-lock-keywords-only for this buffer.
|
|
1745 (if (eq (syntax-table) (standard-syntax-table))
|
|
1746 ;; Assume that modes which haven't bothered to install their own
|
|
1747 ;; syntax table don't do anything syntactically interesting.
|
|
1748 ;; Really, the standard-syntax-table shouldn't have comments and
|
|
1749 ;; strings in it, but changing that now might break things.
|
|
1750 nil
|
|
1751 ;; else map over the syntax table looking for strings or comments.
|
|
1752 (let (got-one)
|
|
1753 ;; XEmacs 20.0 ...
|
|
1754 (if (fboundp 'map-syntax-table)
|
|
1755 (setq got-one
|
|
1756 (map-syntax-table
|
|
1757 #'(lambda (key value)
|
|
1758 (memq (char-syntax-from-code value)
|
|
1759 '(?\" ?\< ?\> ?\$)))
|
|
1760 (syntax-table)))
|
|
1761 ;; older Emacsen.
|
|
1762 (let ((i (1- (length (syntax-table)))))
|
|
1763 (while (>= i 0)
|
|
1764 (if (memq (char-syntax i) '(?\" ?\< ?\> ?\$))
|
|
1765 (setq got-one t i 0))
|
|
1766 (setq i (1- i)))))
|
|
1767 (set (make-local-variable 'font-lock-keywords-only) (not got-one)))))
|
|
1768
|
|
1769 ;; font-lock-set-defaults is in fontl-hooks.el.
|
|
1770
|
|
1771 ;;;###autoload
|
|
1772 (defun font-lock-set-defaults-1 (&optional explicit-defaults)
|
|
1773 ;; does everything that font-lock-set-defaults does except
|
|
1774 ;; enable font-lock-mode. This is called by `font-lock-mode'.
|
|
1775 ;; Note that the return value is used!
|
|
1776
|
|
1777 (if (and font-lock-defaults-computed (not explicit-defaults))
|
|
1778 ;; nothing to do.
|
|
1779 nil
|
|
1780
|
|
1781 (or font-lock-keywords
|
|
1782 (let* ((defaults (or (and (not (eq t explicit-defaults))
|
|
1783 explicit-defaults)
|
|
1784 ;; in case modes decide to set
|
|
1785 ;; `font-lock-defaults' themselves,
|
|
1786 ;; as in FSF Emacs.
|
|
1787 font-lock-defaults
|
|
1788 (font-lock-find-font-lock-defaults major-mode)))
|
|
1789 (keywords (font-lock-choose-keywords
|
|
1790 (nth 0 defaults) font-lock-maximum-decoration)))
|
460
|
1791
|
428
|
1792 ;; Keywords?
|
|
1793 (setq font-lock-keywords (if (fboundp keywords)
|
|
1794 (funcall keywords)
|
|
1795 (eval keywords)))
|
|
1796 (or font-lock-keywords
|
|
1797 ;; older way:
|
|
1798 ;; try to look for a variable `foo-mode-font-lock-keywords',
|
|
1799 ;; or similar.
|
|
1800 (let ((major (symbol-name major-mode))
|
|
1801 (try #'(lambda (n)
|
|
1802 (if (stringp n) (setq n (intern-soft n)))
|
|
1803 (if (and n
|
|
1804 (boundp n))
|
|
1805 n
|
|
1806 nil))))
|
|
1807 (setq font-lock-keywords
|
|
1808 (symbol-value
|
|
1809 (or (funcall try (get major-mode 'font-lock-keywords))
|
|
1810 (funcall try (concat major "-font-lock-keywords"))
|
|
1811 (funcall try (and (string-match "-mode\\'" major)
|
|
1812 (concat (substring
|
|
1813 major 0
|
|
1814 (match-beginning 0))
|
|
1815 "-font-lock-keywords")))
|
|
1816 'font-lock-keywords)))))
|
|
1817
|
|
1818 ;; Case fold?
|
|
1819 (if (>= (length defaults) 3)
|
|
1820 (setq font-lock-keywords-case-fold-search (nth 2 defaults))
|
|
1821 ;; older way:
|
|
1822 ;; look for a property 'font-lock-keywords-case-fold-search on
|
|
1823 ;; the major-mode symbol.
|
|
1824 (let* ((nonexist (make-symbol ""))
|
|
1825 (value (get major-mode 'font-lock-keywords-case-fold-search
|
|
1826 nonexist)))
|
|
1827 (if (not (eq nonexist value))
|
|
1828 (setq font-lock-keywords-case-fold-search value))))
|
|
1829
|
|
1830 ;; Syntactic?
|
|
1831 (if (>= (length defaults) 2)
|
|
1832 (setq font-lock-keywords-only (nth 1 defaults))
|
|
1833 ;; older way:
|
|
1834 ;; cleverly examine the syntax table.
|
|
1835 (font-lock-examine-syntax-table))
|
|
1836
|
|
1837 ;; Syntax table?
|
|
1838 (if (nth 3 defaults)
|
|
1839 (let ((slist (nth 3 defaults)))
|
|
1840 (setq font-lock-syntax-table
|
|
1841 (copy-syntax-table (syntax-table)))
|
|
1842 (while slist
|
|
1843 (modify-syntax-entry (car (car slist)) (cdr (car slist))
|
|
1844 font-lock-syntax-table)
|
|
1845 (setq slist (cdr slist)))))
|
|
1846
|
|
1847 ;; Syntax function?
|
|
1848 (cond (defaults
|
|
1849 (setq font-lock-beginning-of-syntax-function
|
|
1850 (nth 4 defaults)))
|
|
1851 (t
|
|
1852 ;; older way:
|
|
1853 ;; defaults not specified at all, so use `beginning-of-defun'.
|
|
1854 (setq font-lock-beginning-of-syntax-function
|
|
1855 'beginning-of-defun)))))
|
|
1856
|
460
|
1857 (setq font-lock-cache-position (make-marker))
|
428
|
1858 (setq font-lock-defaults-computed t)))
|
|
1859
|
|
1860
|
|
1861 ;;;;;;;;;;;;;;;;;;;;;; keywords ;;;;;;;;;;;;;;;;;;;;;;
|
|
1862
|
|
1863 ;;; Various major-mode interfaces.
|
|
1864 ;;; Probably these should go in with the source of the respective major modes.
|
|
1865
|
|
1866 ;; The defaults and keywords listed here should perhaps be moved into
|
|
1867 ;; mode-specific files.
|
|
1868
|
|
1869 ;; For C and Lisp modes we use `beginning-of-defun', rather than nil,
|
|
1870 ;; for SYNTAX-BEGIN. Thus the calculation of the cache is usually
|
|
1871 ;; faster but not infallible, so we risk mis-fontification. --sm.
|
|
1872
|
|
1873 (put 'c-mode 'font-lock-defaults
|
|
1874 '((c-font-lock-keywords
|
|
1875 c-font-lock-keywords-1 c-font-lock-keywords-2 c-font-lock-keywords-3)
|
|
1876 nil nil ((?_ . "w")) beginning-of-defun))
|
|
1877 (put 'c++-c-mode 'font-lock-defaults 'c-mode)
|
|
1878 (put 'elec-c-mode 'font-lock-defaults 'c-mode)
|
|
1879
|
|
1880 (put 'c++-mode 'font-lock-defaults
|
|
1881 '((c++-font-lock-keywords
|
|
1882 c++-font-lock-keywords-1 c++-font-lock-keywords-2
|
|
1883 c++-font-lock-keywords-3)
|
|
1884 nil nil ((?_ . "w") (?~ . "w")) beginning-of-defun))
|
|
1885
|
|
1886 (put 'java-mode 'font-lock-defaults
|
|
1887 '((java-font-lock-keywords
|
|
1888 java-font-lock-keywords-1 java-font-lock-keywords-2
|
|
1889 java-font-lock-keywords-3)
|
|
1890 nil nil ((?_ . "w")) beginning-of-defun
|
|
1891 (font-lock-mark-block-function . mark-defun)))
|
|
1892
|
|
1893 (put 'lisp-mode 'font-lock-defaults
|
|
1894 '((lisp-font-lock-keywords
|
|
1895 lisp-font-lock-keywords-1 lisp-font-lock-keywords-2)
|
|
1896 nil nil
|
|
1897 ((?: . "w") (?- . "w") (?* . "w") (?+ . "w") (?. . "w") (?< . "w")
|
|
1898 (?> . "w") (?= . "w") (?! . "w") (?? . "w") (?$ . "w") (?% . "w")
|
|
1899 (?_ . "w") (?& . "w") (?~ . "w") (?^ . "w") (?/ . "w"))
|
|
1900 beginning-of-defun))
|
|
1901 (put 'emacs-lisp-mode 'font-lock-defaults 'lisp-mode)
|
|
1902 (put 'lisp-interaction-mode 'font-lock-defaults 'lisp-mode)
|
|
1903
|
|
1904 (put 'scheme-mode 'font-lock-defaults
|
|
1905 '(scheme-font-lock-keywords
|
|
1906 nil t
|
|
1907 ((?: . "w") (?- . "w") (?* . "w") (?+ . "w") (?. . "w") (?< . "w")
|
|
1908 (?> . "w") (?= . "w") (?! . "w") (?? . "w") (?$ . "w") (?% . "w")
|
|
1909 (?_ . "w") (?& . "w") (?~ . "w") (?^ . "w") (?/ . "w"))
|
|
1910 beginning-of-defun))
|
|
1911 (put 'inferior-scheme-mode 'font-lock-defaults 'scheme-mode)
|
|
1912 (put 'scheme-interaction-mode 'font-lock-defaults 'scheme-mode)
|
|
1913
|
|
1914 (put 'tex-mode 'font-lock-defaults
|
|
1915 ;; For TeX modes we could use `backward-paragraph' for the same reason.
|
|
1916 '(tex-font-lock-keywords nil nil ((?$ . "\""))))
|
|
1917 ;; the nine billion names of TeX mode...
|
|
1918 (put 'bibtex-mode 'font-lock-defaults 'tex-mode)
|
|
1919 (put 'plain-tex-mode 'font-lock-defaults 'tex-mode)
|
|
1920 (put 'slitex-tex-mode 'font-lock-defaults 'tex-mode)
|
|
1921 (put 'SliTeX-mode 'font-lock-defaults 'tex-mode)
|
|
1922 (put 'slitex-mode 'font-lock-defaults 'tex-mode)
|
|
1923 (put 'latex-tex-mode 'font-lock-defaults 'tex-mode)
|
|
1924 (put 'LaTex-tex-mode 'font-lock-defaults 'tex-mode)
|
|
1925 (put 'latex-mode 'font-lock-defaults 'tex-mode)
|
|
1926 (put 'LaTeX-mode 'font-lock-defaults 'tex-mode)
|
|
1927 (put 'japanese-LaTeX-mode 'font-lock-defaults 'tex-mode)
|
|
1928 (put 'japanese-SliTeX-mode 'font-lock-defaults 'tex-mode)
|
|
1929 (put 'FoilTeX-mode 'font-lock-defaults 'tex-mode)
|
|
1930 (put 'LATeX-MoDe 'font-lock-defaults 'tex-mode)
|
|
1931 (put 'lATEx-mODe 'font-lock-defaults 'tex-mode)
|
|
1932 ;; ok, this is getting a bit silly ...
|
|
1933 (put 'eDOm-xETAl 'font-lock-defaults 'tex-mode)
|
|
1934
|
|
1935 ;;; Various regexp information shared by several modes.
|
|
1936 ;;; Information specific to a single mode should go in its load library.
|
|
1937
|
|
1938 (defconst lisp-font-lock-keywords-1
|
|
1939 (list
|
771
|
1940 ;; Anything not a function or type declaration is fontified as a
|
|
1941 ;; variable. It would be cleaner to allow preceding whitespace, but it
|
|
1942 ;; would also be about five times slower. We used to fontify unknown
|
|
1943 ;; stuff as functions, rather than variables, but random things are
|
|
1944 ;; generally more like variables (no parameters), and the function and
|
|
1945 ;; keyword colors are currently the same, while the variable color is
|
|
1946 ;; different, which looks better.
|
872
|
1947 (list (concat
|
|
1948 "^(\\(" lisp-function-and-type-regexp
|
|
1949 ;; Former variable declarations, but woefully inadequate.
|
|
1950 ;; "\\|def\\(const\\(\\|ant\\)\\|ine-key\\(\\|-after\\)\\|"
|
|
1951 ;; "var\\|custom\\)"
|
|
1952 ;; Everything else is a variable declaration.
|
|
1953 ;; anything else is a variable
|
|
1954 "\\|def\\([^ \t\n\(\)]+\\)"
|
|
1955 ;; make sure we are at end of word.
|
|
1956 "\\)\\>"
|
|
1957 ;; Any whitespace following and declared object.
|
|
1958 "[ \t'\(]*"
|
|
1959 "\\([^ \t\n\)]+\\)?")
|
|
1960 ;; Note about numbering: #1 is the grouping around the whole
|
|
1961 ;; keyword. #2 - #4 are in lisp-function-and-type-regexp.
|
|
1962 ;; #5 is for variables. (Must be set if neither #3 nor #4 are.)
|
|
1963 ;; #6 for the following object.
|
|
1964 '(1 font-lock-keyword-face)
|
|
1965 '(6 (cond ((match-beginning 3) 'font-lock-function-name-face)
|
|
1966 ((match-beginning 4) 'font-lock-type-face)
|
|
1967 (t 'font-lock-variable-name-face))
|
|
1968 nil t))
|
428
|
1969 )
|
|
1970 "Subdued level highlighting Lisp modes.")
|
|
1971
|
|
1972 (defconst lisp-font-lock-keywords-2
|
|
1973 (append lisp-font-lock-keywords-1
|
|
1974 (list
|
|
1975 ;;
|
|
1976 ;; Control structures. ELisp and CLisp combined.
|
|
1977 ;;
|
|
1978 (cons
|
|
1979 (concat
|
|
1980 "(\\("
|
442
|
1981 ;; beginning of generated stuff
|
|
1982 ;; to regenerate, use the regexp-opt below, then delete the outermost
|
|
1983 ;; grouping, then use the macro below to break up the string.
|
|
1984 ;; (regexp-opt
|
|
1985 ;; '("cond" "if" "while" "let" "let*" "prog" "progn" "prog1"
|
|
1986 ;; "prog2" "progv" "catch" "throw" "save-restriction"
|
|
1987 ;; "save-excursion" "save-window-excursion"
|
|
1988 ;; "save-current-buffer" "with-current-buffer"
|
|
1989 ;; "save-selected-window" "with-selected-window"
|
|
1990 ;; "save-selected-frame" "with-selected-frame"
|
|
1991 ;; "with-temp-file" "with-temp-buffer" "with-output-to-string"
|
|
1992 ;; "with-string-as-buffer-contents"
|
|
1993 ;; "save-match-data" "unwind-protect" "call-with-condition-handler"
|
|
1994 ;; "condition-case" "track-mouse" "autoload"
|
|
1995 ;; "eval-after-load" "eval-and-compile" "eval-when-compile"
|
|
1996 ;; "when" "unless" "do" "dolist" "dotimes" "flet" "labels"
|
|
1997 ;; "lambda" "block" "return" "return-from" "loop") t)
|
|
1998 ;; (setq last-kbd-macro
|
|
1999 ;; (read-kbd-macro "\" C-7 C-1 <right> C-r \\\\| 3*<right> \" RET"))
|
|
2000 "autoload\\|block\\|c\\(?:a\\(?:ll-with-condition-handler\\|tch\\)\\|"
|
|
2001 "ond\\(?:ition-case\\)?\\)\\|do\\(?:list\\|times\\)?\\|"
|
|
2002 "eval-\\(?:a\\(?:fter-load\\|nd-compile\\)\\|when-compile\\)\\|flet\\|"
|
|
2003 "if\\|l\\(?:a\\(?:bels\\|mbda\\)\\|et\\*?\\|oop\\)\\|prog[12nv]?\\|"
|
|
2004 "return\\(?:-from\\)?\\|save-\\(?:current-buffer\\|excursion\\|"
|
|
2005 "match-data\\|restriction\\|selected-\\(?:frame\\|window\\)\\|"
|
|
2006 "window-excursion\\)\\|t\\(?:hrow\\|rack-mouse\\)\\|un\\(?:less\\|"
|
|
2007 "wind-protect\\)\\|w\\(?:h\\(?:en\\|ile\\)\\|ith-\\(?:current-buffer\\|"
|
|
2008 "output-to-string\\|s\\(?:elected-\\(?:frame\\|window\\)\\|"
|
|
2009 "tring-as-buffer-contents\\)\\|temp-\\(?:buffer\\|file\\)\\)\\)"
|
|
2010 ;; end of generated stuff
|
428
|
2011 "\\)\\>") 1)
|
|
2012 ;;
|
|
2013 ;; Feature symbols as references.
|
|
2014 '("(\\(featurep\\|provide\\|require\\)\\>[ \t']*\\(\\sw+\\)?"
|
|
2015 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
|
|
2016 ;;
|
|
2017 ;; Words inside \\[] tend to be for `substitute-command-keys'.
|
|
2018 '("\\\\\\\\\\[\\(\\sw+\\)]" 1 font-lock-reference-face prepend)
|
|
2019 ;;
|
|
2020 ;; Words inside `' tend to be symbol names.
|
|
2021 '("`\\(\\sw\\sw+\\)'" 1 font-lock-reference-face prepend)
|
|
2022 ;;
|
|
2023 ;; CLisp `:' keywords as references.
|
|
2024 '("\\<:\\sw+\\>" 0 font-lock-reference-face prepend)
|
|
2025 ;;
|
|
2026 ;; ELisp and CLisp `&' keywords as types.
|
|
2027 '("\\<\\&\\(optional\\|rest\\|whole\\)\\>" . font-lock-type-face)
|
|
2028 ))
|
|
2029 "Gaudy level highlighting for Lisp modes.")
|
|
2030
|
|
2031 (defvar lisp-font-lock-keywords lisp-font-lock-keywords-1
|
|
2032 "Default expressions to highlight in Lisp modes.")
|
|
2033
|
|
2034 ;; The previous version, before replacing it with the FSF version.
|
|
2035 ;(defconst lisp-font-lock-keywords-1 (purecopy
|
|
2036 ; '(;;
|
|
2037 ; ;; highlight defining forms. This doesn't work too nicely for
|
|
2038 ; ;; (defun (setf foo) ...) but it does work for (defvar foo) which
|
|
2039 ; ;; is more important.
|
|
2040 ; ("^(def[-a-z]+\\s +\\([^ \t\n\)]+\\)" 1 font-lock-function-name-face)
|
|
2041 ; ;;
|
|
2042 ; ;; highlight CL keywords (three clauses seems faster than one)
|
|
2043 ; ("\\s :\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1)
|
|
2044 ; ("(:\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1)
|
|
2045 ; ("':\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1)
|
|
2046 ; ;;
|
|
2047 ; ;; this is highlights things like (def* (setf foo) (bar baz)), but may
|
|
2048 ; ;; be slower (I haven't really thought about it)
|
|
2049 ;; ("^(def[-a-z]+\\s +\\(\\s(\\S)*\\s)\\|\\S(\\S *\\)"
|
|
2050 ;; 1 font-lock-function-name-face)
|
|
2051 ; ))
|
|
2052 ; "For consideration as a value of `lisp-font-lock-keywords'.
|
|
2053 ;This does fairly subdued highlighting.")
|
|
2054 ;
|
|
2055 ;(defconst lisp-font-lock-keywords-2 (purecopy
|
|
2056 ; (append lisp-font-lock-keywords-1
|
|
2057 ; '(;;
|
|
2058 ; ;; Highlight control structures
|
|
2059 ; ("(\\(cond\\|if\\|when\\|unless\\|[ec]?\\(type\\)?case\\)[ \t\n]" . 1)
|
|
2060 ; ("(\\(while\\|do\\|let\\*?\\|flet\\|labels\\|prog[nv12*]?\\)[ \t\n]" . 1)
|
|
2061 ; ("(\\(do\\*\\|dotimes\\|dolist\\|loop\\)[ \t\n]" . 1)
|
|
2062 ; ("(\\(catch\\|\\throw\\|block\\|return\\|return-from\\)[ \t\n]" . 1)
|
|
2063 ; ("(\\(save-restriction\\|save-window-restriction\\)[ \t\n]" . 1)
|
|
2064 ; ("(\\(save-excursion\\|unwind-protect\\|condition-case\\)[ \t\n]" . 1)
|
|
2065 ; ;;
|
|
2066 ; ;; highlight function names in emacs-lisp docstrings (in the syntax
|
|
2067 ; ;; that substitute-command-keys understands.)
|
|
2068 ; ("\\\\\\\\\\[\\([^]\\\n]+\\)]" 1 font-lock-keyword-face t)
|
|
2069 ; ;;
|
|
2070 ; ;; highlight words inside `' which tend to be function names
|
|
2071 ; ("`\\([-a-zA-Z0-9_][-a-zA-Z0-9_][-a-zA-Z0-9_.]+\\)'"
|
|
2072 ; 1 font-lock-keyword-face t)
|
|
2073 ; )))
|
|
2074 ; "For consideration as a value of `lisp-font-lock-keywords'.
|
|
2075 ;
|
|
2076 ;This does a lot more highlighting.")
|
|
2077
|
|
2078 (defvar scheme-font-lock-keywords
|
|
2079 (eval-when-compile
|
|
2080 (list
|
|
2081 ;;
|
|
2082 ;; Declarations. Hannes Haug <hannes.haug@student.uni-tuebingen.de> says
|
|
2083 ;; this works for SOS, STklos, SCOOPS, Meroon and Tiny CLOS.
|
|
2084 (list (concat "(\\(define\\("
|
|
2085 ;; Function names.
|
|
2086 "\\(\\|-\\(generic\\(\\|-procedure\\)\\|method\\)\\)\\|"
|
|
2087 ;; Macro names, as variable names. A bit dubious, this.
|
|
2088 "\\(-syntax\\)\\|"
|
|
2089 ;; Class names.
|
|
2090 "\\(-class\\)"
|
|
2091 "\\)\\)\\>"
|
|
2092 ;; Any whitespace and declared object.
|
|
2093 "[ \t]*(?"
|
|
2094 "\\(\\sw+\\)?")
|
|
2095 '(1 font-lock-keyword-face)
|
|
2096 '(8 (cond ((match-beginning 3) 'font-lock-function-name-face)
|
|
2097 ((match-beginning 6) 'font-lock-variable-name-face)
|
|
2098 (t 'font-lock-type-face))
|
|
2099 nil t))
|
|
2100 ;;
|
|
2101 ;; Control structures.
|
|
2102 ;(regexp-opt '("begin" "call-with-current-continuation" "call/cc"
|
|
2103 ; "call-with-input-file" "call-with-output-file" "case" "cond"
|
|
2104 ; "do" "else" "for-each" "if" "lambda"
|
|
2105 ; "let\\*?" "let-syntax" "letrec" "letrec-syntax"
|
|
2106 ; ;; Hannes Haug <hannes.haug@student.uni-tuebingen.de> wants:
|
|
2107 ; "and" "or" "delay"
|
|
2108 ; ;; Stefan Monnier <stefan.monnier@epfl.ch> says don't bother:
|
|
2109 ; ;;"quasiquote" "quote" "unquote" "unquote-splicing"
|
|
2110 ; "map" "syntax" "syntax-rules"))
|
|
2111 (cons
|
|
2112 (concat "(\\("
|
|
2113 "and\\|begin\\|c\\(a\\(ll\\(-with-\\(current-continuation\\|"
|
|
2114 "input-file\\|output-file\\)\\|/cc\\)\\|se\\)\\|ond\\)\\|"
|
|
2115 "d\\(elay\\|o\\)\\|else\\|for-each\\|if\\|"
|
|
2116 "l\\(ambda\\|et\\(-syntax\\|\\*?\\|rec\\(\\|-syntax\\)\\)\\)\\|"
|
|
2117 "map\\|or\\|syntax\\(\\|-rules\\)"
|
|
2118 "\\)\\>") 1)
|
|
2119 ;;
|
|
2120 ;; David Fox <fox@graphics.cs.nyu.edu> for SOS/STklos class specifiers.
|
|
2121 '("\\<<\\sw+>\\>" . font-lock-type-face)
|
|
2122 ;;
|
|
2123 ;; Scheme `:' keywords as references.
|
|
2124 '("\\<:\\sw+\\>" . font-lock-reference-face)
|
|
2125 ))
|
|
2126 "Default expressions to highlight in Scheme modes.")
|
|
2127
|
|
2128 ;; The previous version, before replacing it with the FSF version.
|
|
2129 ;(defconst scheme-font-lock-keywords (purecopy
|
|
2130 ; '(("(define[ \t]+(?\\([^ \t\n\)]+\\)" 1 font-lock-function-name-face)
|
|
2131 ; ("(\\(cond\\|lambda\\|begin\\|if\\|else\\|case\\|do\\)[ \t\n]" . 1)
|
|
2132 ; ("(\\(\\|letrec\\|let\\*?\\|set!\\|and\\|or\\)[ \t\n]" . 1)
|
|
2133 ; ("(\\(quote\\|unquote\\|quasiquote\\|unquote-splicing\\)[ \t\n]" . 1)
|
|
2134 ; ("(\\(syntax\\|syntax-rules\\|define-syntax\\|let-syntax\\|letrec-syntax\\)[ \t\n]" . 1)))
|
|
2135 ; "Expressions to highlight in Scheme buffers.")
|
|
2136
|
|
2137 (defconst c-font-lock-keywords-1 nil
|
|
2138 "Subdued level highlighting for C modes.")
|
|
2139
|
|
2140 (defconst c-font-lock-keywords-2 nil
|
|
2141 "Medium level highlighting for C modes.")
|
|
2142
|
|
2143 (defconst c-font-lock-keywords-3 nil
|
|
2144 "Gaudy level highlighting for C modes.")
|
|
2145
|
|
2146 (defconst c++-font-lock-keywords-1 nil
|
|
2147 "Subdued level highlighting for C++ modes.")
|
|
2148
|
|
2149 (defconst c++-font-lock-keywords-2 nil
|
|
2150 "Medium level highlighting for C++ modes.")
|
|
2151
|
|
2152 (defconst c++-font-lock-keywords-3 nil
|
|
2153 "Gaudy level highlighting for C++ modes.")
|
|
2154
|
|
2155 (defun font-lock-match-c++-style-declaration-item-and-skip-to-next (limit)
|
|
2156 ;; Match, and move over, any declaration/definition item after point.
|
|
2157 ;; The expect syntax of an item is "word" or "word::word", possibly ending
|
|
2158 ;; with optional whitespace and a "(". Everything following the item (but
|
|
2159 ;; belonging to it) is expected to by skip-able by `forward-sexp', and items
|
|
2160 ;; are expected to be separated with a "," or ";".
|
|
2161 (if (looking-at "[ \t*&]*\\(\\(?:\\sw\\|\\s_\\)+\\)\\(::\\(\\(?:\\sw\\|\\s_\\)+\\)\\)?[ \t]*\\((\\)?")
|
|
2162 (save-match-data
|
|
2163 (condition-case nil
|
|
2164 (save-restriction
|
|
2165 ;; Restrict to the end of line, currently guaranteed to be LIMIT.
|
|
2166 (narrow-to-region (point-min) limit)
|
|
2167 (goto-char (match-end 1))
|
|
2168 ;; Move over any item value, etc., to the next item.
|
|
2169 (while (not (looking-at "[ \t]*\\([,;]\\|$\\)"))
|
|
2170 (goto-char (or (scan-sexps (point) 1) (point-max))))
|
|
2171 (goto-char (match-end 0)))
|
|
2172 (error t)))))
|
|
2173
|
|
2174 (let ((c-keywords
|
|
2175 ; ("break" "continue" "do" "else" "for" "if" "return" "switch" "while")
|
|
2176 "break\\|continue\\|do\\|else\\|for\\|if\\|return\\|switch\\|while")
|
|
2177 (c-type-types
|
|
2178 ; ("auto" "extern" "register" "static" "typedef" "struct" "union" "enum"
|
|
2179 ; "signed" "unsigned" "short" "long" "int" "char" "float" "double"
|
|
2180 ; "void" "volatile" "const")
|
|
2181 (concat "auto\\|c\\(har\\|onst\\)\\|double\\|e\\(num\\|xtern\\)\\|"
|
|
2182 "float\\|int\\|long\\|register\\|"
|
|
2183 "s\\(hort\\|igned\\|t\\(atic\\|ruct\\)\\)\\|typedef\\|"
|
|
2184 "un\\(ion\\|signed\\)\\|vo\\(id\\|latile\\)")) ; 6 ()s deep.
|
|
2185 (c++-keywords
|
|
2186 ; ("break" "continue" "do" "else" "for" "if" "return" "switch" "while"
|
|
2187 ; "asm" "catch" "delete" "new" "operator" "sizeof" "this" "throw" "try"
|
448
|
2188 ; "protected" "private" "public" "const_cast" "dynamic_cast" "reinterpret_cast"
|
|
2189 ; "static_cast" "and" "bitor" "or" "xor" "compl" "bitand" "and_eq"
|
|
2190 ; "or_eq" "xor_eq" "not" "not_eq" "typeid" "false" "true")
|
|
2191 (concat "a\\(nd\\(\\|_eq\\)\\|sm\\)\\|"
|
|
2192 "b\\(it\\(or\\|and\\)\\|reak\\)\\|"
|
|
2193 "c\\(atch\\|o\\(mpl\\|n\\(tinue\\|st_cast\\)\\)\\)\\|"
|
|
2194 "d\\(elete\\|o\\|ynamic_cast\\)\\|"
|
|
2195 "else\\|"
|
|
2196 "f\\(alse\\|or\\)\\|if\\|"
|
|
2197 "n\\(ew\\|ot\\(\\|_eq\\)\\)\\|"
|
|
2198 "p\\(r\\(ivate\\|otected\\)\\|ublic\\)\\|"
|
|
2199 "or\\(\\|_eq\\)\\|"
|
|
2200 "re\\(interpret_cast\\|turn\\)\\|"
|
|
2201 "s\\(izeof\\|tatic_cast\\|witch\\)\\|"
|
|
2202 "t\\(h\\(is\\|row\\)\\|r\\(ue\\|y\\)\\|ypeid\\)\\|"
|
|
2203 "xor\\(\\|_eq\\)\\|while"))
|
428
|
2204 (c++-type-types
|
|
2205 ; ("auto" "extern" "register" "static" "typedef" "struct" "union" "enum"
|
|
2206 ; "signed" "unsigned" "short" "long" "int" "char" "float" "double"
|
|
2207 ; "void" "volatile" "const" "class" "inline" "friend" "bool"
|
448
|
2208 ; "virtual" "complex" "template" "explicit" "mutable" "export" "namespace"
|
|
2209 ; "using" "typename" "wchar_t")
|
428
|
2210 (concat "auto\\|bool\\|c\\(har\\|lass\\|o\\(mplex\\|nst\\)\\)\\|"
|
448
|
2211 "double\\|"
|
|
2212 "e\\(num\\|x\\(p\\(licit\\|ort\\)\\|tern\\)\\)\\|"
|
|
2213 "f\\(loat\\|riend\\)\\|"
|
|
2214 "in\\(line\\|t\\)\\|long\\|mutable\\|namespace\\|register\\|"
|
428
|
2215 "s\\(hort\\|igned\\|t\\(atic\\|ruct\\)\\)\\|"
|
448
|
2216 "t\\(emplate\\|ype\\(def\\|name\\)\\)\\|"
|
|
2217 "u\\(\\(n\\(ion\\|signed\\)\\|sing\\)\\)\\|"
|
|
2218 "v\\(irtual\\|o\\(id\\|latile\\)\\)\\|"
|
|
2219 "wchar_t")) ; 11 ()s deep.
|
428
|
2220 (ctoken "\\(\\sw\\|\\s_\\|[:~*&]\\)+")
|
|
2221 )
|
|
2222 (setq c-font-lock-keywords-1
|
|
2223 (list
|
|
2224 ;;
|
|
2225 ;; These are all anchored at the beginning of line for speed.
|
|
2226 ;;
|
|
2227 ;; Fontify function name definitions (GNU style; without type on line).
|
|
2228
|
|
2229 ;; In FSF this has the simpler definition of "\\sw+" for ctoken.
|
|
2230 ;; I'm not sure if ours is more correct.
|
|
2231 ;; This is a subset of the next rule, and is slower when present. --dmoore
|
|
2232 ;; (list (concat "^\\(" ctoken "\\)[ \t]*(") 1 'font-lock-function-name-face)
|
|
2233 ;;
|
|
2234 ;; fontify the names of functions being defined.
|
|
2235 ;; FSF doesn't have this but I think it should be fast for us because
|
|
2236 ;; our regexp routines are more intelligent than FSF's about handling
|
|
2237 ;; anchored-at-newline. (When I added this hack in regex.c, it halved
|
|
2238 ;; the time to do the regexp phase of font-lock for a C file!) Not
|
|
2239 ;; including this discriminates against those who don't follow the
|
|
2240 ;; GNU coding style. --ben
|
|
2241 ;; x?x?x?y?z should always be: (x(xx?)?)?y?z --dmoore
|
|
2242 (list (concat
|
|
2243 "^\\("
|
|
2244 "\\(" ctoken "[ \t]+\\)" ; type specs; there can be no
|
|
2245 "\\("
|
|
2246 "\\(" ctoken "[ \t]+\\)" ; more than 3 tokens, right?
|
|
2247 "\\(" ctoken "[ \t]+\\)"
|
|
2248 "?\\)?\\)?"
|
|
2249 "\\([*&]+[ \t]*\\)?" ; pointer
|
|
2250 "\\(" ctoken "\\)[ \t]*(") ; name
|
|
2251 10 'font-lock-function-name-face)
|
|
2252 ;;
|
|
2253 ;; This is faster but not by much. I don't see why not.
|
|
2254 ;(list (concat "^\\(" ctoken "\\)[ \t]*(") 1 'font-lock-function-name-face)
|
|
2255 ;;
|
|
2256 ;; Added next two; they're both jolly-good fastmatch candidates so
|
|
2257 ;; should be fast. --ben
|
|
2258 ;;
|
|
2259 ;; Fontify structure names (in structure definition form).
|
|
2260 (list (concat "^\\(typedef[ \t]+struct\\|struct\\|static[ \t]+struct\\)"
|
|
2261 "[ \t]+\\(" ctoken "\\)[ \t]*\\(\{\\|$\\)")
|
|
2262 2 'font-lock-function-name-face)
|
|
2263 ;;
|
|
2264 ;; Fontify case clauses. This is fast because its anchored on the left.
|
|
2265 '("case[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)[ \t]+:". 1)
|
|
2266 ;;
|
|
2267 '("\\<\\(default\\):". 1)
|
|
2268 ;; Fontify filenames in #include <...> preprocessor directives as strings.
|
|
2269 '("^#[ \t]*include[ \t]+\\(<[^>\"\n]+>\\)" 1 font-lock-string-face)
|
|
2270 ;;
|
|
2271 ;; Fontify function macro names.
|
|
2272 '("^#[ \t]*define[ \t]+\\(\\(\\sw+\\)(\\)" 2 font-lock-function-name-face)
|
|
2273 ;;
|
|
2274 ;; Fontify symbol names in #if ... defined preprocessor directives.
|
|
2275 '("^#[ \t]*if\\>"
|
|
2276 ("\\<\\(defined\\)\\>[ \t]*(?\\(\\sw+\\)?" nil nil
|
|
2277 (1 font-lock-preprocessor-face) (2 font-lock-variable-name-face nil t)))
|
|
2278 ;;
|
|
2279 ;; Fontify symbol names in #elif ... defined preprocessor directives.
|
|
2280 '("^#[ \t]*elif\\>"
|
|
2281 ("\\<\\(defined\\)\\>[ \t]*(?\\(\\sw+\\)?" nil nil
|
|
2282 (1 font-lock-preprocessor-face) (2 font-lock-variable-name-face nil t)))
|
|
2283 ;;
|
|
2284 ;; Fontify otherwise as symbol names, and the preprocessor directive names.
|
|
2285 '("^\\(#[ \t]*[a-z]+\\)\\>[ \t]*\\(\\sw+\\)?"
|
|
2286 (1 font-lock-preprocessor-face) (2 font-lock-variable-name-face nil t))
|
|
2287 ))
|
|
2288
|
|
2289 (setq c-font-lock-keywords-2
|
|
2290 (append c-font-lock-keywords-1
|
|
2291 (list
|
|
2292 ;;
|
|
2293 ;; Simple regexps for speed.
|
|
2294 ;;
|
|
2295 ;; Fontify all type specifiers.
|
|
2296 (cons (concat "\\<\\(" c-type-types "\\)\\>") 'font-lock-type-face)
|
|
2297 ;;
|
|
2298 ;; Fontify all builtin keywords (except case, default and goto; see below).
|
|
2299 (cons (concat "\\<\\(" c-keywords "\\)\\>") 'font-lock-keyword-face)
|
|
2300 ;;
|
|
2301 ;; Fontify case/goto keywords and targets, and case default/goto tags.
|
|
2302 '("\\<\\(case\\|goto\\)\\>[ \t]*\\([^ \t\n:;]+\\)?"
|
|
2303 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
|
|
2304 '("^[ \t]*\\(\\sw+\\)[ \t]*:" 1 font-lock-reference-face)
|
|
2305 )))
|
|
2306
|
|
2307 (setq c-font-lock-keywords-3
|
|
2308 (append c-font-lock-keywords-2
|
|
2309 ;;
|
|
2310 ;; More complicated regexps for more complete highlighting for types.
|
|
2311 ;; We still have to fontify type specifiers individually, as C is so hairy.
|
|
2312 (list
|
|
2313 ;;
|
|
2314 ;; Fontify all storage classes and type specifiers, plus their items.
|
|
2315 (list (concat "\\<\\(" c-type-types "\\)\\>"
|
|
2316 "\\([ \t*&]+\\sw+\\>\\)*")
|
|
2317 ;; Fontify each declaration item.
|
|
2318 '(font-lock-match-c++-style-declaration-item-and-skip-to-next
|
|
2319 ;; Start with point after all type specifiers.
|
|
2320 (goto-char (or (match-beginning 8) (match-end 1)))
|
|
2321 ;; Finish with point after first type specifier.
|
|
2322 (goto-char (match-end 1))
|
|
2323 ;; Fontify as a variable or function name.
|
|
2324 (1 (if (match-beginning 4)
|
|
2325 font-lock-function-name-face
|
|
2326 font-lock-variable-name-face))))
|
|
2327 ;;
|
|
2328 ;; Fontify structures, or typedef names, plus their items.
|
|
2329 '("\\(}\\)[ \t*]*\\sw"
|
|
2330 (font-lock-match-c++-style-declaration-item-and-skip-to-next
|
|
2331 (goto-char (match-end 1)) nil
|
|
2332 (1 (if (match-beginning 4)
|
|
2333 font-lock-function-name-face
|
|
2334 font-lock-variable-name-face))))
|
|
2335 ;;
|
|
2336 ;; Fontify anything at beginning of line as a declaration or definition.
|
|
2337 '("^\\(\\sw+\\)\\>\\([ \t*]+\\sw+\\>\\)*"
|
|
2338 (1 font-lock-type-face)
|
|
2339 (font-lock-match-c++-style-declaration-item-and-skip-to-next
|
|
2340 (goto-char (or (match-beginning 2) (match-end 1))) nil
|
|
2341 (1 (if (match-beginning 4)
|
|
2342 font-lock-function-name-face
|
|
2343 font-lock-variable-name-face))))
|
|
2344 )))
|
|
2345
|
|
2346 (setq c++-font-lock-keywords-1
|
|
2347 (append
|
|
2348 ;;
|
|
2349 ;; The list `c-font-lock-keywords-1' less that for function names.
|
|
2350 ;; the simple function form regexp has been removed. --dmoore
|
|
2351 ;;(cdr c-font-lock-keywords-1)
|
|
2352 c-font-lock-keywords-1
|
|
2353 ;;
|
|
2354 ;; Fontify function name definitions, possibly incorporating class name.
|
|
2355 (list
|
|
2356 '("^\\(\\sw+\\)\\(::\\(\\sw+\\)\\)?[ \t]*("
|
|
2357 (1 (if (match-beginning 2)
|
|
2358 font-lock-type-face
|
|
2359 font-lock-function-name-face))
|
|
2360 (3 (if (match-beginning 2) font-lock-function-name-face) nil t))
|
|
2361 )))
|
|
2362
|
|
2363 (setq c++-font-lock-keywords-2
|
|
2364 (append c++-font-lock-keywords-1
|
|
2365 (list
|
|
2366 ;;
|
|
2367 ;; The list `c-font-lock-keywords-2' for C++ plus operator overloading.
|
|
2368 (cons (concat "\\<\\(" c++-type-types "\\)\\>") 'font-lock-type-face)
|
|
2369 ;;
|
|
2370 ;; Fontify operator function name overloading.
|
|
2371 '("\\<\\(operator\\)\\>[ \t]*\\([][)(><!=+-][][)(><!=+-]?\\)?"
|
|
2372 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t))
|
|
2373 ;;
|
|
2374 ;; Fontify case/goto keywords and targets, and case default/goto tags.
|
|
2375 '("\\<\\(case\\|goto\\)\\>[ \t]*\\([^ \t\n:;]+\\)?"
|
|
2376 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
|
|
2377 '("^[ \t]*\\(\\sw+\\)[ \t]*:[^:]" 1 font-lock-reference-face)
|
|
2378 ;;
|
|
2379 ;; Fontify other builtin keywords.
|
|
2380 (cons (concat "\\<\\(" c++-keywords "\\)\\>") 'font-lock-keyword-face)
|
|
2381 )))
|
|
2382
|
|
2383 (setq c++-font-lock-keywords-3
|
|
2384 (append c++-font-lock-keywords-2
|
|
2385 ;;
|
|
2386 ;; More complicated regexps for more complete highlighting for types.
|
|
2387 (list
|
|
2388 ;;
|
|
2389 ;; Fontify all storage classes and type specifiers, plus their items.
|
|
2390 (list (concat "\\<\\(" c++-type-types "\\)\\>"
|
|
2391 "\\([ \t*&]+\\sw+\\>\\)*")
|
|
2392 ;; Fontify each declaration item.
|
|
2393 '(font-lock-match-c++-style-declaration-item-and-skip-to-next
|
|
2394 ;; Start with point after all type specifiers.
|
|
2395 (goto-char (or (match-beginning 13) (match-end 1)))
|
|
2396 ;; Finish with point after first type specifier.
|
|
2397 (goto-char (match-end 1))
|
|
2398 ;; Fontify as a variable or function name.
|
|
2399 (1 (cond ((match-beginning 2) 'font-lock-type-face)
|
|
2400 ((match-beginning 4) 'font-lock-function-name-face)
|
|
2401 (t 'font-lock-variable-name-face)))
|
|
2402 (3 (if (match-beginning 4)
|
|
2403 'font-lock-function-name-face
|
|
2404 'font-lock-variable-name-face) nil t)))
|
|
2405 ;;
|
|
2406 ;; Fontify structures, or typedef names, plus their items.
|
|
2407 '("\\(}\\)[ \t*]*\\sw"
|
|
2408 (font-lock-match-c++-style-declaration-item-and-skip-to-next
|
|
2409 (goto-char (match-end 1)) nil
|
|
2410 (1 (if (match-beginning 4)
|
|
2411 font-lock-function-name-face
|
|
2412 font-lock-variable-name-face))))
|
|
2413 ;;
|
|
2414 ;; Fontify anything at beginning of line as a declaration or definition.
|
|
2415 '("^\\(\\sw+\\)\\>\\([ \t*]+\\sw+\\>\\)*"
|
|
2416 (1 font-lock-type-face)
|
|
2417 (font-lock-match-c++-style-declaration-item-and-skip-to-next
|
|
2418 (goto-char (or (match-beginning 2) (match-end 1))) nil
|
|
2419 (1 (cond ((match-beginning 2) 'font-lock-type-face)
|
|
2420 ((match-beginning 4) 'font-lock-function-name-face)
|
|
2421 (t 'font-lock-variable-name-face)))
|
|
2422 (3 (if (match-beginning 4)
|
|
2423 'font-lock-function-name-face
|
|
2424 'font-lock-variable-name-face) nil t)))
|
|
2425 )))
|
|
2426 )
|
|
2427
|
|
2428 (defvar c-font-lock-keywords c-font-lock-keywords-1
|
|
2429 "Default expressions to highlight in C mode.")
|
|
2430
|
|
2431 (defvar c++-font-lock-keywords c++-font-lock-keywords-1
|
|
2432 "Default expressions to highlight in C++ mode.")
|
|
2433
|
|
2434 ;;; Java.
|
|
2435
|
|
2436 ;; Java support has been written by XEmacs people, and it's apparently
|
|
2437 ;; totally divergent from the FSF. I don't know if it's better or
|
|
2438 ;; worse, so I'm leaving it in until someone convinces me the FSF
|
|
2439 ;; version is better. --hniksic
|
|
2440
|
|
2441 (defconst java-font-lock-keywords-1 nil
|
|
2442 "For consideration as a value of `java-font-lock-keywords'.
|
|
2443 This does fairly subdued highlighting.")
|
|
2444
|
|
2445 (defconst java-font-lock-keywords-2 nil
|
|
2446 "For consideration as a value of `java-font-lock-keywords'.
|
|
2447 This adds highlighting of types and identifier names.")
|
|
2448
|
|
2449 (defconst java-font-lock-keywords-3 nil
|
|
2450 "For consideration as a value of `java-font-lock-keywords'.
|
|
2451 This adds highlighting of Java documentation tags, such as @see.")
|
|
2452
|
|
2453 (defvar java-font-lock-type-regexp
|
|
2454 (concat "\\<\\(boolean\\|byte\\|char\\|double\\|float\\|int"
|
|
2455 "\\|long\\|short\\|void\\)\\>")
|
|
2456 "Regexp which should match a primitive type.")
|
|
2457
|
|
2458 (defvar java-font-lock-identifier-regexp
|
442
|
2459 (let ((letter "a-zA-Z_$\300-\326\330-\366\370-\377")
|
|
2460 (digit "0-9"))
|
|
2461 (concat "\\<\\([" letter "][" letter digit "]*\\)\\>"))
|
428
|
2462 "Regexp which should match all Java identifiers.")
|
|
2463
|
|
2464 (defvar java-font-lock-class-name-regexp
|
442
|
2465 (let ((capital-letter "A-Z\300-\326\330-\337")
|
|
2466 (letter "a-zA-Z_$\300-\326\330-\366\370-\377")
|
|
2467 (digit "0-9"))
|
|
2468 (concat "\\<\\([" capital-letter "][" letter digit "]*\\)\\>"))
|
428
|
2469 "Regexp which should match a class or an interface name.
|
|
2470 The name is assumed to begin with a capital letter.")
|
|
2471
|
|
2472 (let ((java-modifier-regexp
|
|
2473 (concat "\\<\\(abstract\\|const\\|final\\|native\\|"
|
|
2474 "private\\|protected\\|public\\|"
|
|
2475 "static\\|synchronized\\|transient\\|volatile\\)\\>")))
|
|
2476
|
|
2477 ;; Basic font-lock support:
|
|
2478 (setq java-font-lock-keywords-1
|
|
2479 (list
|
|
2480 ;; Keywords:
|
|
2481 (list
|
|
2482 (concat
|
|
2483 "\\<\\("
|
|
2484 "break\\|byvalue\\|"
|
|
2485 "case\\|cast\\|catch\\|class\\|continue\\|"
|
|
2486 "do\\|else\\|extends\\|"
|
|
2487 "finally\\|for\\|future\\|"
|
|
2488 "generic\\|goto\\|"
|
|
2489 "if\\|implements\\|import\\|"
|
|
2490 "instanceof\\|interface\\|"
|
|
2491 "new\\|package\\|return\\|switch\\|"
|
|
2492 "throws?\\|try\\|while\\)\\>")
|
|
2493 1 'font-lock-keyword-face)
|
|
2494
|
|
2495 ;; Modifiers:
|
|
2496 (list java-modifier-regexp 1 font-lock-type-face)
|
|
2497
|
|
2498 ;; Special constants:
|
|
2499 '("\\<\\(this\\|super\\)\\>" (1 font-lock-reference-face))
|
|
2500 '("\\<\\(false\\|null\\|true\\)\\>" (1 font-lock-keyword-face))
|
|
2501
|
|
2502 ;; Class names:
|
442
|
2503 (list (concat "\\<\\(class\\|interface\\)\\>\\s *"
|
|
2504 java-font-lock-identifier-regexp)
|
|
2505 2 'font-lock-function-name-face)
|
428
|
2506
|
|
2507 ;; Package declarations:
|
|
2508 (list (concat "\\<\\(package\\|import\\)\\>\\s *"
|
|
2509 java-font-lock-identifier-regexp)
|
|
2510 '(2 font-lock-reference-face)
|
|
2511 (list (concat
|
|
2512 "\\=\\.\\(" java-font-lock-identifier-regexp "\\)")
|
|
2513 nil nil '(1 (if (equal (char-after (match-end 0)) ?.)
|
|
2514 'font-lock-reference-face
|
|
2515 'font-lock-type-face))))
|
|
2516
|
|
2517 ;; Constructors:
|
|
2518 (list (concat
|
|
2519 "^\\s *\\(" java-modifier-regexp "\\s +\\)*"
|
|
2520 java-font-lock-class-name-regexp "\\s *\(")
|
|
2521 (list 3
|
|
2522 '(condition-case nil
|
|
2523 (save-excursion
|
|
2524 (goto-char (scan-sexps (- (match-end 0) 1) 1))
|
|
2525 (parse-partial-sexp (point) (point-max) nil t)
|
|
2526 (and (looking-at "\\($\\|\\<throws\\>\\|{\\)")
|
|
2527 'font-lock-function-name-face))
|
|
2528 (error 'font-lock-function-name-face))))
|
|
2529
|
|
2530 ;; Methods:
|
|
2531 (list (concat "\\(" java-font-lock-type-regexp "\\|"
|
|
2532 java-font-lock-class-name-regexp "\\)"
|
|
2533 "\\s *\\(\\[\\s *\\]\\s *\\)*"
|
|
2534 java-font-lock-identifier-regexp "\\s *\(")
|
|
2535 5
|
|
2536 'font-lock-function-name-face)
|
|
2537
|
|
2538 ;; Labels:
|
|
2539 (list ":"
|
|
2540 (list
|
|
2541 (concat "^\\s *" java-font-lock-identifier-regexp "\\s *:")
|
|
2542 '(beginning-of-line) '(end-of-line)
|
|
2543 '(1 font-lock-reference-face)))
|
|
2544
|
|
2545 ;; `break' and continue' destination labels:
|
|
2546 (list (concat "\\<\\(break\\|continue\\)\\>\\s *"
|
|
2547 java-font-lock-identifier-regexp)
|
|
2548 2 'font-lock-reference-face)
|
|
2549
|
|
2550 ;; Case statements:
|
|
2551 ;; In Java, any constant expression is allowed.
|
|
2552 '("\\<case\\>\\s *\\(.*\\):" 1 font-lock-reference-face)))
|
|
2553
|
|
2554 ;; Types and declared variable names:
|
|
2555 (setq java-font-lock-keywords-2
|
|
2556 (append
|
|
2557
|
|
2558 java-font-lock-keywords-1
|
|
2559 (list
|
|
2560 ;; Keywords followed by a type:
|
|
2561 (list (concat "\\<\\(extends\\|instanceof\\|new\\)\\>\\s *"
|
|
2562 java-font-lock-identifier-regexp)
|
|
2563 '(2 (if (equal (char-after (match-end 0)) ?.)
|
|
2564 'font-lock-reference-face 'font-lock-type-face))
|
|
2565 (list (concat "\\=\\." java-font-lock-identifier-regexp)
|
|
2566 '(goto-char (match-end 0)) nil
|
|
2567 '(1 (if (equal (char-after (match-end 0)) ?.)
|
|
2568 'font-lock-reference-face 'font-lock-type-face))))
|
|
2569
|
|
2570 ;; Keywords followed by a type list:
|
|
2571 (list (concat "\\<\\(implements\\|throws\\)\\>\\ s*"
|
|
2572 java-font-lock-identifier-regexp)
|
|
2573 '(2 (if (equal (char-after (match-end 0)) ?.)
|
|
2574 font-lock-reference-face font-lock-type-face))
|
|
2575 (list (concat "\\=\\(\\.\\|\\s *\\(,\\)\\s *\\)"
|
|
2576 java-font-lock-identifier-regexp)
|
|
2577 '(goto-char (match-end 0)) nil
|
|
2578 '(3 (if (equal (char-after (match-end 0)) ?.)
|
|
2579 font-lock-reference-face font-lock-type-face))))
|
|
2580
|
|
2581 ;; primitive types, can't be confused with anything else.
|
|
2582 (list java-font-lock-type-regexp
|
|
2583 '(1 font-lock-type-face)
|
|
2584 '(font-lock-match-java-declarations
|
|
2585 (goto-char (match-end 0))
|
|
2586 (goto-char (match-end 0))
|
|
2587 (0 font-lock-variable-name-face)))
|
|
2588
|
|
2589 ;; Declarations, class types and capitalized variables:
|
|
2590 ;;
|
|
2591 ;; Declarations are easy to recognize. Capitalized words
|
|
2592 ;; followed by a closing parenthesis are treated as casts if they
|
|
2593 ;; also are followed by an expression. Expressions beginning with
|
|
2594 ;; a unary numerical operator, e.g. +, can't be cast to an object
|
|
2595 ;; type.
|
|
2596 ;;
|
|
2597 ;; The path of a fully qualified type, e.g. java.lang.Foo, is
|
|
2598 ;; fontified in the reference face.
|
|
2599 ;;
|
|
2600 ;; An access to a static field, e.g. System.out.println, is
|
|
2601 ;; not fontified since it can't be distinguished from the
|
|
2602 ;; usage of a capitalized variable, e.g. Foo.out.println.
|
|
2603
|
|
2604 (list (concat java-font-lock-class-name-regexp
|
|
2605 "\\s *\\(\\[\\s *\\]\\s *\\)*"
|
|
2606 "\\(\\<\\|$\\|)\\s *\\([\(\"]\\|\\<\\)\\)")
|
|
2607 '(1 (save-match-data
|
|
2608 (save-excursion
|
|
2609 (goto-char
|
|
2610 (match-beginning 3))
|
|
2611 (if (not (looking-at "\\<instanceof\\>"))
|
|
2612 'font-lock-type-face))))
|
|
2613 (list (concat "\\=" java-font-lock-identifier-regexp "\\.")
|
|
2614 '(progn
|
|
2615 (goto-char (match-beginning 0))
|
|
2616 (while (or (= (preceding-char) ?.)
|
|
2617 (= (char-syntax (preceding-char)) ?w))
|
|
2618 (backward-char)))
|
|
2619 '(goto-char (match-end 0))
|
|
2620 '(1 font-lock-reference-face)
|
|
2621 '(0 nil)) ; Workaround for bug in XEmacs.
|
|
2622 '(font-lock-match-java-declarations
|
|
2623 (goto-char (match-end 1))
|
|
2624 (goto-char (match-end 0))
|
|
2625 (1 font-lock-variable-name-face))))))
|
|
2626
|
|
2627 ;; Modifier keywords and Java doc tags
|
|
2628 (setq java-font-lock-keywords-3
|
|
2629 (append
|
|
2630
|
|
2631 '(
|
|
2632 ;; Feature scoping:
|
|
2633 ;; These must come first or the Modifiers from keywords-1 will
|
|
2634 ;; catch them. We don't want to use override fontification here
|
|
2635 ;; because then these terms will be fontified within comments.
|
|
2636 ("\\<private\\>" 0 font-lock-string-face)
|
|
2637 ("\\<protected\\>" 0 font-lock-preprocessor-face)
|
|
2638 ("\\<public\\>" 0 font-lock-reference-face))
|
|
2639 java-font-lock-keywords-2
|
|
2640
|
|
2641 (list
|
|
2642
|
442
|
2643 ;; Javadoc tags
|
|
2644 '("@\\(author\\|deprecated\\|exception\\|throws\\|param\\|return\\|see\\|since\\|version\\|serial\\|serialData\\|serialField\\)\\s "
|
428
|
2645 0 font-lock-keyword-face t)
|
|
2646
|
|
2647 ;; Doc tag - Parameter identifiers
|
|
2648 (list (concat "@param\\s +" java-font-lock-identifier-regexp)
|
|
2649 1 'font-lock-variable-name-face t)
|
|
2650
|
|
2651 ;; Doc tag - Exception types
|
442
|
2652 (list (concat "@\\(exception\\|throws\\)\\s +"
|
428
|
2653 java-font-lock-identifier-regexp)
|
442
|
2654 '(2 (if (equal (char-after (match-end 0)) ?.)
|
428
|
2655 font-lock-reference-face font-lock-type-face) t)
|
|
2656 (list (concat "\\=\\." java-font-lock-identifier-regexp)
|
|
2657 '(goto-char (match-end 0)) nil
|
|
2658 '(1 (if (equal (char-after (match-end 0)) ?.)
|
|
2659 'font-lock-reference-face 'font-lock-type-face) t)))
|
|
2660
|
|
2661 ;; Doc tag - Cross-references, usually to methods
|
|
2662 '("@see\\s +\\(\\S *[^][ \t\n\r\f(){},.;:]\\)"
|
|
2663 1 font-lock-function-name-face t)
|
|
2664
|
442
|
2665 ;; Doc tag - docRoot (1.3)
|
|
2666 '("\\({ *@docRoot *}\\)"
|
|
2667 0 font-lock-keyword-face t)
|
|
2668 ;; Doc tag - beaninfo, unofficial but widely used, even by Sun
|
|
2669 '("\\(@beaninfo\\)"
|
428
|
2670 0 font-lock-keyword-face t)
|
|
2671 ;; Doc tag - Links
|
442
|
2672 '("{ *@link\\s +\\([^}]+\\)}"
|
|
2673 0 font-lock-keyword-face t)
|
|
2674 ;; Doc tag - Links
|
|
2675 '("{ *@link\\s +\\(\\(\\S +\\)\\|\\(\\S +\\s +\\S +\\)\\) *}"
|
428
|
2676 1 font-lock-function-name-face t)
|
|
2677
|
|
2678 )))
|
|
2679 )
|
|
2680
|
|
2681 (defvar java-font-lock-keywords java-font-lock-keywords-1
|
|
2682 "Additional expressions to highlight in Java mode.")
|
|
2683
|
|
2684 ;; Match and move over any declaration/definition item after
|
|
2685 ;; point. Does not match items which look like a type declaration
|
|
2686 ;; (primitive types and class names, i.e. capitalized words.)
|
|
2687 ;; Should the variable name be followed by a comma, we reposition
|
|
2688 ;; the cursor to fontify more identifiers.
|
|
2689 (defun font-lock-match-java-declarations (limit)
|
|
2690 "Match and skip over variable definitions."
|
|
2691 (if (looking-at "\\s *\\(\\[\\s *\\]\\s *\\)*")
|
|
2692 (goto-char (match-end 0)))
|
|
2693 (and
|
|
2694 (looking-at java-font-lock-identifier-regexp)
|
|
2695 (save-match-data
|
|
2696 (not (string-match java-font-lock-type-regexp
|
|
2697 (buffer-substring (match-beginning 1)
|
|
2698 (match-end 1)))))
|
|
2699 (save-match-data
|
|
2700 (save-excursion
|
|
2701 (goto-char (match-beginning 1))
|
|
2702 (not (looking-at
|
|
2703 (concat java-font-lock-class-name-regexp
|
|
2704 "\\s *\\(\\[\\s *\\]\\s *\\)*\\<")))))
|
|
2705 (save-match-data
|
|
2706 (condition-case nil
|
|
2707 (save-restriction
|
|
2708 (narrow-to-region (point-min) limit)
|
|
2709 (goto-char (match-end 0))
|
|
2710 ;; Note: Both `scan-sexps' and the second goto-char can
|
|
2711 ;; generate an error which is caught by the
|
|
2712 ;; `condition-case' expression.
|
|
2713 (while (not (looking-at "\\s *\\(\\(,\\)\\|;\\|$\\)"))
|
|
2714 (goto-char (or (scan-sexps (point) 1) (point-max))))
|
|
2715 (goto-char (match-end 2))) ; non-nil
|
|
2716 (error t)))))
|
|
2717
|
|
2718
|
|
2719 (defvar tex-font-lock-keywords
|
|
2720 ; ;; Regexps updated with help from Ulrik Dickow <dickow@nbi.dk>.
|
|
2721 ; '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
|
|
2722 ; 2 font-lock-function-name-face)
|
|
2723 ; ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
|
|
2724 ; 2 font-lock-reference-face)
|
|
2725 ; ;; It seems a bit dubious to use `bold' and `italic' faces since we might
|
|
2726 ; ;; not be able to display those fonts.
|
|
2727 ; ("{\\\\bf\\([^}]+\\)}" 1 'bold keep)
|
|
2728 ; ("{\\\\\\(em\\|it\\|sl\\)\\([^}]+\\)}" 2 'italic keep)
|
|
2729 ; ("\\\\\\([a-zA-Z@]+\\|.\\)" . font-lock-keyword-face)
|
|
2730 ; ("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face keep))
|
|
2731 ;; Rewritten and extended for LaTeX2e by Ulrik Dickow <dickow@nbi.dk>.
|
|
2732 '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
|
|
2733 2 font-lock-function-name-face)
|
|
2734 ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
|
|
2735 2 font-lock-reference-face)
|
|
2736 ("^[ \t]*\\\\def\\\\\\(\\(\\w\\|@\\)+\\)" 1 font-lock-function-name-face)
|
|
2737 "\\\\\\([a-zA-Z@]+\\|.\\)"
|
|
2738 ;; It seems a bit dubious to use `bold' and `italic' faces since we might
|
|
2739 ;; not be able to display those fonts.
|
|
2740 ;; LaTeX2e: \emph{This is emphasized}.
|
|
2741 ("\\\\emph{\\([^}]+\\)}" 1 'italic keep)
|
|
2742 ;; LaTeX2e: \textbf{This is bold}, \textit{...}, \textsl{...}
|
|
2743 ("\\\\text\\(\\(bf\\)\\|it\\|sl\\){\\([^}]+\\)}"
|
|
2744 3 (if (match-beginning 2) 'bold 'italic) keep)
|
|
2745 ;; Old-style bf/em/it/sl. Stop at `\\' and un-escaped `&', for good tables.
|
|
2746 ("\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)"
|
|
2747 3 (if (match-beginning 2) 'bold 'italic) keep))
|
|
2748 "Default expressions to highlight in TeX modes.")
|
|
2749
|
444
|
2750 (defconst ksh-font-lock-keywords
|
428
|
2751 (list
|
|
2752 '("\\(^\\|[^\$\\\]\\)#.*" . font-lock-comment-face)
|
|
2753 '("\\<\\(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)
|
|
2754 '("\\<\\[\\[.*\\]\\]\\>" . font-lock-type-face)
|
|
2755 '("\$\(.*\)" . font-lock-type-face)
|
444
|
2756 )
|
428
|
2757 "Additional expressions to highlight in ksh-mode.")
|
|
2758
|
444
|
2759 (defconst sh-font-lock-keywords
|
428
|
2760 (list
|
|
2761 '("\\(^\\|[^\$\\\]\\)#.*" . font-lock-comment-face)
|
|
2762 '("\\<\\(if\\|then\\|else\\|elif\\|fi\\|case\\|esac\\|for\\|do\\|done\\|in\\|while\\|exec\\|export\\|set\\|echo\\|eval\\|cd\\)\\>" . font-lock-keyword-face)
|
|
2763 '("\\[.*\\]" . font-lock-type-face)
|
|
2764 '("`.*`" . font-lock-type-face)
|
444
|
2765 )
|
428
|
2766 "Additional expressions to highlight in sh-mode.")
|
|
2767
|
|
2768
|
|
2769 ;; Install ourselves:
|
|
2770
|
|
2771 (add-hook 'find-file-hooks 'font-lock-set-defaults t)
|
|
2772
|
|
2773 ;;;###autoload
|
692
|
2774 (add-minor-mode 'font-lock-mode 'font-lock-mode-line-string)
|
428
|
2775
|
|
2776 ;; Provide ourselves:
|
|
2777
|
|
2778 (provide 'font-lock)
|
|
2779
|
|
2780 ;;; font-lock.el ends here
|