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