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