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