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