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.
|
30
|
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
|
|
29 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
10
|
30 ;; Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
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
|
10
|
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
|
10
|
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 ...)
|
30
|
267 (eval . FORM)
|
0
|
268
|
|
269 where HIGHLIGHT should be either MATCH-HIGHLIGHT or MATCH-ANCHORED.
|
|
270
|
30
|
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.
|
30
|
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
|
26
|
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
|
30
|
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)
|
30
|
565 (setq font-lock-defaults-computed nil
|
|
566 font-lock-keywords nil)
|
16
|
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 ()
|
38
|
773 (condition-case nil
|
|
774 (if font-lock-old-extent
|
|
775 (font-lock-fontify-glumped-region))
|
|
776 (error (warn "Error caught in `font-lock-pre-idle-hook'"))))
|
0
|
777
|
|
778 (defvar font-lock-always-fontify-immediately nil
|
|
779 "Set this to non-nil to disable font-lock deferral.")
|
|
780
|
|
781 ;;; called when any modification is made to buffer text. This function
|
|
782 ;;; attempts to glump adjacent changes together so that excessive
|
|
783 ;;; fontification is avoided. This function could easily be adapted
|
|
784 ;;; to other after-change-functions.
|
|
785
|
|
786 (defun font-lock-after-change-function (beg end old-len)
|
|
787 (let ((obeg (and font-lock-old-extent
|
|
788 (extent-start-position font-lock-old-extent)))
|
|
789 (oend (and font-lock-old-extent
|
|
790 (extent-end-position font-lock-old-extent)))
|
|
791 (bc-end (+ beg old-len)))
|
|
792
|
|
793 ;; If this change can't be merged into the glumped one,
|
|
794 ;; we need to fontify the glumped one right now.
|
|
795 (if (and font-lock-old-extent
|
|
796 (or (not (eq (current-buffer)
|
|
797 (extent-object font-lock-old-extent)))
|
|
798 (< bc-end obeg)
|
|
799 (> beg oend)))
|
|
800 (font-lock-fontify-glumped-region))
|
|
801
|
|
802 (if font-lock-old-extent
|
|
803 ;; Update glumped region.
|
|
804 (progn
|
|
805 ;; Any characters in the before-change region that are
|
|
806 ;; outside the glumped region go into the glumped
|
|
807 ;; before-change region.
|
|
808 (if (> bc-end oend)
|
|
809 (setq font-lock-old-len (+ font-lock-old-len (- bc-end oend))))
|
|
810 (if (> obeg beg)
|
|
811 (setq font-lock-old-len (+ font-lock-old-len (- obeg beg))))
|
|
812 ;; New glumped region is the union of the glumped region
|
|
813 ;; and the new region.
|
|
814 (set-extent-endpoints font-lock-old-extent
|
|
815 (min obeg beg)
|
|
816 (max oend end)))
|
|
817
|
|
818 ;; No glumped region, so create one.
|
|
819 (setq font-lock-old-extent (make-extent beg end))
|
|
820 (set-extent-property font-lock-old-extent 'detachable nil)
|
|
821 (set-extent-property font-lock-old-extent 'end-open nil)
|
|
822 (setq font-lock-old-len old-len))
|
|
823
|
|
824 (if font-lock-always-fontify-immediately
|
|
825 (font-lock-fontify-glumped-region))))
|
|
826
|
|
827 (defun font-lock-after-change-function-1 (beg end old-len)
|
|
828 (if (null font-lock-mode)
|
|
829 nil
|
|
830 (save-excursion
|
|
831 (save-restriction
|
|
832 ;; if we don't widen, then fill-paragraph (and any command that
|
|
833 ;; operates on a narrowed region) confuses things, because the C
|
|
834 ;; code will fail to realize that we're inside a comment.
|
|
835 (widen)
|
|
836 (save-match-data
|
|
837 (let ((zmacs-region-stays zmacs-region-stays)) ; protect from change!
|
|
838 (goto-char beg)
|
|
839 ;; Maybe flush the internal cache used by syntactically-sectionize.
|
|
840 ;; (It'd be nice if this was more automatic.) Any deletions mean
|
|
841 ;; the cache is invalid, and insertions at beginning or end of line
|
|
842 ;; mean that the bol cache might be invalid.
|
|
843 ;; (if (or (> old-len 0) (bobp) (= (preceding-char) ?\n))
|
|
844 ;; (buffer-syntactic-context-flush-cache))
|
|
845
|
|
846 ;; Always recompute the whole line.
|
|
847 (goto-char end)
|
|
848 (forward-line 1)
|
|
849 (setq end (point))
|
|
850 (goto-char beg)
|
|
851 (beginning-of-line)
|
|
852 (setq beg (point))
|
|
853 ;; Rescan between start of line from `beg' and start of line after
|
|
854 ;; `end'.
|
|
855 (font-lock-fontify-region beg end)))))))
|
|
856
|
|
857
|
|
858 ;; Syntactic fontification functions.
|
|
859
|
|
860 ;; Note: Here is the FSF version. Our version is much faster because
|
|
861 ;; of the C support we provide. This may be useful for reference,
|
|
862 ;; however, and perhaps there is something useful here that should
|
|
863 ;; be merged into our version.
|
|
864 ;;
|
|
865 ;(defun font-lock-fontify-syntactically-region (start end &optional loudly)
|
|
866 ; "Put proper face on each string and comment between START and END.
|
|
867 ;START should be at the beginning of a line."
|
|
868 ; (let ((synstart (if comment-start-skip
|
|
869 ; (concat "\\s\"\\|" comment-start-skip)
|
|
870 ; "\\s\""))
|
|
871 ; (comstart (if comment-start-skip
|
|
872 ; (concat "\\s<\\|" comment-start-skip)
|
|
873 ; "\\s<"))
|
|
874 ; state prev prevstate)
|
|
875 ; (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name)))
|
|
876 ; (save-restriction
|
|
877 ; (widen)
|
|
878 ; (goto-char start)
|
|
879 ; ;;
|
|
880 ; ;; Find the state at the `beginning-of-line' before `start'.
|
|
881 ; (if (eq start font-lock-cache-position)
|
|
882 ; ;; Use the cache for the state of `start'.
|
|
883 ; (setq state font-lock-cache-state)
|
|
884 ; ;; Find the state of `start'.
|
|
885 ; (if (null font-lock-beginning-of-syntax-function)
|
|
886 ; ;; Use the state at the previous cache position, if any, or
|
|
887 ; ;; otherwise calculate from `point-min'.
|
|
888 ; (if (or (null font-lock-cache-position)
|
|
889 ; (< start font-lock-cache-position))
|
|
890 ; (setq state (parse-partial-sexp (point-min) start))
|
|
891 ; (setq state (parse-partial-sexp font-lock-cache-position start
|
|
892 ; nil nil font-lock-cache-state)))
|
|
893 ; ;; Call the function to move outside any syntactic block.
|
|
894 ; (funcall font-lock-beginning-of-syntax-function)
|
|
895 ; (setq state (parse-partial-sexp (point) start)))
|
|
896 ; ;; Cache the state and position of `start'.
|
|
897 ; (setq font-lock-cache-state state
|
|
898 ; font-lock-cache-position start))
|
|
899 ; ;;
|
|
900 ; ;; If the region starts inside a string, show the extent of it.
|
|
901 ; (if (nth 3 state)
|
|
902 ; (let ((beg (point)))
|
|
903 ; (while (and (re-search-forward "\\s\"" end 'move)
|
|
904 ; (nth 3 (parse-partial-sexp beg (point)
|
|
905 ; nil nil state))))
|
|
906 ; (put-text-property beg (point) 'face font-lock-string-face)
|
|
907 ; (setq state (parse-partial-sexp beg (point) nil nil state))))
|
|
908 ; ;;
|
|
909 ; ;; Likewise for a comment.
|
|
910 ; (if (or (nth 4 state) (nth 7 state))
|
|
911 ; (let ((beg (point)))
|
|
912 ; (save-restriction
|
|
913 ; (narrow-to-region (point-min) end)
|
|
914 ; (condition-case nil
|
|
915 ; (progn
|
|
916 ; (re-search-backward comstart (point-min) 'move)
|
|
917 ; (forward-comment 1)
|
|
918 ; ;; forward-comment skips all whitespace,
|
|
919 ; ;; so go back to the real end of the comment.
|
|
920 ; (skip-chars-backward " \t"))
|
|
921 ; (error (goto-char end))))
|
|
922 ; (put-text-property beg (point) 'face font-lock-comment-face)
|
|
923 ; (setq state (parse-partial-sexp beg (point) nil nil state))))
|
|
924 ; ;;
|
|
925 ; ;; Find each interesting place between here and `end'.
|
|
926 ; (while (and (< (point) end)
|
|
927 ; (setq prev (point) prevstate state)
|
|
928 ; (re-search-forward synstart end t)
|
|
929 ; (progn
|
|
930 ; ;; Clear out the fonts of what we skip over.
|
|
931 ; (remove-text-properties prev (point) '(face nil))
|
|
932 ; ;; Verify the state at that place
|
|
933 ; ;; so we don't get fooled by \" or \;.
|
|
934 ; (setq state (parse-partial-sexp prev (point)
|
|
935 ; nil nil state))))
|
|
936 ; (let ((here (point)))
|
|
937 ; (if (or (nth 4 state) (nth 7 state))
|
|
938 ; ;;
|
|
939 ; ;; We found a real comment start.
|
|
940 ; (let ((beg (match-beginning 0)))
|
|
941 ; (goto-char beg)
|
|
942 ; (save-restriction
|
|
943 ; (narrow-to-region (point-min) end)
|
|
944 ; (condition-case nil
|
|
945 ; (progn
|
|
946 ; (forward-comment 1)
|
|
947 ; ;; forward-comment skips all whitespace,
|
|
948 ; ;; so go back to the real end of the comment.
|
|
949 ; (skip-chars-backward " \t"))
|
|
950 ; (error (goto-char end))))
|
|
951 ; (put-text-property beg (point) 'face
|
|
952 ; font-lock-comment-face)
|
|
953 ; (setq state (parse-partial-sexp here (point) nil nil state)))
|
|
954 ; (if (nth 3 state)
|
|
955 ; ;;
|
|
956 ; ;; We found a real string start.
|
|
957 ; (let ((beg (match-beginning 0)))
|
|
958 ; (while (and (re-search-forward "\\s\"" end 'move)
|
|
959 ; (nth 3 (parse-partial-sexp here (point)
|
|
960 ; nil nil state))))
|
|
961 ; (put-text-property beg (point) 'face font-lock-string-face)
|
|
962 ; (setq state (parse-partial-sexp here (point)
|
|
963 ; nil nil state))))))
|
|
964 ; ;;
|
|
965 ; ;; Make sure `prev' is non-nil after the loop
|
|
966 ; ;; only if it was set on the very last iteration.
|
|
967 ; (setq prev nil)))
|
|
968 ; ;;
|
|
969 ; ;; Clean up.
|
|
970 ; (and prev (remove-text-properties prev end '(face nil)))))
|
|
971
|
|
972 (defun font-lock-fontify-syntactically-region (start end &optional loudly)
|
|
973 "Put proper face on each string and comment between START and END.
|
|
974 START should be at the beginning of a line."
|
|
975 (if font-lock-keywords-only
|
|
976 nil
|
|
977 (if (and font-lock-verbose
|
|
978 (>= (- end start) font-lock-message-threshold))
|
|
979 (message "Fontifying %s... (syntactically...)" (buffer-name)))
|
|
980 (font-lock-unfontify-region start end loudly)
|
|
981 (goto-char start)
|
|
982 (if (> end (point-max)) (setq end (point-max)))
|
|
983 (syntactically-sectionize
|
|
984 #'(lambda (s e context depth)
|
|
985 (let (face)
|
|
986 (cond ((eq context 'string)
|
|
987 ;;#### Should only do this is Lisp-like modes!
|
|
988 (setq face
|
|
989 (if (= depth 1)
|
|
990 ;; really we should only use this if
|
|
991 ;; in position 3 depth 1, but that's
|
|
992 ;; too expensive to compute.
|
|
993 'font-lock-doc-string-face
|
|
994 'font-lock-string-face)))
|
|
995 ((or (eq context 'comment)
|
|
996 (eq context 'block-comment))
|
|
997 (setq face 'font-lock-comment-face)
|
|
998 ; ;; Don't fontify whitespace at the beginning of lines;
|
|
999 ; ;; otherwise comment blocks may not line up with code.
|
|
1000 ; ;; (This is sometimes a good idea, sometimes not; in any
|
|
1001 ; ;; event it should be in C for speed --jwz)
|
|
1002 ; (save-excursion
|
|
1003 ; (goto-char s)
|
|
1004 ; (while (prog1 (search-forward "\n" (1- e) 'move)
|
|
1005 ; (setq face 'font-lock-comment-face)
|
|
1006 ; (setq e (point)))
|
|
1007 ; (skip-chars-forward " \t\n")
|
|
1008 ; (setq s (point)))
|
|
1009 ))
|
|
1010 (font-lock-set-face s e face)))
|
|
1011 start end)
|
|
1012 ))
|
|
1013
|
|
1014 ;;; Additional text property functions.
|
|
1015
|
|
1016 ;; The following three text property functions are not generally available (and
|
|
1017 ;; it's not certain that they should be) so they are inlined for speed.
|
|
1018 ;; The case for `fillin-text-property' is simple; it may or not be generally
|
|
1019 ;; useful. (Since it is used here, it is useful in at least one place.;-)
|
|
1020 ;; However, the case for `append-text-property' and `prepend-text-property' is
|
|
1021 ;; more complicated. Should they remove duplicate property values or not? If
|
|
1022 ;; so, should the first or last duplicate item remain? Or the one that was
|
|
1023 ;; added? In our implementation, the first duplicate remains.
|
|
1024
|
|
1025 ;; XEmacs: modified all these functions to use
|
|
1026 ;; `put-nonduplicable-text-property' instead of `put-text-property', and
|
|
1027 ;; the first one to take both SETPROP and MARKPROP, in accordance with the
|
|
1028 ;; changed definitions of `font-lock-any-faces-p' and `font-lock-set-face'.
|
|
1029
|
|
1030 (defsubst font-lock-fillin-text-property (start end setprop markprop value &optional object)
|
|
1031 "Fill in one property of the text from START to END.
|
|
1032 Arguments PROP and VALUE specify the property and value to put where none are
|
|
1033 already in place. Therefore existing property values are not overwritten.
|
|
1034 Optional argument OBJECT is the string or buffer containing the text."
|
|
1035 (let ((start (text-property-any start end markprop nil object)) next)
|
|
1036 (while start
|
|
1037 (setq next (next-single-property-change start markprop object end))
|
|
1038 (put-nonduplicable-text-property start next setprop value object)
|
|
1039 (put-nonduplicable-text-property start next markprop value object)
|
|
1040 (setq start (text-property-any next end markprop nil object)))))
|
|
1041
|
|
1042 ;; This function (from simon's unique.el) is rewritten and inlined for speed.
|
|
1043 ;(defun unique (list function)
|
|
1044 ; "Uniquify LIST, deleting elements using FUNCTION.
|
|
1045 ;Return the list with subsequent duplicate items removed by side effects.
|
|
1046 ;FUNCTION is called with an element of LIST and a list of elements from LIST,
|
|
1047 ;and should return the list of elements with occurrences of the element removed,
|
|
1048 ;i.e., a function such as `delete' or `delq'.
|
|
1049 ;This function will work even if LIST is unsorted. See also `uniq'."
|
|
1050 ; (let ((list list))
|
|
1051 ; (while list
|
|
1052 ; (setq list (setcdr list (funcall function (car list) (cdr list))))))
|
|
1053 ; list)
|
|
1054
|
|
1055 (defsubst font-lock-unique (list)
|
|
1056 "Uniquify LIST, deleting elements using `delq'.
|
|
1057 Return the list with subsequent duplicate items removed by side effects."
|
|
1058 (let ((list list))
|
|
1059 (while list
|
|
1060 (setq list (setcdr list (delq (car list) (cdr list))))))
|
|
1061 list)
|
|
1062
|
|
1063 ;; A generalisation of `facemenu-add-face' for any property, but without the
|
|
1064 ;; removal of inactive faces via `facemenu-discard-redundant-faces' and special
|
|
1065 ;; treatment of `default'. Uses `unique' to remove duplicate property values.
|
|
1066 (defsubst font-lock-prepend-text-property (start end prop value &optional object)
|
|
1067 "Prepend to one property of the text from START to END.
|
|
1068 Arguments PROP and VALUE specify the property and value to prepend to the value
|
|
1069 already in place. The resulting property values are always lists, and unique.
|
|
1070 Optional argument OBJECT is the string or buffer containing the text."
|
|
1071 (let ((val (if (listp value) value (list value))) next prev)
|
|
1072 (while (/= start end)
|
|
1073 (setq next (next-single-property-change start prop object end)
|
|
1074 prev (get-text-property start prop object))
|
|
1075 (put-text-property
|
|
1076 start next prop
|
|
1077 (font-lock-unique (append val (if (listp prev) prev (list prev))))
|
|
1078 object)
|
|
1079 (setq start next))))
|
|
1080
|
|
1081 (defsubst font-lock-append-text-property (start end prop value &optional object)
|
|
1082 "Append to one property of the text from START to END.
|
|
1083 Arguments PROP and VALUE specify the property and value to append to the value
|
|
1084 already in place. The resulting property values are always lists, and unique.
|
|
1085 Optional argument OBJECT is the string or buffer containing the text."
|
|
1086 (let ((val (if (listp value) value (list value))) next prev)
|
|
1087 (while (/= start end)
|
|
1088 (setq next (next-single-property-change start prop object end)
|
|
1089 prev (get-text-property start prop object))
|
|
1090 (put-text-property
|
|
1091 start next prop
|
|
1092 (font-lock-unique (append (if (listp prev) prev (list prev)) val))
|
|
1093 object)
|
|
1094 (setq start next))))
|
|
1095
|
|
1096 ;;; Regexp fontification functions.
|
|
1097
|
|
1098 (defsubst font-lock-apply-highlight (highlight)
|
|
1099 "Apply HIGHLIGHT following a match.
|
|
1100 HIGHLIGHT should be of the form MATCH-HIGHLIGHT, see `font-lock-keywords'."
|
|
1101 (let* ((match (nth 0 highlight))
|
|
1102 (start (match-beginning match)) (end (match-end match))
|
|
1103 (override (nth 2 highlight)))
|
|
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)
|
20
|
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'.
|
|
1177 (setq highlights (cdr keyword))
|
|
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
|
30
|
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
|
30
|
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)
|
|
1277 ;; older Emacsen.
|
|
1278 (let ((i (1- (length (syntax-table)))))
|
|
1279 (while (>= i 0)
|
|
1280 (if (memq (char-syntax i) '(?\" ?\< ?\> ?\$))
|
|
1281 (setq got-one t i 0))
|
|
1282 (setq i (1- i))))
|
|
1283 (set (make-local-variable 'font-lock-keywords-only) (not got-one)))))
|
|
1284
|
|
1285 ;; font-lock-set-defaults is in fontl-hooks.el.
|
|
1286
|
|
1287 (defun font-lock-set-defaults-1 (&optional explicit-defaults)
|
|
1288 ;; does everything that font-lock-set-defaults does except
|
|
1289 ;; enable font-lock-mode. This is called by `font-lock-mode'.
|
|
1290 ;; Note that the return value is used!
|
|
1291
|
|
1292 (if (and font-lock-defaults-computed (not explicit-defaults))
|
|
1293 ;; nothing to do.
|
|
1294 nil
|
|
1295
|
|
1296 (or font-lock-keywords
|
|
1297 (let* ((defaults (or (and (not (eq t explicit-defaults))
|
|
1298 explicit-defaults)
|
|
1299 ;; in case modes decide to set
|
|
1300 ;; `font-lock-defaults' themselves,
|
|
1301 ;; as in FSF Emacs.
|
|
1302 font-lock-defaults
|
|
1303 (font-lock-find-font-lock-defaults major-mode)))
|
|
1304 (keywords (font-lock-choose-keywords
|
|
1305 (nth 0 defaults) font-lock-maximum-decoration)))
|
|
1306
|
|
1307 ;; Keywords?
|
|
1308 (setq font-lock-keywords (if (fboundp keywords)
|
|
1309 (funcall keywords)
|
|
1310 (eval keywords)))
|
|
1311 (or font-lock-keywords
|
|
1312 ;; older way:
|
|
1313 ;; try to look for a variable `foo-mode-font-lock-keywords',
|
|
1314 ;; or similar.
|
|
1315 (let ((major (symbol-name major-mode))
|
|
1316 (try #'(lambda (n)
|
|
1317 (if (stringp n) (setq n (intern-soft n)))
|
|
1318 (if (and n
|
|
1319 (boundp n))
|
|
1320 n
|
|
1321 nil))))
|
|
1322 (setq font-lock-keywords
|
|
1323 (symbol-value
|
|
1324 (or (funcall try (get major-mode 'font-lock-keywords))
|
|
1325 (funcall try (concat major "-font-lock-keywords"))
|
|
1326 (funcall try (and (string-match "-mode\\'" major)
|
|
1327 (concat (substring
|
|
1328 major 0
|
|
1329 (match-beginning 0))
|
|
1330 "-font-lock-keywords")))
|
|
1331 'font-lock-keywords)))))
|
|
1332
|
|
1333 ;; Case fold?
|
|
1334 (if (>= (length defaults) 3)
|
|
1335 (setq font-lock-keywords-case-fold-search (nth 2 defaults))
|
|
1336 ;; older way:
|
|
1337 ;; look for a property 'font-lock-keywords-case-fold-search on
|
|
1338 ;; the major-mode symbol.
|
|
1339 (let* ((nonexist (make-symbol ""))
|
|
1340 (value (get major-mode 'font-lock-keywords-case-fold-search
|
|
1341 nonexist)))
|
|
1342 (if (not (eq nonexist value))
|
|
1343 (setq font-lock-keywords-case-fold-search value))))
|
|
1344
|
|
1345 ;; Syntactic?
|
|
1346 (if (>= (length defaults) 2)
|
|
1347 (setq font-lock-keywords-only (nth 1 defaults))
|
|
1348 ;; older way:
|
|
1349 ;; cleverly examine the syntax table.
|
|
1350 (font-lock-examine-syntax-table))
|
|
1351
|
|
1352 ;; Syntax table?
|
|
1353 (if (nth 3 defaults)
|
|
1354 (let ((slist (nth 3 defaults)))
|
|
1355 (setq font-lock-syntax-table
|
|
1356 (copy-syntax-table (syntax-table)))
|
|
1357 (while slist
|
|
1358 (modify-syntax-entry (car (car slist)) (cdr (car slist))
|
|
1359 font-lock-syntax-table)
|
|
1360 (setq slist (cdr slist)))))
|
|
1361
|
|
1362 ;; Syntax function?
|
|
1363 (cond (defaults
|
|
1364 (setq font-lock-beginning-of-syntax-function
|
|
1365 (nth 4 defaults)))
|
|
1366 (t
|
|
1367 ;; older way:
|
|
1368 ;; defaults not specified at all, so use `beginning-of-defun'.
|
|
1369 (setq font-lock-beginning-of-syntax-function
|
|
1370 'beginning-of-defun)))))
|
|
1371
|
|
1372 (setq font-lock-defaults-computed t)))
|
|
1373
|
|
1374
|
|
1375 ;;; Initialization of faces.
|
|
1376
|
|
1377 (defconst font-lock-face-list
|
|
1378 '(font-lock-comment-face
|
|
1379 font-lock-doc-string-face
|
|
1380 font-lock-string-face
|
|
1381 font-lock-keyword-face
|
|
1382 font-lock-function-name-face
|
|
1383 font-lock-variable-name-face
|
|
1384 font-lock-type-face
|
|
1385 font-lock-reference-face
|
|
1386 font-lock-preprocessor-face))
|
|
1387
|
|
1388 (defun font-lock-reset-face (face)
|
|
1389 "Reset FACE its default state (from the X resource database).
|
|
1390 Returns whether it is indistinguishable from the default face."
|
|
1391 (reset-face face)
|
|
1392 (init-face-from-resources face)
|
|
1393 (face-differs-from-default-p face))
|
|
1394
|
|
1395 (defun font-lock-reset-all-faces ()
|
|
1396 (mapcar 'font-lock-reset-face font-lock-face-list))
|
|
1397
|
|
1398 (defun font-lock-add-fonts (tag-list)
|
|
1399 ;; Underling comments looks terrible on tty's
|
|
1400 (if (featurep 'tty)
|
|
1401 (progn
|
|
1402 (set-face-underline-p 'font-lock-comment-face nil 'global
|
|
1403 (append '(tty) tag-list) 'append)
|
|
1404 (set-face-highlight-p 'font-lock-comment-face t 'global
|
|
1405 (append '(tty) tag-list) 'append)))
|
|
1406 (set-face-font 'font-lock-comment-face [italic] 'global tag-list 'append)
|
|
1407 (set-face-font 'font-lock-string-face [italic] 'global tag-list 'append)
|
|
1408 (set-face-font 'font-lock-doc-string-face [italic] 'global tag-list 'append)
|
|
1409 (set-face-font 'font-lock-function-name-face [bold] 'global tag-list 'append)
|
|
1410 (set-face-font 'font-lock-variable-name-face [bold] 'global tag-list 'append)
|
|
1411 (set-face-font 'font-lock-keyword-face [bold] 'global tag-list 'append)
|
|
1412 (set-face-font 'font-lock-preprocessor-face [bold-italic] 'global tag-list
|
|
1413 'append)
|
|
1414 (set-face-font 'font-lock-type-face [italic] 'global tag-list 'append)
|
|
1415 (set-face-font 'font-lock-reference-face [bold] 'global tag-list 'append)
|
|
1416 nil)
|
|
1417
|
|
1418 (defun font-lock-add-colors (tag-list)
|
|
1419 (set-face-foreground 'font-lock-comment-face "red" 'global tag-list 'append)
|
|
1420 ;(set-face-font 'font-lock-comment-face [italic] 'global tag-list 'append)
|
|
1421 (set-face-foreground 'font-lock-string-face "green4" 'global tag-list
|
|
1422 'append)
|
|
1423 (set-face-foreground 'font-lock-string-face "green" 'global tag-list
|
|
1424 'append)
|
|
1425 (set-face-foreground 'font-lock-doc-string-face "green4" 'global tag-list
|
|
1426 'append)
|
|
1427 (set-face-foreground 'font-lock-doc-string-face "green" 'global tag-list
|
|
1428 'append)
|
|
1429 (set-face-foreground 'font-lock-function-name-face "blue3" 'global tag-list
|
|
1430 'append)
|
|
1431 (set-face-foreground 'font-lock-function-name-face "blue" 'global tag-list
|
|
1432 'append)
|
|
1433 (set-face-foreground 'font-lock-variable-name-face "blue3" 'global tag-list
|
|
1434 'append)
|
|
1435 (set-face-foreground 'font-lock-variable-name-face "blue" 'global tag-list
|
|
1436 'append)
|
|
1437 (set-face-foreground 'font-lock-reference-face "red3" 'global
|
|
1438 tag-list 'append)
|
|
1439 (set-face-foreground 'font-lock-reference-face "red" 'global tag-list
|
|
1440 'append)
|
|
1441 (set-face-foreground 'font-lock-keyword-face "orange" 'global tag-list
|
|
1442 'append)
|
|
1443 ;(set-face-font 'font-lock-keyword-face [bold] 'global tag-list 'append)
|
|
1444 (set-face-foreground 'font-lock-preprocessor-face "blue3" 'global tag-list
|
|
1445 'append)
|
|
1446 (set-face-foreground 'font-lock-preprocessor-face "blue" 'global tag-list
|
|
1447 'append)
|
|
1448 ;(set-face-font 'font-lock-preprocessor-face [bold] 'global tag-list 'append)
|
|
1449 (set-face-foreground 'font-lock-type-face "#6920ac" 'global tag-list 'append)
|
|
1450 nil)
|
|
1451
|
|
1452 (defun font-lock-apply-defaults (function tag-list)
|
|
1453 (if (and (listp tag-list)
|
|
1454 (eq 'or (car tag-list)))
|
|
1455 (mapcar #'(lambda (x)
|
|
1456 (font-lock-apply-defaults function x))
|
|
1457 (cdr tag-list))
|
|
1458 (if tag-list
|
|
1459 (if (not (valid-specifier-tag-set-p tag-list))
|
|
1460 (warn "Invalid tag set found: %s" tag-list)
|
|
1461 (funcall function tag-list)))))
|
|
1462
|
|
1463 (defun font-lock-recompute-variables ()
|
|
1464 ;; Is this a Draconian thing to do?
|
|
1465 (mapcar #'(lambda (buffer)
|
|
1466 (save-excursion
|
|
1467 (set-buffer buffer)
|
|
1468 (font-lock-mode 0)
|
|
1469 (font-lock-set-defaults t)))
|
|
1470 (buffer-list)))
|
|
1471
|
|
1472 ;; Backwards-compatible crud.
|
|
1473
|
|
1474 (defun font-lock-use-default-fonts ()
|
|
1475 "Reset the font-lock faces to a default set of fonts."
|
|
1476 (interactive)
|
|
1477 (font-lock-reset-all-faces)
|
|
1478 (font-lock-add-fonts nil))
|
|
1479
|
|
1480 (defun font-lock-use-default-colors ()
|
|
1481 "Reset the font-lock faces to a default set of colors."
|
|
1482 (interactive)
|
|
1483 (font-lock-reset-all-faces)
|
|
1484 (font-lock-add-colors nil))
|
|
1485
|
|
1486 (defun font-lock-use-default-minimal-decoration ()
|
|
1487 "Reset the font-lock patterns to a fast, minimal set of decorations."
|
|
1488 (and font-lock-maximum-decoration
|
|
1489 (setq font-lock-maximum-decoration nil)
|
|
1490 (font-lock-recompute-variables)))
|
|
1491
|
|
1492 (defun font-lock-use-default-maximal-decoration ()
|
|
1493 "Reset the font-lock patterns to a larger set of decorations."
|
|
1494 (and (not (eq t font-lock-maximum-decoration))
|
|
1495 (setq font-lock-maximum-decoration t)
|
|
1496 (font-lock-recompute-variables)))
|
|
1497
|
|
1498
|
|
1499 ;;;;;;;;;;;;;;;;;;;;;; keywords ;;;;;;;;;;;;;;;;;;;;;;
|
|
1500
|
|
1501 ;;; Various major-mode interfaces.
|
|
1502 ;;; Probably these should go in with the source of the respective major modes.
|
|
1503
|
|
1504 ;; The defaults and keywords listed here should perhaps be moved into
|
|
1505 ;; mode-specific files.
|
|
1506
|
|
1507 ;; For C and Lisp modes we use `beginning-of-defun', rather than nil,
|
|
1508 ;; for SYNTAX-BEGIN. Thus the calculation of the cache is usually
|
|
1509 ;; faster but not infallible, so we risk mis-fontification. --sm.
|
|
1510
|
|
1511 (put 'c-mode 'font-lock-defaults
|
|
1512 '((c-font-lock-keywords
|
|
1513 c-font-lock-keywords-1 c-font-lock-keywords-2 c-font-lock-keywords-3)
|
|
1514 nil nil ((?_ . "w")) beginning-of-defun))
|
|
1515 (put 'c++-c-mode 'font-lock-defaults 'c-mode)
|
|
1516 (put 'elec-c-mode 'font-lock-defaults 'c-mode)
|
|
1517
|
|
1518 (put 'c++-mode 'font-lock-defaults
|
|
1519 '((c++-font-lock-keywords
|
|
1520 c++-font-lock-keywords-1 c++-font-lock-keywords-2
|
|
1521 c++-font-lock-keywords-3)
|
|
1522 nil nil ((?_ . "w") (?~ . "w")) beginning-of-defun))
|
|
1523
|
|
1524 (put 'java-mode 'font-lock-defaults
|
|
1525 '((java-font-lock-keywords
|
10
|
1526 java-font-lock-keywords-1 java-font-lock-keywords-2
|
|
1527 java-font-lock-keywords-3)
|
|
1528 nil nil ((?_ . "w")) beginning-of-defun
|
|
1529 (font-lock-mark-block-function . mark-defun)))
|
0
|
1530
|
|
1531 (put 'lisp-mode 'font-lock-defaults
|
|
1532 '((lisp-font-lock-keywords
|
|
1533 lisp-font-lock-keywords-1 lisp-font-lock-keywords-2)
|
|
1534 nil nil
|
|
1535 ((?: . "w") (?- . "w") (?* . "w") (?+ . "w") (?. . "w") (?< . "w")
|
|
1536 (?> . "w") (?= . "w") (?! . "w") (?? . "w") (?$ . "w") (?% . "w")
|
|
1537 (?_ . "w") (?& . "w") (?~ . "w") (?^ . "w") (?/ . "w"))
|
|
1538 beginning-of-defun))
|
|
1539 (put 'emacs-lisp-mode 'font-lock-defaults 'lisp-mode)
|
|
1540 (put 'lisp-interaction-mode 'font-lock-defaults 'lisp-mode)
|
|
1541
|
|
1542 (put 'scheme-mode 'font-lock-defaults
|
|
1543 '(scheme-font-lock-keywords
|
|
1544 nil t
|
|
1545 ((?: . "w") (?- . "w") (?* . "w") (?+ . "w") (?. . "w") (?< . "w")
|
|
1546 (?> . "w") (?= . "w") (?! . "w") (?? . "w") (?$ . "w") (?% . "w")
|
|
1547 (?_ . "w") (?& . "w") (?~ . "w") (?^ . "w") (?/ . "w"))
|
|
1548 beginning-of-defun))
|
|
1549 (put 'inferior-scheme-mode 'font-lock-defaults 'scheme-mode)
|
|
1550 (put 'scheme-interaction-mode 'font-lock-defaults 'scheme-mode)
|
|
1551
|
|
1552 (put 'tex-mode 'font-lock-defaults
|
|
1553 ;; For TeX modes we could use `backward-paragraph' for the same reason.
|
|
1554 '(tex-font-lock-keywords nil nil ((?$ . "\""))))
|
|
1555 ;; the nine billion names of TeX mode...
|
|
1556 (put 'bibtex-mode 'font-lock-defaults 'tex-mode)
|
|
1557 (put 'plain-tex-mode 'font-lock-defaults 'tex-mode)
|
|
1558 (put 'slitex-tex-mode 'font-lock-defaults 'tex-mode)
|
|
1559 (put 'SliTeX-mode 'font-lock-defaults 'tex-mode)
|
|
1560 (put 'slitex-mode 'font-lock-defaults 'tex-mode)
|
|
1561 (put 'latex-tex-mode 'font-lock-defaults 'tex-mode)
|
|
1562 (put 'LaTex-tex-mode 'font-lock-defaults 'tex-mode)
|
|
1563 (put 'latex-mode 'font-lock-defaults 'tex-mode)
|
|
1564 (put 'LaTeX-mode 'font-lock-defaults 'tex-mode)
|
|
1565 (put 'japanese-LaTeX-mode 'font-lock-defaults 'tex-mode)
|
|
1566 (put 'japanese-SliTeX-mode 'font-lock-defaults 'tex-mode)
|
|
1567 (put 'FoilTeX-mode 'font-lock-defaults 'tex-mode)
|
|
1568 (put 'LATeX-MoDe 'font-lock-defaults 'tex-mode)
|
|
1569 (put 'lATEx-mODe 'font-lock-defaults 'tex-mode)
|
|
1570 ;; ok, this is getting a bit silly ...
|
|
1571 (put 'eDOm-xETAl 'font-lock-defaults 'tex-mode)
|
|
1572
|
|
1573 ;;; Various regexp information shared by several modes.
|
|
1574 ;;; Information specific to a single mode should go in its load library.
|
|
1575
|
|
1576 (defconst lisp-font-lock-keywords-1
|
|
1577 (list
|
|
1578 ;; Anything not a variable or type declaration is fontified as a function.
|
|
1579 ;; It would be cleaner to allow preceding whitespace, but it would also be
|
|
1580 ;; about five times slower.
|
|
1581 (list (concat "^(\\(def\\("
|
|
1582 ;; Variable declarations.
|
|
1583 "\\(const\\(\\|ant\\)\\|ine-key\\(\\|-after\\)\\|var\\)\\|"
|
|
1584 ;; Structure declarations.
|
|
1585 "\\(class\\|struct\\|type\\)\\|"
|
|
1586 ;; Everything else is a function declaration.
|
|
1587 "\\([^ \t\n\(\)]+\\)"
|
|
1588 "\\)\\)\\>"
|
|
1589 ;; Any whitespace and declared object.
|
|
1590 "[ \t'\(]*"
|
|
1591 "\\([^ \t\n\)]+\\)?")
|
|
1592 '(1 font-lock-keyword-face)
|
|
1593 '(8 (cond ((match-beginning 3) 'font-lock-variable-name-face)
|
|
1594 ((match-beginning 6) 'font-lock-type-face)
|
|
1595 (t 'font-lock-function-name-face))
|
|
1596 nil t))
|
|
1597 )
|
|
1598 "Subdued level highlighting Lisp modes.")
|
|
1599
|
|
1600 (defconst lisp-font-lock-keywords-2
|
|
1601 (append lisp-font-lock-keywords-1
|
|
1602 (list
|
|
1603 ;;
|
|
1604 ;; Control structures. ELisp and CLisp combined.
|
|
1605 ; (make-regexp
|
|
1606 ; '("cond" "if" "while" "let\\*?" "prog[nv12*]?" "catch" "throw"
|
|
1607 ; "save-restriction" "save-excursion" "save-window-excursion"
|
|
1608 ; "save-selected-window" "save-match-data" "unwind-protect"
|
|
1609 ; "condition-case" "track-mouse"
|
|
1610 ; "eval-after-load" "eval-and-compile" "eval-when-compile"
|
|
1611 ; "when" "unless" "do" "flet" "labels" "return" "return-from"))
|
|
1612 (cons
|
|
1613 (concat
|
|
1614 "(\\("
|
|
1615 "\\(c\\(atch\\|ond\\(\\|ition-case\\)\\)\\|do\\|"
|
|
1616 "eval-\\(a\\(fter-load\\|nd-compile\\)\\|when-compile\\)\\|flet\\|"
|
|
1617 "if\\|l\\(abels\\|et\\*?\\)\\|prog[nv12*]?\\|return\\(\\|-from\\)\\|"
|
|
1618 "save-\\(excursion\\|match-data\\|restriction\\|selected-window\\|"
|
|
1619 "window-excursion\\)\\|t\\(hrow\\|rack-mouse\\)\\|"
|
|
1620 "un\\(less\\|wind-protect\\)\\|wh\\(en\\|ile\\)\\)"
|
|
1621 "\\)\\>") 1)
|
|
1622 ;;
|
|
1623 ;; Words inside \\[] tend to be for `substitute-command-keys'.
|
|
1624 '("\\\\\\\\\\[\\(\\sw+\\)]" 1 font-lock-reference-face prepend)
|
|
1625 ;;
|
|
1626 ;; Words inside `' tend to be symbol names.
|
|
1627 '("`\\(\\sw\\sw+\\)'" 1 font-lock-reference-face prepend)
|
|
1628 ;;
|
|
1629 ;; CLisp `:' keywords as references.
|
|
1630 '("\\<:\\sw+\\>" 0 font-lock-reference-face prepend)
|
|
1631 ;;
|
|
1632 ;; ELisp and CLisp `&' keywords as types.
|
|
1633 '("\\<\\&\\(optional\\|rest\\|whole\\)\\>" . font-lock-type-face)
|
|
1634 ))
|
|
1635 "Gaudy level highlighting for Lisp modes.")
|
|
1636
|
|
1637 (defvar lisp-font-lock-keywords lisp-font-lock-keywords-1
|
|
1638 "Default expressions to highlight in Lisp modes.")
|
|
1639
|
|
1640 ;; The previous version, before replacing it with the FSF version.
|
|
1641 ;(defconst lisp-font-lock-keywords-1 (purecopy
|
|
1642 ; '(;;
|
|
1643 ; ;; highlight defining forms. This doesn't work too nicely for
|
|
1644 ; ;; (defun (setf foo) ...) but it does work for (defvar foo) which
|
|
1645 ; ;; is more important.
|
|
1646 ; ("^(def[-a-z]+\\s +\\([^ \t\n\)]+\\)" 1 font-lock-function-name-face)
|
|
1647 ; ;;
|
|
1648 ; ;; highlight CL keywords (three clauses seems faster than one)
|
|
1649 ; ("\\s :\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1)
|
|
1650 ; ("(:\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1)
|
|
1651 ; ("':\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1)
|
|
1652 ; ;;
|
|
1653 ; ;; this is highlights things like (def* (setf foo) (bar baz)), but may
|
|
1654 ; ;; be slower (I haven't really thought about it)
|
|
1655 ;; ("^(def[-a-z]+\\s +\\(\\s(\\S)*\\s)\\|\\S(\\S *\\)"
|
|
1656 ;; 1 font-lock-function-name-face)
|
|
1657 ; ))
|
|
1658 ; "For consideration as a value of `lisp-font-lock-keywords'.
|
|
1659 ;This does fairly subdued highlighting.")
|
|
1660 ;
|
|
1661 ;(defconst lisp-font-lock-keywords-2 (purecopy
|
|
1662 ; (append lisp-font-lock-keywords-1
|
|
1663 ; '(;;
|
|
1664 ; ;; Highlight control structures
|
|
1665 ; ("(\\(cond\\|if\\|when\\|unless\\|[ec]?\\(type\\)?case\\)[ \t\n]" . 1)
|
|
1666 ; ("(\\(while\\|do\\|let\\*?\\|flet\\|labels\\|prog[nv12*]?\\)[ \t\n]" . 1)
|
|
1667 ; ("(\\(do\\*\\|dotimes\\|dolist\\|loop\\)[ \t\n]" . 1)
|
|
1668 ; ("(\\(catch\\|\\throw\\|block\\|return\\|return-from\\)[ \t\n]" . 1)
|
|
1669 ; ("(\\(save-restriction\\|save-window-restriction\\)[ \t\n]" . 1)
|
|
1670 ; ("(\\(save-excursion\\|unwind-protect\\|condition-case\\)[ \t\n]" . 1)
|
|
1671 ; ;;
|
|
1672 ; ;; highlight function names in emacs-lisp docstrings (in the syntax
|
|
1673 ; ;; that substitute-command-keys understands.)
|
|
1674 ; ("\\\\\\\\\\[\\([^]\\\n]+\\)]" 1 font-lock-keyword-face t)
|
|
1675 ; ;;
|
|
1676 ; ;; highlight words inside `' which tend to be function names
|
|
1677 ; ("`\\([-a-zA-Z0-9_][-a-zA-Z0-9_][-a-zA-Z0-9_.]+\\)'"
|
|
1678 ; 1 font-lock-keyword-face t)
|
|
1679 ; )))
|
|
1680 ; "For consideration as a value of `lisp-font-lock-keywords'.
|
|
1681 ;
|
|
1682 ;This does a lot more highlighting.")
|
|
1683
|
|
1684 (defvar scheme-font-lock-keywords
|
|
1685 (eval-when-compile
|
|
1686 (list
|
|
1687 ;;
|
|
1688 ;; Declarations. Hannes Haug <hannes.haug@student.uni-tuebingen.de> says
|
|
1689 ;; this works for SOS, STklos, SCOOPS, Meroon and Tiny CLOS.
|
|
1690 (list (concat "(\\(define\\("
|
|
1691 ;; Function names.
|
|
1692 "\\(\\|-\\(generic\\(\\|-procedure\\)\\|method\\)\\)\\|"
|
|
1693 ;; Macro names, as variable names. A bit dubious, this.
|
|
1694 "\\(-syntax\\)\\|"
|
|
1695 ;; Class names.
|
|
1696 "\\(-class\\)"
|
|
1697 "\\)\\)\\>"
|
|
1698 ;; Any whitespace and declared object.
|
|
1699 "[ \t]*(?"
|
|
1700 "\\(\\sw+\\)?")
|
|
1701 '(1 font-lock-keyword-face)
|
|
1702 '(8 (cond ((match-beginning 3) 'font-lock-function-name-face)
|
|
1703 ((match-beginning 6) 'font-lock-variable-name-face)
|
|
1704 (t 'font-lock-type-face))
|
|
1705 nil t))
|
|
1706 ;;
|
|
1707 ;; Control structures.
|
|
1708 ;(make-regexp '("begin" "call-with-current-continuation" "call/cc"
|
|
1709 ; "call-with-input-file" "call-with-output-file" "case" "cond"
|
|
1710 ; "do" "else" "for-each" "if" "lambda"
|
|
1711 ; "let\\*?" "let-syntax" "letrec" "letrec-syntax"
|
|
1712 ; ;; Hannes Haug <hannes.haug@student.uni-tuebingen.de> wants:
|
|
1713 ; "and" "or" "delay"
|
|
1714 ; ;; Stefan Monnier <stefan.monnier@epfl.ch> says don't bother:
|
|
1715 ; ;;"quasiquote" "quote" "unquote" "unquote-splicing"
|
|
1716 ; "map" "syntax" "syntax-rules"))
|
|
1717 (cons
|
|
1718 (concat "(\\("
|
|
1719 "and\\|begin\\|c\\(a\\(ll\\(-with-\\(current-continuation\\|"
|
|
1720 "input-file\\|output-file\\)\\|/cc\\)\\|se\\)\\|ond\\)\\|"
|
|
1721 "d\\(elay\\|o\\)\\|else\\|for-each\\|if\\|"
|
|
1722 "l\\(ambda\\|et\\(-syntax\\|\\*?\\|rec\\(\\|-syntax\\)\\)\\)\\|"
|
|
1723 "map\\|or\\|syntax\\(\\|-rules\\)"
|
|
1724 "\\)\\>") 1)
|
|
1725 ;;
|
|
1726 ;; David Fox <fox@graphics.cs.nyu.edu> for SOS/STklos class specifiers.
|
|
1727 '("\\<<\\sw+>\\>" . font-lock-type-face)
|
|
1728 ;;
|
|
1729 ;; Scheme `:' keywords as references.
|
|
1730 '("\\<:\\sw+\\>" . font-lock-reference-face)
|
|
1731 ))
|
|
1732 "Default expressions to highlight in Scheme modes.")
|
|
1733
|
|
1734 ;; The previous version, before replacing it with the FSF version.
|
|
1735 ;(defconst scheme-font-lock-keywords (purecopy
|
|
1736 ; '(("(define[ \t]+(?\\([^ \t\n\)]+\\)" 1 font-lock-function-name-face)
|
|
1737 ; ("(\\(cond\\|lambda\\|begin\\|if\\|else\\|case\\|do\\)[ \t\n]" . 1)
|
|
1738 ; ("(\\(\\|letrec\\|let\\*?\\|set!\\|and\\|or\\)[ \t\n]" . 1)
|
|
1739 ; ("(\\(quote\\|unquote\\|quasiquote\\|unquote-splicing\\)[ \t\n]" . 1)
|
|
1740 ; ("(\\(syntax\\|syntax-rules\\|define-syntax\\|let-syntax\\|letrec-syntax\\)[ \t\n]" . 1)))
|
|
1741 ; "Expressions to highlight in Scheme buffers.")
|
|
1742
|
|
1743 (defconst c-font-lock-keywords-1 nil
|
|
1744 "Subdued level highlighting for C modes.")
|
|
1745
|
|
1746 (defconst c-font-lock-keywords-2 nil
|
|
1747 "Medium level highlighting for C modes.")
|
|
1748
|
|
1749 (defconst c-font-lock-keywords-3 nil
|
|
1750 "Gaudy level highlighting for C modes.")
|
|
1751
|
|
1752 (defconst c++-font-lock-keywords-1 nil
|
|
1753 "Subdued level highlighting for C++ modes.")
|
|
1754
|
|
1755 (defconst c++-font-lock-keywords-2 nil
|
|
1756 "Medium level highlighting for C++ modes.")
|
|
1757
|
|
1758 (defconst c++-font-lock-keywords-3 nil
|
|
1759 "Gaudy level highlighting for C++ modes.")
|
|
1760
|
|
1761 (defun font-lock-match-c++-style-declaration-item-and-skip-to-next (limit)
|
|
1762 ;; Match, and move over, any declaration/definition item after point.
|
|
1763 ;; The expect syntax of an item is "word" or "word::word", possibly ending
|
|
1764 ;; with optional whitespace and a "(". Everything following the item (but
|
|
1765 ;; belonging to it) is expected to by skip-able by `forward-sexp', and items
|
|
1766 ;; are expected to be separated with a "," or ";".
|
|
1767 (if (looking-at "[ \t*&]*\\(\\sw+\\)\\(::\\(\\sw+\\)\\)?[ \t]*\\((\\)?")
|
|
1768 (save-match-data
|
|
1769 (condition-case nil
|
|
1770 (save-restriction
|
|
1771 ;; Restrict to the end of line, currently guaranteed to be LIMIT.
|
|
1772 (narrow-to-region (point-min) limit)
|
|
1773 (goto-char (match-end 1))
|
|
1774 ;; Move over any item value, etc., to the next item.
|
|
1775 (while (not (looking-at "[ \t]*\\([,;]\\|$\\)"))
|
|
1776 (goto-char (or (scan-sexps (point) 1) (point-max))))
|
|
1777 (goto-char (match-end 0)))
|
|
1778 (error t)))))
|
|
1779
|
|
1780 (let ((c-keywords
|
|
1781 ; ("break" "continue" "do" "else" "for" "if" "return" "switch" "while")
|
|
1782 "break\\|continue\\|do\\|else\\|for\\|if\\|return\\|switch\\|while")
|
|
1783 (c-type-types
|
|
1784 ; ("auto" "extern" "register" "static" "typedef" "struct" "union" "enum"
|
|
1785 ; "signed" "unsigned" "short" "long" "int" "char" "float" "double"
|
|
1786 ; "void" "volatile" "const")
|
|
1787 (concat "auto\\|c\\(har\\|onst\\)\\|double\\|e\\(num\\|xtern\\)\\|"
|
|
1788 "float\\|int\\|long\\|register\\|"
|
|
1789 "s\\(hort\\|igned\\|t\\(atic\\|ruct\\)\\)\\|typedef\\|"
|
|
1790 "un\\(ion\\|signed\\)\\|vo\\(id\\|latile\\)")) ; 6 ()s deep.
|
|
1791 (c++-keywords
|
|
1792 ; ("break" "continue" "do" "else" "for" "if" "return" "switch" "while"
|
|
1793 ; "asm" "catch" "delete" "new" "operator" "sizeof" "this" "throw" "try"
|
|
1794 ; "protected" "private" "public")
|
|
1795 (concat "asm\\|break\\|c\\(atch\\|ontinue\\)\\|d\\(elete\\|o\\)\\|"
|
|
1796 "else\\|for\\|if\\|new\\|"
|
|
1797 "p\\(r\\(ivate\\|otected\\)\\|ublic\\)\\|return\\|"
|
|
1798 "s\\(izeof\\|witch\\)\\|t\\(h\\(is\\|row\\)\\|ry\\)\\|while"))
|
|
1799 (c++-type-types
|
|
1800 ; ("auto" "extern" "register" "static" "typedef" "struct" "union" "enum"
|
|
1801 ; "signed" "unsigned" "short" "long" "int" "char" "float" "double"
|
|
1802 ; "void" "volatile" "const" "class" "inline" "friend" "bool"
|
|
1803 ; "virtual" "complex" "template")
|
|
1804 (concat "auto\\|bool\\|c\\(har\\|lass\\|o\\(mplex\\|nst\\)\\)\\|"
|
|
1805 "double\\|e\\(num\\|xtern\\)\\|f\\(loat\\|riend\\)\\|"
|
|
1806 "in\\(line\\|t\\)\\|long\\|register\\|"
|
|
1807 "s\\(hort\\|igned\\|t\\(atic\\|ruct\\)\\)\\|"
|
|
1808 "t\\(emplate\\|ypedef\\)\\|un\\(ion\\|signed\\)\\|"
|
|
1809 "v\\(irtual\\|o\\(id\\|latile\\)\\)")) ; 11 ()s deep.
|
|
1810 (ctoken "\\(\\sw\\|\\s_\\|[:~*&]\\)+")
|
|
1811 )
|
|
1812 (setq c-font-lock-keywords-1
|
|
1813 (list
|
|
1814 ;;
|
|
1815 ;; These are all anchored at the beginning of line for speed.
|
|
1816 ;;
|
|
1817 ;; Fontify function name definitions (GNU style; without type on line).
|
|
1818
|
|
1819 ;; In FSF this has the simpler definition of "\\sw+" for ctoken.
|
|
1820 ;; I'm not sure if ours is more correct.
|
48
|
1821 ;; This is a subset of the next rule, and is slower when present. --dmoore
|
|
1822 ;; (list (concat "^\\(" ctoken "\\)[ \t]*(") 1 'font-lock-function-name-face)
|
0
|
1823 ;;
|
|
1824 ;; fontify the names of functions being defined.
|
|
1825 ;; FSF doesn't have this but I think it should be fast for us because
|
|
1826 ;; our regexp routines are more intelligent than FSF's about handling
|
|
1827 ;; anchored-at-newline. (When I added this hack in regex.c, it halved
|
|
1828 ;; the time to do the regexp phase of font-lock for a C file!) Not
|
|
1829 ;; including this discriminates against those who don't follow the
|
|
1830 ;; GNU coding style. --ben
|
48
|
1831 ;; x?x?x?y?z should always be: (x(xx?)?)?y?z --dmoore
|
0
|
1832 (list (concat
|
48
|
1833 "^\\("
|
|
1834 "\\(" ctoken "[ \t]+\\)" ; type specs; there can be no
|
|
1835 "\\("
|
|
1836 "\\(" ctoken "[ \t]+\\)" ; more than 3 tokens, right?
|
|
1837 "\\(" ctoken "[ \t]+\\)"
|
|
1838 "?\\)?\\)?"
|
0
|
1839 "\\([*&]+[ \t]*\\)?" ; pointer
|
|
1840 "\\(" ctoken "\\)[ \t]*(") ; name
|
48
|
1841 10 'font-lock-function-name-face)
|
0
|
1842 ;;
|
|
1843 ;; This is faster but not by much. I don't see why not.
|
|
1844 ;(list (concat "^\\(" ctoken "\\)[ \t]*(") 1 'font-lock-function-name-face)
|
|
1845 ;;
|
|
1846 ;; Added next two; they're both jolly-good fastmatch candidates so
|
|
1847 ;; should be fast. --ben
|
|
1848 ;;
|
|
1849 ;; Fontify structure names (in structure definition form).
|
|
1850 (list (concat "^\\(typedef[ \t]+struct\\|struct\\|static[ \t]+struct\\)"
|
|
1851 "[ \t]+\\(" ctoken "\\)[ \t]*\\(\{\\|$\\)")
|
|
1852 2 'font-lock-function-name-face)
|
|
1853 ;;
|
|
1854 ;; Fontify case clauses. This is fast because its anchored on the left.
|
|
1855 '("case[ \t]+\\(\\(\\sw\\|\\s_\\)+\\):". 1)
|
|
1856 ;;
|
|
1857 '("\\<\\(default\\):". 1)
|
|
1858 ;; Fontify filenames in #include <...> preprocessor directives as strings.
|
|
1859 '("^#[ \t]*include[ \t]+\\(<[^>\"\n]+>\\)" 1 font-lock-string-face)
|
|
1860 ;;
|
|
1861 ;; Fontify function macro names.
|
|
1862 '("^#[ \t]*define[ \t]+\\(\\(\\sw+\\)(\\)" 2 font-lock-function-name-face)
|
|
1863 ;;
|
|
1864 ;; Fontify symbol names in #if ... defined preprocessor directives.
|
|
1865 '("^#[ \t]*if\\>"
|
|
1866 ("\\<\\(defined\\)\\>[ \t]*(?\\(\\sw+\\)?" nil nil
|
|
1867 (1 font-lock-preprocessor-face) (2 font-lock-variable-name-face nil t)))
|
|
1868 ;;
|
|
1869 ;; Fontify symbol names in #elif ... defined preprocessor directives.
|
|
1870 '("^#[ \t]*elif\\>"
|
|
1871 ("\\<\\(defined\\)\\>[ \t]*(?\\(\\sw+\\)?" nil nil
|
|
1872 (1 font-lock-preprocessor-face) (2 font-lock-variable-name-face nil t)))
|
|
1873 ;;
|
|
1874 ;; Fontify otherwise as symbol names, and the preprocessor directive names.
|
|
1875 '("^\\(#[ \t]*[a-z]+\\)\\>[ \t]*\\(\\sw+\\)?"
|
|
1876 (1 font-lock-preprocessor-face) (2 font-lock-variable-name-face nil t))
|
|
1877 ))
|
|
1878
|
|
1879 (setq c-font-lock-keywords-2
|
|
1880 (append c-font-lock-keywords-1
|
|
1881 (list
|
|
1882 ;;
|
|
1883 ;; Simple regexps for speed.
|
|
1884 ;;
|
|
1885 ;; Fontify all type specifiers.
|
|
1886 (cons (concat "\\<\\(" c-type-types "\\)\\>") 'font-lock-type-face)
|
|
1887 ;;
|
|
1888 ;; Fontify all builtin keywords (except case, default and goto; see below).
|
|
1889 (cons (concat "\\<\\(" c-keywords "\\)\\>") 'font-lock-keyword-face)
|
|
1890 ;;
|
|
1891 ;; Fontify case/goto keywords and targets, and case default/goto tags.
|
|
1892 '("\\<\\(case\\|goto\\)\\>[ \t]*\\([^ \t\n:;]+\\)?"
|
|
1893 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
|
|
1894 '("^[ \t]*\\(\\sw+\\)[ \t]*:" 1 font-lock-reference-face)
|
|
1895 )))
|
|
1896
|
|
1897 (setq c-font-lock-keywords-3
|
|
1898 (append c-font-lock-keywords-2
|
|
1899 ;;
|
|
1900 ;; More complicated regexps for more complete highlighting for types.
|
|
1901 ;; We still have to fontify type specifiers individually, as C is so hairy.
|
|
1902 (list
|
|
1903 ;;
|
|
1904 ;; Fontify all storage classes and type specifiers, plus their items.
|
|
1905 (list (concat "\\<\\(" c-type-types "\\)\\>"
|
|
1906 "\\([ \t*&]+\\sw+\\>\\)*")
|
|
1907 ;; Fontify each declaration item.
|
|
1908 '(font-lock-match-c++-style-declaration-item-and-skip-to-next
|
|
1909 ;; Start with point after all type specifiers.
|
|
1910 (goto-char (or (match-beginning 8) (match-end 1)))
|
|
1911 ;; Finish with point after first type specifier.
|
|
1912 (goto-char (match-end 1))
|
|
1913 ;; Fontify as a variable or function name.
|
|
1914 (1 (if (match-beginning 4)
|
|
1915 font-lock-function-name-face
|
|
1916 font-lock-variable-name-face))))
|
|
1917 ;;
|
|
1918 ;; Fontify structures, or typedef names, plus their items.
|
|
1919 '("\\(}\\)[ \t*]*\\sw"
|
|
1920 (font-lock-match-c++-style-declaration-item-and-skip-to-next
|
|
1921 (goto-char (match-end 1)) nil
|
|
1922 (1 (if (match-beginning 4)
|
|
1923 font-lock-function-name-face
|
|
1924 font-lock-variable-name-face))))
|
|
1925 ;;
|
|
1926 ;; Fontify anything at beginning of line as a declaration or definition.
|
|
1927 '("^\\(\\sw+\\)\\>\\([ \t*]+\\sw+\\>\\)*"
|
|
1928 (1 font-lock-type-face)
|
|
1929 (font-lock-match-c++-style-declaration-item-and-skip-to-next
|
|
1930 (goto-char (or (match-beginning 2) (match-end 1))) nil
|
|
1931 (1 (if (match-beginning 4)
|
|
1932 font-lock-function-name-face
|
|
1933 font-lock-variable-name-face))))
|
|
1934 )))
|
|
1935
|
|
1936 (setq c++-font-lock-keywords-1
|
|
1937 (append
|
|
1938 ;;
|
|
1939 ;; The list `c-font-lock-keywords-1' less that for function names.
|
48
|
1940 ;; the simple function form regexp has been removed. --dmoore
|
|
1941 ;;(cdr c-font-lock-keywords-1)
|
|
1942 c-font-lock-keywords-1
|
0
|
1943 ;;
|
|
1944 ;; Fontify function name definitions, possibly incorporating class name.
|
|
1945 (list
|
|
1946 '("^\\(\\sw+\\)\\(::\\(\\sw+\\)\\)?[ \t]*("
|
|
1947 (1 (if (match-beginning 2)
|
|
1948 font-lock-type-face
|
|
1949 font-lock-function-name-face))
|
|
1950 (3 (if (match-beginning 2) font-lock-function-name-face) nil t))
|
|
1951 )))
|
|
1952
|
|
1953 (setq c++-font-lock-keywords-2
|
|
1954 (append c++-font-lock-keywords-1
|
|
1955 (list
|
|
1956 ;;
|
|
1957 ;; The list `c-font-lock-keywords-2' for C++ plus operator overloading.
|
|
1958 (cons (concat "\\<\\(" c++-type-types "\\)\\>") 'font-lock-type-face)
|
|
1959 ;;
|
|
1960 ;; Fontify operator function name overloading.
|
|
1961 '("\\<\\(operator\\)\\>[ \t]*\\([][)(><!=+-][][)(><!=+-]?\\)?"
|
|
1962 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t))
|
|
1963 ;;
|
|
1964 ;; Fontify case/goto keywords and targets, and case default/goto tags.
|
|
1965 '("\\<\\(case\\|goto\\)\\>[ \t]*\\([^ \t\n:;]+\\)?"
|
|
1966 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
|
|
1967 '("^[ \t]*\\(\\sw+\\)[ \t]*:[^:]" 1 font-lock-reference-face)
|
|
1968 ;;
|
|
1969 ;; Fontify other builtin keywords.
|
|
1970 (cons (concat "\\<\\(" c++-keywords "\\)\\>") 'font-lock-keyword-face)
|
|
1971 )))
|
|
1972
|
|
1973 (setq c++-font-lock-keywords-3
|
|
1974 (append c++-font-lock-keywords-2
|
|
1975 ;;
|
|
1976 ;; More complicated regexps for more complete highlighting for types.
|
|
1977 (list
|
|
1978 ;;
|
|
1979 ;; Fontify all storage classes and type specifiers, plus their items.
|
|
1980 (list (concat "\\<\\(" c++-type-types "\\)\\>"
|
|
1981 "\\([ \t*&]+\\sw+\\>\\)*")
|
|
1982 ;; Fontify each declaration item.
|
|
1983 '(font-lock-match-c++-style-declaration-item-and-skip-to-next
|
|
1984 ;; Start with point after all type specifiers.
|
|
1985 (goto-char (or (match-beginning 13) (match-end 1)))
|
|
1986 ;; Finish with point after first type specifier.
|
|
1987 (goto-char (match-end 1))
|
|
1988 ;; Fontify as a variable or function name.
|
|
1989 (1 (cond ((match-beginning 2) 'font-lock-type-face)
|
|
1990 ((match-beginning 4) 'font-lock-function-name-face)
|
|
1991 (t 'font-lock-variable-name-face)))
|
|
1992 (3 (if (match-beginning 4)
|
|
1993 'font-lock-function-name-face
|
|
1994 'font-lock-variable-name-face) nil t)))
|
|
1995 ;;
|
|
1996 ;; Fontify structures, or typedef names, plus their items.
|
|
1997 '("\\(}\\)[ \t*]*\\sw"
|
|
1998 (font-lock-match-c++-style-declaration-item-and-skip-to-next
|
|
1999 (goto-char (match-end 1)) nil
|
|
2000 (1 (if (match-beginning 4)
|
|
2001 font-lock-function-name-face
|
|
2002 font-lock-variable-name-face))))
|
|
2003 ;;
|
|
2004 ;; Fontify anything at beginning of line as a declaration or definition.
|
|
2005 '("^\\(\\sw+\\)\\>\\([ \t*]+\\sw+\\>\\)*"
|
|
2006 (1 font-lock-type-face)
|
|
2007 (font-lock-match-c++-style-declaration-item-and-skip-to-next
|
|
2008 (goto-char (or (match-beginning 2) (match-end 1))) nil
|
|
2009 (1 (cond ((match-beginning 2) 'font-lock-type-face)
|
|
2010 ((match-beginning 4) 'font-lock-function-name-face)
|
|
2011 (t 'font-lock-variable-name-face)))
|
|
2012 (3 (if (match-beginning 4)
|
|
2013 'font-lock-function-name-face
|
|
2014 'font-lock-variable-name-face) nil t)))
|
|
2015 )))
|
|
2016 )
|
|
2017
|
|
2018 (defvar c-font-lock-keywords c-font-lock-keywords-1
|
|
2019 "Default expressions to highlight in C mode.")
|
|
2020
|
|
2021 (defvar c++-font-lock-keywords c++-font-lock-keywords-1
|
|
2022 "Default expressions to highlight in C++ mode.")
|
|
2023
|
|
2024 ;; The previous version, before replacing it with the FSF version.
|
|
2025 ;(defconst c-font-lock-keywords-1 nil
|
|
2026 ; "For consideration as a value of `c-font-lock-keywords'.
|
|
2027 ;This does fairly subdued highlighting.")
|
|
2028 ;
|
|
2029 ;(defconst c-font-lock-keywords-2 nil
|
|
2030 ; "For consideration as a value of `c-font-lock-keywords'.
|
|
2031 ;This does a lot more highlighting.")
|
|
2032 ;
|
|
2033 ;(let ((storage "auto\\|extern\\|register\\|static\\|volatile")
|
|
2034 ; (prefixes "unsigned\\|short\\|long\\|const")
|
|
2035 ; (types (concat "int\\|long\\|char\\|float\\|double\\|void\\|struct\\|"
|
|
2036 ; "union\\|enum\\|typedef"))
|
|
2037 ; (ctoken "\\(\\sw\\|\\s_\\|[:~*&]\\)+")
|
|
2038 ; )
|
|
2039 ; (setq c-font-lock-keywords-1 (purecopy
|
|
2040 ; (list
|
|
2041 ; ;; fontify preprocessor directives.
|
|
2042 ; '("^#[ \t]*[a-z]+" . font-lock-preprocessor-face)
|
|
2043 ; ;;
|
|
2044 ; ;; fontify names being defined.
|
|
2045 ; '("^#[ \t]*\\(define\\|undef\\)[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)" 2
|
|
2046 ; font-lock-function-name-face)
|
|
2047 ; ;;
|
|
2048 ; ;; fontify other preprocessor lines.
|
|
2049 ; '("^#[ \t]*\\(if\\|ifn?def\\|elif\\)[ \t]+\\([^\n]+\\)"
|
|
2050 ; 2 font-lock-function-name-face t)
|
|
2051 ; ;;
|
|
2052 ; ;; fontify the filename in #include <...>
|
|
2053 ; ;; don't need to do this for #include "..." because those were
|
|
2054 ; ;; already fontified as strings by the syntactic pass.
|
|
2055 ; ;; (Changed to not include the <> in the face, since "" aren't.)
|
|
2056 ; '("^#[ \t]*include[ \t]+<\\([^>\"\n]+\\)>" 1 font-lock-string-face)
|
|
2057 ; ;;
|
|
2058 ; ;; fontify the names of functions being defined.
|
|
2059 ; ;; I think this should be fast because it's anchored at bol, but it's not.
|
|
2060 ; (list (concat
|
|
2061 ; "^\\(" ctoken "[ \t]+\\)?" ; type specs; there can be no
|
|
2062 ; "\\(" ctoken "[ \t]+\\)?" ; more than 3 tokens, right?
|
|
2063 ; "\\(" ctoken "[ \t]+\\)?"
|
|
2064 ; "\\([*&]+[ \t]*\\)?" ; pointer
|
|
2065 ; "\\(" ctoken "\\)[ \t]*(") ; name
|
|
2066 ; 8 'font-lock-function-name-face)
|
|
2067 ; ;;
|
|
2068 ; ;; This is faster but not by much. I don't see why not.
|
|
2069 ;; (list (concat "^\\(" ctoken "\\)[ \t]*(") 1 'font-lock-function-name-face)
|
|
2070 ; ;;
|
|
2071 ; ;; Fontify structure names (in structure definition form).
|
|
2072 ; (list (concat "^\\(typedef[ \t]+struct\\|struct\\|static[ \t]+struct\\)"
|
|
2073 ; "[ \t]+\\(" ctoken "\\)[ \t]*\\(\{\\|$\\)")
|
|
2074 ; 2 'font-lock-function-name-face)
|
|
2075 ; ;;
|
|
2076 ; ;; Fontify case clauses. This is fast because its anchored on the left.
|
|
2077 ; '("case[ \t]+\\(\\(\\sw\\|\\s_\\)+\\):". 1)
|
|
2078 ; '("\\<\\(default\\):". 1)
|
|
2079 ; )))
|
|
2080 ;
|
|
2081 ; (setq c-font-lock-keywords-2 (purecopy
|
|
2082 ; (append c-font-lock-keywords-1
|
|
2083 ; (list
|
|
2084 ; ;;
|
|
2085 ; ;; fontify all storage classes and type specifiers
|
|
2086 ; ;; types should be surrounded by non alphanumerics (Raymond Toy)
|
|
2087 ; (cons (concat "\\<\\(" storage "\\)\\>") 'font-lock-type-face)
|
|
2088 ; (list (concat "\\([^a-zA-Z0-9_]\\|^\\)\\("
|
|
2089 ; types
|
|
2090 ; "\\)\\([^a-zA-Z0-9_]\\|$\\)")
|
|
2091 ; 2 'font-lock-type-face)
|
|
2092 ; ;; fontify the prefixes now. The types should have been fontified
|
|
2093 ; ;; previously.
|
|
2094 ; (list (concat "\\<\\(" prefixes "\\)[ \t]+\\(" types "\\)\\>")
|
|
2095 ; 1 'font-lock-type-face)
|
|
2096 ; ;;
|
|
2097 ; ;; fontify all builtin tokens
|
|
2098 ; (cons (concat
|
|
2099 ; "[ \t]\\("
|
|
2100 ; (mapconcat 'identity
|
|
2101 ; '("for" "while" "do" "return" "goto" "case" "break" "switch"
|
|
2102 ; "if" "then" "else if" "else" "return" "continue" "default"
|
|
2103 ; )
|
|
2104 ; "\\|")
|
|
2105 ; "\\)[ \t\n(){};,]")
|
|
2106 ; 1)
|
|
2107 ; ;;
|
|
2108 ; ;; fontify case targets and goto-tags. This is slow because the
|
|
2109 ; ;; expression is anchored on the right.
|
|
2110 ; "\\(\\(\\sw\\|\\s_\\)+\\):"
|
|
2111 ; ;;
|
|
2112 ; ;; Fontify variables declared with structures, or typedef names.
|
|
2113 ; '("}[ \t*]*\\(\\(\\sw\\|\\s_\\)+\\)[ \t]*[,;]"
|
|
2114 ; 1 font-lock-function-name-face)
|
|
2115 ; ;;
|
|
2116 ; ;; Fontify global variables without a type.
|
|
2117 ;; '("^\\([_a-zA-Z0-9:~*]+\\)[ \t]*[[;={]" 1 font-lock-function-name-face)
|
|
2118 ;
|
|
2119 ; ))))
|
|
2120 ; )
|
|
2121 ;
|
|
2122 ;
|
|
2123 ;;; default to the gaudier variety?
|
|
2124 ;;(defconst c-font-lock-keywords c-font-lock-keywords-2
|
|
2125 ;; "Additional expressions to highlight in C mode.")
|
|
2126 ;(defconst c-font-lock-keywords c-font-lock-keywords-1
|
|
2127 ; "Additional expressions to highlight in C mode.")
|
|
2128 ;
|
|
2129 ;(defconst c++-font-lock-keywords-1 nil
|
|
2130 ; "For consideration as a value of `c++-font-lock-keywords'.
|
|
2131 ;This does fairly subdued highlighting.")
|
|
2132 ;
|
|
2133 ;(defconst c++-font-lock-keywords-2 nil
|
|
2134 ; "For consideration as a value of `c++-font-lock-keywords'.
|
|
2135 ;This does a lot more highlighting.")
|
|
2136 ;
|
|
2137 ;(let ((ctoken "\\(\\sw\\|\\s_\\|[:~*&]\\)+")
|
|
2138 ; (c++-types (concat "complex\\|public\\|private\\|protected\\|virtual\\|"
|
|
2139 ; "friend\\|inline"))
|
|
2140 ; c++-font-lock-keywords-internal-1
|
|
2141 ; c++-font-lock-keywords-internal-2
|
|
2142 ; )
|
|
2143 ; (setq c++-font-lock-keywords-internal-1 (purecopy
|
|
2144 ; (list
|
|
2145 ; ;;
|
|
2146 ; ;; fontify friend operator functions
|
|
2147 ; '("^\\(operator[^(]*\\)(" 1 font-lock-function-name-face)
|
|
2148 ; '("^\\(operator[ \\t]*([ \\t]*)[^(]*\\)(" 1 font-lock-function-name-face)
|
|
2149 ;
|
|
2150 ; ;; fontify the class names only in the definition
|
|
2151 ; (list (concat "^class[ \t]+" ctoken "[ \t\n{: ;]") 1
|
|
2152 ; 'font-lock-function-name-face)
|
|
2153 ;
|
|
2154 ; (list (concat
|
|
2155 ; "^\\(" ctoken "[ \t]+\\)?" ; type specs; there can be no
|
|
2156 ; "\\(" ctoken "[ \t]+\\)?" ; more than 3 tokens, right?
|
|
2157 ; "\\(" ctoken "[ \t]+\\)?"
|
|
2158 ; "\\(\\*+[ \t]*\\)?" ; pointer
|
|
2159 ; "\\(" ctoken "\\(::\\)?~?\\(\\(operator[ \t]*[^ \ta-zA-Z]+\\)\\|"
|
|
2160 ; ctoken "\\)\\)[ \t]*(") ; name
|
|
2161 ; 8 'font-lock-function-name-face t)
|
|
2162 ; )))
|
|
2163 ;
|
|
2164 ; (setq c++-font-lock-keywords-internal-2 (purecopy
|
|
2165 ; (list
|
|
2166 ; ;; fontify extra c++ storage classes and type specifiers
|
|
2167 ; (cons (concat "\\<\\(" c++-types "\\)\\>") 'font-lock-type-face)
|
|
2168 ;
|
|
2169 ; ;;special check for class
|
|
2170 ; '("^\\(\\<\\|template[ \t]+<[ \t]*\\)\\(class\\)[ \t\n]+" 2
|
|
2171 ; font-lock-type-face)
|
|
2172 ;
|
|
2173 ; ;; special handling of template
|
|
2174 ; "^\\(template\\)\\>"
|
|
2175 ; ;; fontify extra c++ builtin tokens
|
|
2176 ; (cons (concat
|
|
2177 ; "[ \t]\\("
|
|
2178 ; (mapconcat 'identity
|
|
2179 ; '("asm" "catch" "throw" "try" "delete" "new" "operator"
|
|
2180 ; "sizeof" "this"
|
|
2181 ; )
|
|
2182 ; "\\|")
|
|
2183 ; "\\)[ \t\n(){};,]")
|
|
2184 ; 1)
|
|
2185 ; )))
|
|
2186 ;
|
|
2187 ; (setq c++-font-lock-keywords-1 (purecopy
|
|
2188 ; (append c-font-lock-keywords-1 c++-font-lock-keywords-internal-1)))
|
|
2189 ;
|
|
2190 ; (setq c++-font-lock-keywords-2 (purecopy
|
|
2191 ; (append c-font-lock-keywords-2 c++-font-lock-keywords-internal-1
|
|
2192 ; c++-font-lock-keywords-internal-2)))
|
|
2193 ; )
|
|
2194 ;
|
|
2195 ;(defconst c++-font-lock-keywords c++-font-lock-keywords-1
|
|
2196 ; "Additional expressions to highlight in C++ mode.")
|
|
2197
|
10
|
2198 ;; Java support from Anders Lindgren and Bob Weiner
|
|
2199
|
0
|
2200 (defconst java-font-lock-keywords-1 nil
|
|
2201 "For consideration as a value of `java-font-lock-keywords'.
|
|
2202 This does fairly subdued highlighting.")
|
|
2203
|
|
2204 (defconst java-font-lock-keywords-2 nil
|
|
2205 "For consideration as a value of `java-font-lock-keywords'.
|
10
|
2206 This adds highlighting of types and identifier names.")
|
|
2207
|
|
2208 (defconst java-font-lock-keywords-3 nil
|
|
2209 "For consideration as a value of `java-font-lock-keywords'.
|
|
2210 This adds highlighting of Java documentation tags, such as @see.")
|
|
2211
|
|
2212 (defvar java-font-lock-type-regexp
|
|
2213 (concat "\\<\\(boolean\\|byte\\|char\\|double\\|float\\|int"
|
|
2214 "\\|long\\|short\\|void\\)\\>")
|
|
2215 "Regexp which should match a primitive type.")
|
|
2216
|
|
2217 (let ((capital-letter "A-Z\300-\326\330-\337")
|
|
2218 (letter "a-zA-Z_$\300-\326\330-\366\370-\377")
|
|
2219 (digit "0-9"))
|
|
2220 (defvar java-font-lock-identifier-regexp
|
|
2221 (concat "\\<\\([" letter "][" letter digit "]*\\)\\>")
|
|
2222 "Regexp which should match all Java identifiers.")
|
|
2223
|
|
2224 (defvar java-font-lock-class-name-regexp
|
|
2225 (concat "\\<\\([" capital-letter "][" letter digit "]*\\)\\>")
|
|
2226 "Regexp which should match a class or an interface name.
|
|
2227 The name is assumed to begin with a capital letter.")
|
|
2228 )
|
|
2229
|
0
|
2230
|
10
|
2231 (let ((java-modifier-regexp
|
|
2232 (concat "\\<\\(abstract\\|const\\|final\\|native\\|"
|
|
2233 "private\\|protected\\|public\\|"
|
|
2234 "static\\|synchronized\\|transient\\|volatile\\)\\>")))
|
0
|
2235
|
10
|
2236 ;; Basic font-lock support:
|
0
|
2237 (setq java-font-lock-keywords-1
|
10
|
2238 (list
|
|
2239 ;; Keywords:
|
|
2240 (list
|
|
2241 (concat
|
|
2242 "\\<\\("
|
|
2243 "break\\|byvalue\\|"
|
|
2244 "case\\|cast\\|catch\\|class\\|continue\\|"
|
|
2245 "do\\|else\\|extends\\|"
|
|
2246 "finally\\|for\\|future\\|"
|
|
2247 "generic\\|goto\\|"
|
|
2248 "if\\|implements\\|import\\|"
|
|
2249 "instanceof\\|interface\\|"
|
|
2250 "new\\|package\\|return\\|switch\\|"
|
|
2251 "throws?\\|try\\|while\\)\\>")
|
|
2252 1 'font-lock-keyword-face)
|
0
|
2253
|
10
|
2254 ;; Modifiers:
|
|
2255 (list java-modifier-regexp 1 font-lock-type-face)
|
0
|
2256
|
10
|
2257 ;; Special constants:
|
|
2258 '("\\<\\(this\\|super\\)\\>" (1 font-lock-reference-face))
|
|
2259 '("\\<\\(false\\|null\\|true\\)\\>" (1 font-lock-keyword-face))
|
0
|
2260
|
10
|
2261 ;; Class names:
|
|
2262 (list (concat "\\<class\\>\\s *" java-font-lock-identifier-regexp)
|
|
2263 1 'font-lock-function-name-face)
|
0
|
2264
|
10
|
2265 ;; Package declarations:
|
|
2266 (list (concat "\\<\\(package\\|import\\)\\>\\s *"
|
|
2267 java-font-lock-identifier-regexp)
|
|
2268 '(2 font-lock-reference-face)
|
|
2269 (list (concat
|
|
2270 "\\=\\.\\(" java-font-lock-identifier-regexp "\\)")
|
38
|
2271 nil nil '(1 (let ((c (char-after (match-end 0))))
|
|
2272 (if (and (characterp c)
|
|
2273 (= c ?.))
|
|
2274 'font-lock-reference-face
|
|
2275 'font-lock-type-face)))))
|
0
|
2276
|
10
|
2277 ;; Constructors:
|
|
2278 (list (concat
|
|
2279 "^\\s *\\(" java-modifier-regexp "\\s +\\)*"
|
|
2280 java-font-lock-class-name-regexp "\\s *\(")
|
|
2281 (list 3
|
|
2282 '(condition-case nil
|
|
2283 (save-excursion
|
|
2284 (goto-char (scan-sexps (- (match-end 0) 1) 1))
|
|
2285 (parse-partial-sexp (point) (point-max) nil t)
|
|
2286 (and (looking-at "\\($\\|\\<throws\\>\\|{\\)")
|
|
2287 'font-lock-function-name-face))
|
|
2288 (error 'font-lock-function-name-face))))
|
0
|
2289
|
10
|
2290 ;; Methods:
|
|
2291 (list (concat "\\(" java-font-lock-type-regexp "\\|"
|
|
2292 java-font-lock-class-name-regexp "\\)"
|
|
2293 "\\s *\\(\\[\\s *\\]\\s *\\)*"
|
|
2294 java-font-lock-identifier-regexp "\\s *\(")
|
|
2295 5
|
|
2296 'font-lock-function-name-face)
|
0
|
2297
|
10
|
2298 ;; Labels:
|
|
2299 (list ":"
|
|
2300 (list
|
|
2301 (concat "^\\s *" java-font-lock-identifier-regexp "\\s *:")
|
|
2302 '(beginning-of-line) '(end-of-line)
|
|
2303 '(1 font-lock-reference-face)))
|
0
|
2304
|
10
|
2305 ;; `break' and continue' destination labels:
|
|
2306 (list (concat "\\<\\(break\\|continue\\)\\>\\s *"
|
|
2307 java-font-lock-identifier-regexp)
|
|
2308 2 'font-lock-reference-face)
|
0
|
2309
|
10
|
2310 ;; Case statements:
|
|
2311 ;; In Java, any constant expression is allowed.
|
|
2312 '("\\<case\\>\\s *\\(.*\\):" 1 font-lock-reference-face)))
|
|
2313
|
|
2314 ;; Types and declared variable names:
|
|
2315 (setq java-font-lock-keywords-2
|
|
2316 (append
|
0
|
2317
|
10
|
2318 java-font-lock-keywords-1
|
|
2319 (list
|
|
2320 ;; Keywords followed by a type:
|
|
2321 (list (concat "\\<\\(extends\\|instanceof\\|new\\)\\>\\s *"
|
|
2322 java-font-lock-identifier-regexp)
|
|
2323 '(2 (if (= (char-after (match-end 0)) ?.)
|
|
2324 'font-lock-reference-face 'font-lock-type-face))
|
|
2325 (list (concat "\\=\\." java-font-lock-identifier-regexp)
|
|
2326 '(goto-char (match-end 0)) nil
|
|
2327 '(1 (if (= (char-after (match-end 0)) ?.)
|
|
2328 'font-lock-reference-face 'font-lock-type-face))))
|
0
|
2329
|
10
|
2330 ;; Keywords followed by a type list:
|
|
2331 (list (concat "\\<\\(implements\\|throws\\)\\>\\ s*"
|
|
2332 java-font-lock-identifier-regexp)
|
|
2333 '(2 (if (= (char-after (match-end 0)) ?.)
|
|
2334 font-lock-reference-face font-lock-type-face))
|
|
2335 (list (concat "\\=\\(\\.\\|\\s *\\(,\\)\\s *\\)"
|
|
2336 java-font-lock-identifier-regexp)
|
|
2337 '(goto-char (match-end 0)) nil
|
|
2338 '(3 (if (= (char-after (match-end 0)) ?.)
|
|
2339 font-lock-reference-face font-lock-type-face))))
|
0
|
2340
|
10
|
2341 ;; primitive types, can't be confused with anything else.
|
|
2342 (list java-font-lock-type-regexp
|
|
2343 '(1 font-lock-type-face)
|
|
2344 '(font-lock-match-java-declarations
|
|
2345 (goto-char (match-end 0))
|
|
2346 (goto-char (match-end 0))
|
|
2347 (0 font-lock-variable-name-face)))
|
0
|
2348
|
10
|
2349 ;; Declarations, class types and capitalized variables:
|
|
2350 ;;
|
|
2351 ;; Declarations are easy to recognize. Capitalized words
|
|
2352 ;; followed by a closing parenthesis are treated as casts if they
|
|
2353 ;; also are followed by an expression. Expressions beginning with
|
|
2354 ;; a unary numerical operator, e.g. +, can't be cast to an object
|
|
2355 ;; type.
|
|
2356 ;;
|
|
2357 ;; The path of a fully qualified type, e.g. java.lang.Foo, is
|
|
2358 ;; fontified in the reference face.
|
|
2359 ;;
|
|
2360 ;; An access to a static field, e.g. System.out.println, is
|
|
2361 ;; not fontified since it can't be distinguished from the
|
|
2362 ;; usage of a capitalized variable, e.g. Foo.out.println.
|
0
|
2363
|
10
|
2364 (list (concat java-font-lock-class-name-regexp
|
|
2365 "\\s *\\(\\[\\s *\\]\\s *\\)*"
|
|
2366 "\\(\\<\\|$\\|)\\s *\\([\(\"]\\|\\<\\)\\)")
|
|
2367 '(1 (save-match-data
|
|
2368 (save-excursion
|
|
2369 (goto-char
|
|
2370 (match-beginning 3))
|
|
2371 (if (not (looking-at "\\<instanceof\\>"))
|
|
2372 'font-lock-type-face))))
|
|
2373 (list (concat "\\=" java-font-lock-identifier-regexp "\\.")
|
|
2374 '(progn
|
|
2375 (goto-char (match-beginning 0))
|
|
2376 (while (or (= (preceding-char) ?.)
|
|
2377 (= (char-syntax (preceding-char)) ?w))
|
|
2378 (backward-char)))
|
|
2379 '(goto-char (match-end 0))
|
|
2380 '(1 font-lock-reference-face)
|
|
2381 '(0 nil)) ; Workaround for bug in XEmacs.
|
|
2382 '(font-lock-match-java-declarations
|
|
2383 (goto-char (match-end 1))
|
|
2384 (goto-char (match-end 0))
|
|
2385 (1 font-lock-variable-name-face))))))
|
0
|
2386
|
10
|
2387 ;; Modifier keywords and Java doc tags
|
|
2388 (setq java-font-lock-keywords-3
|
|
2389 (append
|
0
|
2390
|
10
|
2391 '(
|
|
2392 ;; Feature scoping:
|
|
2393 ;; These must come first or the Modifiers from keywords-1 will
|
|
2394 ;; catch them. We don't want to use override fontification here
|
|
2395 ;; because then these terms will be fontified within comments.
|
|
2396 ("\\<private\\>" 0 font-lock-string-face)
|
|
2397 ("\\<protected\\>" 0 font-lock-preprocessor-face)
|
|
2398 ("\\<public\\>" 0 font-lock-reference-face))
|
|
2399
|
|
2400 java-font-lock-keywords-2
|
|
2401
|
|
2402 (list
|
|
2403
|
|
2404 ;; Java doc tags
|
|
2405 '("@\\(author\\|exception\\|param\\|return\\|see\\|version\\)\\s "
|
|
2406 0 font-lock-keyword-face t)
|
0
|
2407
|
10
|
2408 ;; Doc tag - Parameter identifiers
|
|
2409 (list (concat "@param\\s +" java-font-lock-identifier-regexp)
|
|
2410 1 'font-lock-variable-name-face t)
|
|
2411
|
|
2412 ;; Doc tag - Exception types
|
|
2413 (list (concat "@exception\\ s*"
|
|
2414 java-font-lock-identifier-regexp)
|
|
2415 '(1 (if (= (char-after (match-end 0)) ?.)
|
|
2416 font-lock-reference-face font-lock-type-face) t)
|
|
2417 (list (concat "\\=\\." java-font-lock-identifier-regexp)
|
|
2418 '(goto-char (match-end 0)) nil
|
|
2419 '(1 (if (= (char-after (match-end 0)) ?.)
|
|
2420 'font-lock-reference-face 'font-lock-type-face) t)))
|
|
2421
|
|
2422 ;; Doc tag - Cross-references, usually to methods
|
|
2423 '("@see\\s +\\(\\S *[^][ \t\n\r\f(){},.;:]\\)"
|
|
2424 1 font-lock-function-name-face t)
|
|
2425
|
|
2426 )))
|
0
|
2427 )
|
|
2428
|
|
2429 (defvar java-font-lock-keywords java-font-lock-keywords-1
|
|
2430 "Additional expressions to highlight in Java mode.")
|
|
2431
|
10
|
2432 ;; Match and move over any declaration/definition item after
|
|
2433 ;; point. Does not match items which look like a type declaration
|
|
2434 ;; (primitive types and class names, i.e. capitalized words.)
|
|
2435 ;; Should the variable name be followed by a comma, we reposition
|
|
2436 ;; the cursor to fontify more identifiers.
|
|
2437 (defun font-lock-match-java-declarations (limit)
|
|
2438 "Match and skip over variable definitions."
|
|
2439 (if (looking-at "\\s *\\(\\[\\s *\\]\\s *\\)*")
|
|
2440 (goto-char (match-end 0)))
|
|
2441 (and
|
|
2442 (looking-at java-font-lock-identifier-regexp)
|
|
2443 (save-match-data
|
|
2444 (not (string-match java-font-lock-type-regexp
|
|
2445 (buffer-substring (match-beginning 1)
|
|
2446 (match-end 1)))))
|
|
2447 (save-match-data
|
|
2448 (save-excursion
|
|
2449 (goto-char (match-beginning 1))
|
|
2450 (not (looking-at
|
|
2451 (concat java-font-lock-class-name-regexp
|
|
2452 "\\s *\\(\\[\\s *\\]\\s *\\)*\\<")))))
|
|
2453 (save-match-data
|
|
2454 (condition-case nil
|
|
2455 (save-restriction
|
|
2456 (narrow-to-region (point-min) limit)
|
|
2457 (goto-char (match-end 0))
|
|
2458 ;; Note: Both `scan-sexps' and the second goto-char can
|
|
2459 ;; generate an error which is caught by the
|
|
2460 ;; `condition-case' expression.
|
|
2461 (while (not (looking-at "\\s *\\(\\(,\\)\\|;\\|$\\)"))
|
|
2462 (goto-char (or (scan-sexps (point) 1) (point-max))))
|
|
2463 (goto-char (match-end 2))) ; non-nil
|
|
2464 (error t)))))
|
|
2465
|
|
2466
|
0
|
2467 (defvar tex-font-lock-keywords
|
|
2468 ; ;; Regexps updated with help from Ulrik Dickow <dickow@nbi.dk>.
|
|
2469 ; '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
|
|
2470 ; 2 font-lock-function-name-face)
|
|
2471 ; ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
|
|
2472 ; 2 font-lock-reference-face)
|
|
2473 ; ;; It seems a bit dubious to use `bold' and `italic' faces since we might
|
|
2474 ; ;; not be able to display those fonts.
|
|
2475 ; ("{\\\\bf\\([^}]+\\)}" 1 'bold keep)
|
|
2476 ; ("{\\\\\\(em\\|it\\|sl\\)\\([^}]+\\)}" 2 'italic keep)
|
|
2477 ; ("\\\\\\([a-zA-Z@]+\\|.\\)" . font-lock-keyword-face)
|
|
2478 ; ("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face keep))
|
|
2479 ;; Rewritten and extended for LaTeX2e by Ulrik Dickow <dickow@nbi.dk>.
|
|
2480 '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
|
|
2481 2 font-lock-function-name-face)
|
|
2482 ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
|
|
2483 2 font-lock-reference-face)
|
|
2484 ("^[ \t]*\\\\def\\\\\\(\\(\\w\\|@\\)+\\)" 1 font-lock-function-name-face)
|
|
2485 "\\\\\\([a-zA-Z@]+\\|.\\)"
|
|
2486 ;; It seems a bit dubious to use `bold' and `italic' faces since we might
|
|
2487 ;; not be able to display those fonts.
|
|
2488 ;; LaTeX2e: \emph{This is emphasized}.
|
|
2489 ("\\\\emph{\\([^}]+\\)}" 1 'italic keep)
|
|
2490 ;; LaTeX2e: \textbf{This is bold}, \textit{...}, \textsl{...}
|
|
2491 ("\\\\text\\(\\(bf\\)\\|it\\|sl\\){\\([^}]+\\)}"
|
|
2492 3 (if (match-beginning 2) 'bold 'italic) keep)
|
|
2493 ;; Old-style bf/em/it/sl. Stop at `\\' and un-escaped `&', for good tables.
|
|
2494 ("\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)"
|
|
2495 3 (if (match-beginning 2) 'bold 'italic) keep))
|
|
2496 "Default expressions to highlight in TeX modes.")
|
|
2497
|
|
2498 ;; The previous version, before replacing it with the FSF version.
|
|
2499 ;(defconst tex-font-lock-keywords (purecopy
|
|
2500 ; (list
|
|
2501 ; ;; Lionel Mallet: Thu Oct 14 09:41:38 1993
|
|
2502 ; ;; I've added an exit condition to the regexp below, and the other
|
|
2503 ; ;; regexps for the second part.
|
|
2504 ; ;; What would be useful here is something like:
|
|
2505 ; ;; ("\\(\\\\\\w+\\)\\({\\(\\w+\\)}\\)+" 1 font-lock-keyword-face t 3
|
|
2506 ; ;; font-lock-function-name-face t)
|
|
2507 ; '("\\(\\\\\\w+\\)\\W" 1 font-lock-keyword-face t)
|
|
2508 ; '("\\(\\\\\\w+\\){\\([^}\n]+\\)}" 2 font-lock-function-name-face t)
|
|
2509 ; '("\\(\\\\\\w+\\){\\(\\w+\\)}{\\(\\w+\\)}" 3
|
|
2510 ; font-lock-function-name-face t)
|
|
2511 ; '("\\(\\\\\\w+\\){\\(\\w+\\)}{\\(\\w+\\)}{\\(\\w+\\)}" 4
|
|
2512 ; font-lock-function-name-face t)
|
|
2513 ; '("{\\\\\\(em\\|tt\\)\\([^}]+\\)}" 2 font-lock-comment-face t)
|
|
2514 ; '("{\\\\bf\\([^}]+\\)}" 1 font-lock-keyword-face t)
|
|
2515 ; '("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)\\W" 1 font-lock-function-name-face t)
|
|
2516 ; ;; Lionel Mallet: Thu Oct 14 09:40:10 1993
|
|
2517 ; ;; the regexp below is useless as it is now covered by the first 2 regexps
|
|
2518 ; ;; '("\\\\\\(begin\\|end\\){\\([a-zA-Z0-9\\*]+\\)}"
|
|
2519 ; ;; 2 font-lock-function-name-face t)
|
|
2520 ; '("[^\\\\]\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
|
|
2521 ;; '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
|
|
2522 ; ))
|
|
2523 ; "Additional expressions to highlight in TeX mode.")
|
|
2524
|
|
2525 (defconst ksh-font-lock-keywords (purecopy
|
|
2526 (list
|
|
2527 '("\\(^\\|[^\$\\\]\\)#.*" . font-lock-comment-face)
|
|
2528 '("\\<\\(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)
|
|
2529 '("\\<\\[\\[.*\\]\\]\\>" . font-lock-type-face)
|
|
2530 '("\$\(.*\)" . font-lock-type-face)
|
|
2531 ))
|
|
2532 "Additional expressions to highlight in ksh-mode.")
|
|
2533
|
|
2534 (defconst sh-font-lock-keywords (purecopy
|
|
2535 (list
|
|
2536 '("\\(^\\|[^\$\\\]\\)#.*" . font-lock-comment-face)
|
|
2537 '("\\<\\(if\\|then\\|else\\|elif\\|fi\\|case\\|esac\\|for\\|do\\|done\\|in\\|while\\|exec\\|export\\|set\\|echo\\|eval\\|cd\\)\\>" . font-lock-keyword-face)
|
|
2538 '("\\[.*\\]" . font-lock-type-face)
|
|
2539 '("`.*`" . font-lock-type-face)
|
|
2540 ))
|
|
2541 "Additional expressions to highlight in sh-mode.")
|
|
2542
|
|
2543
|
|
2544 ;; Install ourselves:
|
|
2545
|
|
2546 (add-hook 'find-file-hooks 'font-lock-set-defaults t)
|
|
2547
|
|
2548 (make-face 'font-lock-comment-face "Face to use for comments.")
|
|
2549 (make-face 'font-lock-doc-string-face "Face to use for documentation strings.")
|
|
2550 (make-face 'font-lock-string-face "Face to use for strings.")
|
|
2551 (make-face 'font-lock-keyword-face "Face to use for keywords.")
|
|
2552 (make-face 'font-lock-function-name-face "Face to use for function names.")
|
|
2553 (make-face 'font-lock-variable-name-face "Face to use for variable names.")
|
|
2554 (make-face 'font-lock-type-face "Face to use for type names.")
|
|
2555 (make-face 'font-lock-reference-face "Face to use for reference names.")
|
|
2556 (make-face 'font-lock-preprocessor-face
|
|
2557 "Face to use for preprocessor commands.")
|
|
2558
|
|
2559 ;; Backwards compatibility?
|
|
2560
|
|
2561 (if (eq t font-lock-use-colors)
|
|
2562 (setq font-lock-use-colors '(color)))
|
|
2563
|
|
2564 (if (eq t font-lock-use-fonts)
|
|
2565 (setq font-lock-use-fonts '(or (mono) (grayscale))))
|
|
2566
|
|
2567 (font-lock-apply-defaults 'font-lock-add-fonts font-lock-use-fonts)
|
|
2568 (font-lock-apply-defaults 'font-lock-add-colors font-lock-use-colors)
|
|
2569
|
|
2570 ;;;###autoload
|
|
2571 (add-minor-mode 'font-lock-mode " Font")
|
|
2572
|
|
2573 ;; Provide ourselves:
|
|
2574
|
|
2575 (provide 'font-lock)
|
|
2576
|
|
2577 ;;; font-lock.el ends here
|