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