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