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