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