(gnus-simplify-mode-line): New function to simplify the
[bpt/emacs.git] / lisp / font-lock.el
CommitLineData
876f2438
SM
1;;; font-lock.el --- Electric font lock mode
2
799761f0 3;; Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
030f4a35 4
9bfbb130 5;; Author: jwz, then rms, then sm <simon@gnu.ai.mit.edu>
030f4a35
RS
6;; Maintainer: FSF
7;; Keywords: languages, faces
8
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation; either version 2, or (at your option)
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs; see the file COPYING. If not, write to
23;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
030f4a35
RS
25;;; Commentary:
26
b89e1134
SM
27;; Font Lock mode is a minor mode that causes your comments to be displayed in
28;; one face, strings in another, reserved words in another, and so on.
030f4a35
RS
29;;
30;; Comments will be displayed in `font-lock-comment-face'.
31;; Strings will be displayed in `font-lock-string-face'.
a1eb1cf1 32;; Regexps are used to display selected patterns in other faces.
030f4a35 33;;
9bfbb130
SM
34;; To make the text you type be fontified, use M-x font-lock-mode RET.
35;; When this minor mode is on, the faces of the current line are updated with
36;; every insertion or deletion.
030f4a35 37;;
b89e1134 38;; To turn Font Lock mode on automatically, add this to your .emacs file:
030f4a35 39;;
b89e1134 40;; (add-hook 'emacs-lisp-mode-hook 'turn-on-font-lock)
030f4a35 41;;
9bfbb130
SM
42;; Fontification for a particular mode may be available in a number of levels
43;; of decoration. The higher the level, the more decoration, but the more time
44;; it takes to fontify. See the variable `font-lock-maximum-decoration', and
45;; also the variable `font-lock-maximum-size'.
46
b89e1134
SM
47;; If you add patterns for a new mode, say foo.el's `foo-mode', say in which
48;; you don't want syntactic fontification to occur, you can make Font Lock mode
49;; use your regexps when turning on Font Lock by adding to `foo-mode-hook':
50;;
51;; (add-hook 'foo-mode-hook
52;; '(lambda () (make-local-variable 'font-lock-defaults)
53;; (setq font-lock-defaults '(foo-font-lock-keywords t))))
54;;
a1eb1cf1
RS
55;; Nasty regexps of the form "bar\\(\\|lo\\)\\|f\\(oo\\|u\\(\\|bar\\)\\)\\|lo"
56;; are made thusly: (make-regexp '("foo" "fu" "fubar" "bar" "barlo" "lo")) for
57;; efficiency. See /pub/gnu/emacs/elisp-archive/functions/make-regexp.el.Z on
58;; archive.cis.ohio-state.edu for this and other functions.
9bfbb130
SM
59
60;; What is fontification for? You might say, "It's to make my code look nice."
61;; I think it should be for adding information in the form of cues. These cues
62;; should provide you with enough information to both (a) distinguish between
63;; different items, and (b) identify the item meanings, without having to read
64;; the items and think about it. Therefore, fontification allows you to think
65;; less about, say, the structure of code, and more about, say, why the code
66;; doesn't work. Or maybe it allows you to think less and drift off to sleep.
67;;
68;; So, here are my opinions/advice/guidelines:
69;;
70;; - Use the same face for the same conceptual object, across all modes.
71;; i.e., (b) above, all modes that have items that can be thought of as, say,
72;; keywords, should be highlighted with the same face, etc.
73;; - Keep the faces distinct from each other as far as possible.
74;; i.e., (a) above.
75;; - Make the face attributes fit the concept as far as possible.
76;; i.e., function names might be a bold colour such as blue, comments might
77;; be a bright colour such as red, character strings might be brown, because,
78;; err, strings are brown (that was not the reason, please believe me).
79;; - Don't use a non-nil OVERRIDE unless you have a good reason.
80;; Only use OVERRIDE for special things that are easy to define, such as the
81;; way `...' quotes are treated in strings and comments in Emacs Lisp mode.
82;; Don't use it to, say, highlight keywords in commented out code or strings.
83;; - Err, that's it.
a1eb1cf1 84\f
9bfbb130
SM
85;; User variables.
86
87(defvar font-lock-verbose t
88 "*If non-nil, means show status messages when fontifying.")
89
90;;;###autoload
91(defvar font-lock-maximum-decoration nil
92 "*If non-nil, the maximum decoration level for fontifying.
93If nil, use the default decoration (typically the minimum available).
94If t, use the maximum decoration available.
95If a number, use that level of decoration (or if not available the maximum).
96If a list, each element should be a cons pair of the form (MAJOR-MODE . LEVEL),
97where MAJOR-MODE is a symbol or t (meaning the default). For example:
98 ((c++-mode . 2) (c-mode . t) (t . 1))
99means use level 2 decoration for buffers in `c++-mode', the maximum decoration
100available for buffers in `c-mode', and level 1 decoration otherwise.")
030f4a35 101
9bfbb130
SM
102;;;###autoload
103(defvar font-lock-maximum-size (* 250 1024)
104 "*If non-nil, the maximum size for buffers for fontifying.
105Only buffers less than this can be fontified when Font Lock mode is turned on.
106If nil, means size is irrelevant.
107If a list, each element should be a cons pair of the form (MAJOR-MODE . SIZE),
108where MAJOR-MODE is a symbol or t (meaning the default). For example:
109 ((c++-mode . 256000) (c-mode . 256000) (rmail-mode . 1048576))
110means that the maximum size is 250K for buffers in `c++-mode' or `c-mode', one
111megabyte for buffers in `rmail-mode', and size is irrelevant otherwise.")
112\f
113;; Fontification variables:
114
115(defvar font-lock-comment-face 'font-lock-comment-face
a1eb1cf1 116 "Face to use for comments.")
030f4a35 117
9bfbb130 118(defvar font-lock-string-face 'font-lock-string-face
a1eb1cf1 119 "Face to use for strings.")
030f4a35 120
9bfbb130
SM
121(defvar font-lock-keyword-face 'font-lock-keyword-face
122 "Face to use for keywords.")
123
124(defvar font-lock-function-name-face 'font-lock-function-name-face
030f4a35
RS
125 "Face to use for function names.")
126
9bfbb130 127(defvar font-lock-variable-name-face 'font-lock-variable-name-face
a1eb1cf1
RS
128 "Face to use for variable names.")
129
9bfbb130
SM
130(defvar font-lock-type-face 'font-lock-type-face
131 "Face to use for type names.")
030f4a35 132
9bfbb130
SM
133(defvar font-lock-reference-face 'font-lock-reference-face
134 "Face to use for reference names.")
a1eb1cf1 135
030f4a35 136(defvar font-lock-keywords nil
d46c21ec
SM
137 "*A list of the keywords to highlight.
138Each element should be of the form:
a1eb1cf1 139
826b2925
SM
140 MATCHER
141 (MATCHER . MATCH)
142 (MATCHER . FACENAME)
143 (MATCHER . HIGHLIGHT)
144 (MATCHER HIGHLIGHT ...)
a1eb1cf1 145
9bfbb130
SM
146where HIGHLIGHT should be either MATCH-HIGHLIGHT or MATCH-ANCHORED.
147
148For highlighting single items, typically only MATCH-HIGHLIGHT is required.
149However, if an item or (typically) items is to be hightlighted following the
150instance of another item (the anchor) then MATCH-ANCHORED may be required.
151
152MATCH-HIGHLIGHT should be of the form:
153
154 (MATCH FACENAME OVERRIDE LAXMATCH)
155
156Where MATCHER can be either the regexp to search for, or the function name to
157call to make the search (called with one argument, the limit of the search).
158MATCH is the subexpression of MATCHER to be highlighted. FACENAME is an
159expression whose value is the face name to use. FACENAME's default attributes
160may be defined in `font-lock-face-attributes'.
a1eb1cf1
RS
161
162OVERRIDE and LAXMATCH are flags. If OVERRIDE is t, existing fontification may
9bfbb130
SM
163be overwritten. If `keep', only parts not already fontified are highlighted.
164If `prepend' or `append', existing fontification is merged with the new, in
165which the new or existing fontification, respectively, takes precedence.
826b2925 166If LAXMATCH is non-nil, no error is signalled if there is no MATCH in MATCHER.
a1eb1cf1 167
9bfbb130
SM
168For example, an element of the form highlights (if not already highlighted):
169
876f2438
SM
170 \"\\\\\\=<foo\\\\\\=>\" Discrete occurrences of \"foo\" in the value of the
171 variable `font-lock-keyword-face'.
9bfbb130
SM
172 (\"fu\\\\(bar\\\\)\" . 1) Substring \"bar\" within all occurrences of \"fubar\" in
173 the value of `font-lock-keyword-face'.
174 (\"fubar\" . fubar-face) Occurrences of \"fubar\" in the value of `fubar-face'.
175 (\"foo\\\\|bar\" 0 foo-bar-face t)
176 Occurrences of either \"foo\" or \"bar\" in the value
177 of `foo-bar-face', even if already highlighted.
178
179MATCH-ANCHORED should be of the form:
180
181 (MATCHER PRE-MATCH-FORM POST-MATCH-FORM MATCH-HIGHLIGHT ...)
182
876f2438
SM
183Where MATCHER is as for MATCH-HIGHLIGHT with one exception. The limit of the
184search is currently guaranteed to be (no greater than) the end of the line.
185PRE-MATCH-FORM and POST-MATCH-FORM are evaluated before the first, and after
186the last, instance MATCH-ANCHORED's MATCHER is used. Therefore they can be
187used to initialise before, and cleanup after, MATCHER is used. Typically,
188PRE-MATCH-FORM is used to move to some position relative to the original
189MATCHER, before starting with MATCH-ANCHORED's MATCHER. POST-MATCH-FORM might
190be used to move, before resuming with MATCH-ANCHORED's parent's MATCHER.
9bfbb130
SM
191
192For example, an element of the form highlights (if not already highlighted):
193
876f2438 194 (\"\\\\\\=<anchor\\\\\\=>\" (0 anchor-face) (\"\\\\\\=<item\\\\\\=>\" nil nil (0 item-face)))
9bfbb130 195
876f2438
SM
196 Discrete occurrences of \"anchor\" in the value of `anchor-face', and subsequent
197 discrete occurrences of \"item\" (on the same line) in the value of `item-face'.
198 (Here PRE-MATCH-FORM and POST-MATCH-FORM are nil. Therefore \"item\" is
199 initially searched for starting from the end of the match of \"anchor\", and
200 searching for subsequent instance of \"anchor\" resumes from where searching
201 for \"item\" concluded.)
9bfbb130
SM
202
203Note that the MATCH-ANCHORED feature is experimental; in the future, we may
204replace it with other ways of providing this functionality.
205
a1eb1cf1
RS
206These regular expressions should not match text which spans lines. While
207\\[font-lock-fontify-buffer] handles multi-line patterns correctly, updating
208when you edit the buffer does not, since it considers text one line at a time.
209
9bfbb130 210Be very careful composing regexps for this list;
a1eb1cf1 211the wrong pattern can dramatically slow things down!")
9bfbb130 212(make-variable-buffer-local 'font-lock-keywords)
030f4a35 213
b89e1134
SM
214(defvar font-lock-defaults nil
215 "If set by a major mode, should be the defaults for Font Lock mode.
9bfbb130 216The value should be like the `cdr' of an item in `font-lock-defaults-alist'.")
b89e1134
SM
217
218(defvar font-lock-defaults-alist
9bfbb130
SM
219 (let (;; For C and Lisp modes we use `beginning-of-defun', rather than nil,
220 ;; for SYNTAX-BEGIN. Thus the calculation of the cache is usually
221 ;; faster but not infallible, so we risk mis-fontification. --sm.
fb512de9 222 (c-mode-defaults
9bfbb130
SM
223 '((c-font-lock-keywords c-font-lock-keywords-1
224 c-font-lock-keywords-2 c-font-lock-keywords-3)
225 nil nil ((?_ . "w")) beginning-of-defun))
fb512de9
SM
226 (c++-mode-defaults
227 '((c++-font-lock-keywords c++-font-lock-keywords-1
9bfbb130
SM
228 c++-font-lock-keywords-2 c++-font-lock-keywords-3)
229 nil nil ((?_ . "w") (?~ . "w")) beginning-of-defun))
fb512de9 230 (lisp-mode-defaults
9bfbb130
SM
231 '((lisp-font-lock-keywords
232 lisp-font-lock-keywords-1 lisp-font-lock-keywords-2)
233 nil nil
234 ((?: . "w") (?- . "w") (?* . "w") (?+ . "w") (?. . "w") (?< . "w")
235 (?> . "w") (?= . "w") (?! . "w") (?? . "w") (?$ . "w") (?% . "w")
236 (?_ . "w") (?& . "w") (?~ . "w") (?^ . "w") (?/ . "w"))
d46c21ec
SM
237 beginning-of-defun))
238 (scheme-mode-defaults
9bfbb130
SM
239 '(scheme-font-lock-keywords nil t
240 ((?: . "w") (?- . "w") (?* . "w") (?+ . "w") (?. . "w") (?< . "w")
241 (?> . "w") (?= . "w") (?! . "w") (?? . "w") (?$ . "w") (?% . "w")
242 (?_ . "w") (?& . "w") (?~ . "w") (?^ . "w") (?/ . "w"))
d46c21ec
SM
243 beginning-of-defun))
244 ;; For TeX modes we could use `backward-paragraph' for the same reason.
9bfbb130 245 (tex-mode-defaults '(tex-font-lock-keywords nil nil ((?$ . "\""))))
d46c21ec 246 )
826b2925 247 (list
d46c21ec
SM
248 (cons 'bibtex-mode tex-mode-defaults)
249 (cons 'c++-c-mode c-mode-defaults)
250 (cons 'c++-mode c++-mode-defaults)
251 (cons 'c-mode c-mode-defaults)
9bfbb130 252 (cons 'elec-c-mode c-mode-defaults)
d46c21ec
SM
253 (cons 'emacs-lisp-mode lisp-mode-defaults)
254 (cons 'inferior-scheme-mode scheme-mode-defaults)
255 (cons 'latex-mode tex-mode-defaults)
256 (cons 'lisp-mode lisp-mode-defaults)
257 (cons 'lisp-interaction-mode lisp-mode-defaults)
258 (cons 'plain-tex-mode tex-mode-defaults)
259 (cons 'scheme-mode scheme-mode-defaults)
260 (cons 'scheme-interaction-mode scheme-mode-defaults)
261 (cons 'slitex-mode tex-mode-defaults)
262 (cons 'tex-mode tex-mode-defaults)))
9bfbb130 263 "Alist of default major mode and Font Lock defaults.
b89e1134 264Each item should be a list of the form:
d46c21ec
SM
265
266 (MAJOR-MODE . (KEYWORDS KEYWORDS-ONLY CASE-FOLD SYNTAX-ALIST SYNTAX-BEGIN))
267
9bfbb130
SM
268where MAJOR-MODE is a symbol. KEYWORDS may be a symbol (a variable or function
269whose value is the keywords to use for fontification) or a list of symbols.
270If KEYWORDS-ONLY is non-nil, syntactic fontification (strings and comments) is
271not performed. If CASE-FOLD is non-nil, the case of the keywords is ignored
272when fontifying. If SYNTAX-ALIST is non-nil, it should be a list of cons pairs
273of the form (CHAR . STRING) used to set the local Font Lock syntax table, for
274keyword and syntactic fontification (see `modify-syntax-entry').
275
276If SYNTAX-BEGIN is non-nil, it should be a function with no args used to move
277backwards outside any enclosing syntactic block, for syntactic fontification.
278Typical values are `beginning-of-line' (i.e., the start of the line is known to
279be outside a syntactic block), or `beginning-of-defun' for programming modes or
280`backward-paragraph' for textual modes (i.e., the mode-dependent function is
281known to move outside a syntactic block). If nil, the beginning of the buffer
282is used as a position outside of a syntactic block, in the worst case.
d46c21ec
SM
283
284These item elements are used by Font Lock mode to set the variables
9bfbb130 285`font-lock-keywords', `font-lock-keywords-only',
d46c21ec
SM
286`font-lock-keywords-case-fold-search', `font-lock-syntax-table' and
287`font-lock-beginning-of-syntax-function', respectively.")
288
9bfbb130 289(defvar font-lock-keywords-only nil
d46c21ec
SM
290 "*Non-nil means Font Lock should not fontify comments or strings.
291This is normally set via `font-lock-defaults'.")
b89e1134 292
030f4a35 293(defvar font-lock-keywords-case-fold-search nil
d46c21ec
SM
294 "*Non-nil means the patterns in `font-lock-keywords' are case-insensitive.
295This is normally set via `font-lock-defaults'.")
030f4a35 296
b056da51 297(defvar font-lock-syntax-table nil
799761f0 298 "Non-nil means use this syntax table for fontifying.
d46c21ec
SM
299If this is nil, the major mode's syntax table is used.
300This is normally set via `font-lock-defaults'.")
301
9bfbb130
SM
302;; If this is nil, we only use the beginning of the buffer if we can't use
303;; `font-lock-cache-position' and `font-lock-cache-state'.
d46c21ec 304(defvar font-lock-beginning-of-syntax-function nil
9bfbb130
SM
305 "*Non-nil means use this function to move back outside of a syntactic block.
306If this is nil, the beginning of the buffer is used (in the worst case).
d46c21ec 307This is normally set via `font-lock-defaults'.")
b056da51 308
9bfbb130
SM
309;; These record the parse state at a particular position, always the start of a
310;; line. Used to make `font-lock-fontify-syntactically-region' faster.
030f4a35
RS
311(defvar font-lock-cache-position nil)
312(defvar font-lock-cache-state nil)
313(make-variable-buffer-local 'font-lock-cache-position)
314(make-variable-buffer-local 'font-lock-cache-state)
315
9bfbb130
SM
316(defvar font-lock-mode nil) ; For the modeline.
317(defvar font-lock-fontified nil) ; Whether we have fontified the buffer.
318(put 'font-lock-fontified 'permanent-local t)
826b2925 319
9bfbb130
SM
320;;;###autoload
321(defvar font-lock-mode-hook nil
322 "Function or functions to run on entry to Font Lock mode.")
030f4a35 323\f
9bfbb130 324;; User functions.
030f4a35
RS
325
326;;;###autoload
327(defun font-lock-mode (&optional arg)
e595fa35 328 "Toggle Font Lock mode.
030f4a35
RS
329With arg, turn Font Lock mode on if and only if arg is positive.
330
331When Font Lock mode is enabled, text is fontified as you type it:
332
a1eb1cf1
RS
333 - Comments are displayed in `font-lock-comment-face';
334 - Strings are displayed in `font-lock-string-face';
335 - Certain other expressions are displayed in other faces according to the
336 value of the variable `font-lock-keywords'.
337
338You can enable Font Lock mode in any major mode automatically by turning on in
339the major mode's hook. For example, put in your ~/.emacs:
340
341 (add-hook 'c-mode-hook 'turn-on-font-lock)
342
343Or for any visited file with the following in your ~/.emacs:
344
345 (add-hook 'find-file-hooks 'turn-on-font-lock)
346
347The default Font Lock mode faces and their attributes are defined in the
348variable `font-lock-face-attributes', and Font Lock mode default settings in
9bfbb130
SM
349the variable `font-lock-defaults-alist'. You can set your own default settings
350for some mode, by setting a buffer local value for `font-lock-defaults', via
351its mode hook.
030f4a35 352
826b2925 353Where modes support different levels of fontification, you can use the variable
fb512de9 354`font-lock-maximum-decoration' to specify which level you generally prefer.
b89e1134
SM
355When you turn Font Lock mode on/off the buffer is fontified/defontified, though
356fontification occurs only if the buffer is less than `font-lock-maximum-size'.
357To fontify a buffer without turning on Font Lock mode, and regardless of buffer
358size, you can use \\[font-lock-fontify-buffer]."
030f4a35 359 (interactive "P")
9bfbb130
SM
360 (let ((on-p (if arg (> (prefix-numeric-value arg) 0) (not font-lock-mode)))
361 (maximum-size (if (not (consp font-lock-maximum-size))
362 font-lock-maximum-size
363 (cdr (or (assq major-mode font-lock-maximum-size)
364 (assq t font-lock-maximum-size))))))
030f4a35
RS
365 (if (equal (buffer-name) " *Compiler Input*") ; hack for bytecomp...
366 (setq on-p nil))
a1eb1cf1 367 (if (not on-p)
876f2438
SM
368 (remove-hook 'after-change-functions 'font-lock-after-change-function
369 t)
370 (make-local-hook 'after-change-functions)
371 (add-hook 'after-change-functions 'font-lock-after-change-function
372 nil t))
030f4a35
RS
373 (set (make-local-variable 'font-lock-mode) on-p)
374 (cond (on-p
375 (font-lock-set-defaults)
876f2438
SM
376 (make-local-hook 'before-revert-hook)
377 (make-local-hook 'after-revert-hook)
7daa8d6b 378 ;; If buffer is reverted, must clean up the state.
876f2438
SM
379 (add-hook 'before-revert-hook 'font-lock-revert-setup nil t)
380 (add-hook 'after-revert-hook 'font-lock-revert-cleanup nil t)
030f4a35 381 (run-hooks 'font-lock-mode-hook)
b89e1134
SM
382 (cond (font-lock-fontified
383 nil)
9bfbb130 384 ((or (null maximum-size) (<= (buffer-size) maximum-size))
b89e1134
SM
385 (font-lock-fontify-buffer))
386 (font-lock-verbose
387 (message "Fontifying %s... buffer too big." (buffer-name)))))
030f4a35
RS
388 (font-lock-fontified
389 (setq font-lock-fontified nil)
876f2438
SM
390 (remove-hook 'before-revert-hook 'font-lock-revert-setup t)
391 (remove-hook 'after-revert-hook 'font-lock-revert-cleanup t)
799761f0
SM
392 (font-lock-unfontify-region (point-min) (point-max))
393 (font-lock-thing-lock-cleanup))
394 (t
876f2438
SM
395 (remove-hook 'before-revert-hook 'font-lock-revert-setup t)
396 (remove-hook 'after-revert-hook 'font-lock-revert-cleanup t)
799761f0 397 (font-lock-thing-lock-cleanup)))
030f4a35
RS
398 (force-mode-line-update)))
399
a1eb1cf1
RS
400;;;###autoload
401(defun turn-on-font-lock ()
402 "Unconditionally turn on Font Lock mode."
403 (font-lock-mode 1))
404
a1eb1cf1 405;;;###autoload
030f4a35 406(defun font-lock-fontify-buffer ()
a1eb1cf1 407 "Fontify the current buffer the way `font-lock-mode' would."
030f4a35 408 (interactive)
9bfbb130 409 (let ((verbose (and (or font-lock-verbose (interactive-p))
876f2438 410 (not (zerop (buffer-size))))))
b89e1134 411 (set (make-local-variable 'font-lock-fontified) nil)
a1eb1cf1 412 (if verbose (message "Fontifying %s..." (buffer-name)))
b89e1134 413 ;; Turn it on to run hooks and get the right `font-lock-keywords' etc.
9bfbb130 414 (or font-lock-mode (font-lock-set-defaults))
a1eb1cf1
RS
415 (condition-case nil
416 (save-excursion
876f2438
SM
417 (save-match-data
418 (font-lock-fontify-region (point-min) (point-max) verbose)
419 (setq font-lock-fontified t)))
a1eb1cf1 420 ;; We don't restore the old fontification, so it's best to unfontify.
b89e1134 421 (quit (font-lock-unfontify-region (point-min) (point-max))))
a1eb1cf1
RS
422 (if verbose (message "Fontifying %s... %s." (buffer-name)
423 (if font-lock-fontified "done" "aborted")))
826b2925 424 (font-lock-after-fontify-buffer)))
9bfbb130
SM
425\f
426;; Fontification functions.
427
428;; We use this wrapper. However, `font-lock-fontify-region' used to be the
429;; name used for `font-lock-fontify-syntactically-region', so a change isn't
430;; back-compatible. But you shouldn't be calling these directly, should you?
431(defun font-lock-fontify-region (beg end &optional loudly)
876f2438
SM
432 (let ((modified (buffer-modified-p))
433 (buffer-undo-list t) (inhibit-read-only t)
434 (old-syntax-table (syntax-table))
435 buffer-file-name buffer-file-truename)
436 (unwind-protect
437 (progn
438 ;; Use the fontification syntax table, if any.
439 (if font-lock-syntax-table (set-syntax-table font-lock-syntax-table))
440 ;; Now do the fontification.
441 (if font-lock-keywords-only
442 (font-lock-unfontify-region beg end)
443 (font-lock-fontify-syntactically-region beg end loudly))
444 (font-lock-fontify-keywords-region beg end loudly))
445 ;; Clean up.
446 (set-syntax-table old-syntax-table)
447 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil)))))
9bfbb130
SM
448
449;; The following must be rethought, since keywords can override fontification.
450; ;; Now scan for keywords, but not if we are inside a comment now.
451; (or (and (not font-lock-keywords-only)
452; (let ((state (parse-partial-sexp beg end nil nil
453; font-lock-cache-state)))
454; (or (nth 4 state) (nth 7 state))))
455; (font-lock-fontify-keywords-region beg end))
456
457(defun font-lock-unfontify-region (beg end)
458 (let ((modified (buffer-modified-p))
459 (buffer-undo-list t) (inhibit-read-only t)
460 buffer-file-name buffer-file-truename)
461 (remove-text-properties beg end '(face nil))
876f2438 462 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil))))
9bfbb130
SM
463
464;; Called when any modification is made to buffer text.
465(defun font-lock-after-change-function (beg end old-len)
466 (save-excursion
467 (save-match-data
468 ;; Rescan between start of line from `beg' and start of line after `end'.
469 (font-lock-fontify-region
470 (progn (goto-char beg) (beginning-of-line) (point))
471 (progn (goto-char end) (forward-line 1) (point))))))
472\f
473;; Syntactic fontification functions.
474
475(defun font-lock-fontify-syntactically-region (start end &optional loudly)
476 "Put proper face on each string and comment between START and END.
477START should be at the beginning of a line."
876f2438 478 (let ((synstart (if comment-start-skip
9bfbb130
SM
479 (concat "\\s\"\\|" comment-start-skip)
480 "\\s\""))
481 (comstart (if comment-start-skip
482 (concat "\\s<\\|" comment-start-skip)
483 "\\s<"))
9bfbb130
SM
484 state prev prevstate)
485 (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name)))
876f2438
SM
486 (save-restriction
487 (widen)
488 (goto-char start)
489 ;;
490 ;; Find the state at the `beginning-of-line' before `start'.
491 (if (eq start font-lock-cache-position)
492 ;; Use the cache for the state of `start'.
493 (setq state font-lock-cache-state)
494 ;; Find the state of `start'.
495 (if (null font-lock-beginning-of-syntax-function)
496 ;; Use the state at the previous cache position, if any, or
497 ;; otherwise calculate from `point-min'.
498 (if (or (null font-lock-cache-position)
499 (< start font-lock-cache-position))
500 (setq state (parse-partial-sexp (point-min) start))
501 (setq state (parse-partial-sexp font-lock-cache-position start
502 nil nil font-lock-cache-state)))
503 ;; Call the function to move outside any syntactic block.
504 (funcall font-lock-beginning-of-syntax-function)
505 (setq state (parse-partial-sexp (point) start)))
506 ;; Cache the state and position of `start'.
507 (setq font-lock-cache-state state
508 font-lock-cache-position start))
509 ;;
510 ;; If the region starts inside a string, show the extent of it.
511 (if (nth 3 state)
512 (let ((beg (point)))
513 (while (and (re-search-forward "\\s\"" end 'move)
514 (nth 3 (parse-partial-sexp beg (point)
515 nil nil state))))
516 (put-text-property beg (point) 'face font-lock-string-face)
517 (setq state (parse-partial-sexp beg (point) nil nil state))))
518 ;;
519 ;; Likewise for a comment.
520 (if (or (nth 4 state) (nth 7 state))
521 (let ((beg (point)))
522 (save-restriction
523 (narrow-to-region (point-min) end)
524 (condition-case nil
525 (progn
526 (re-search-backward comstart (point-min) 'move)
527 (forward-comment 1)
528 ;; forward-comment skips all whitespace,
529 ;; so go back to the real end of the comment.
530 (skip-chars-backward " \t"))
531 (error (goto-char end))))
532 (put-text-property beg (point) 'face font-lock-comment-face)
533 (setq state (parse-partial-sexp beg (point) nil nil state))))
534 ;;
535 ;; Find each interesting place between here and `end'.
536 (while (and (< (point) end)
537 (setq prev (point) prevstate state)
538 (re-search-forward synstart end t)
539 (progn
540 ;; Clear out the fonts of what we skip over.
541 (remove-text-properties prev (point) '(face nil))
542 ;; Verify the state at that place
543 ;; so we don't get fooled by \" or \;.
544 (setq state (parse-partial-sexp prev (point)
545 nil nil state))))
546 (let ((here (point)))
547 (if (or (nth 4 state) (nth 7 state))
548 ;;
549 ;; We found a real comment start.
550 (let ((beg (match-beginning 0)))
551 (goto-char beg)
552 (save-restriction
553 (narrow-to-region (point-min) end)
554 (condition-case nil
555 (progn
556 (forward-comment 1)
557 ;; forward-comment skips all whitespace,
558 ;; so go back to the real end of the comment.
559 (skip-chars-backward " \t"))
560 (error (goto-char end))))
561 (put-text-property beg (point) 'face
562 font-lock-comment-face)
563 (setq state (parse-partial-sexp here (point) nil nil state)))
564 (if (nth 3 state)
9bfbb130 565 ;;
876f2438 566 ;; We found a real string start.
9bfbb130 567 (let ((beg (match-beginning 0)))
876f2438
SM
568 (while (and (re-search-forward "\\s\"" end 'move)
569 (nth 3 (parse-partial-sexp here (point)
570 nil nil state))))
571 (put-text-property beg (point) 'face font-lock-string-face)
572 (setq state (parse-partial-sexp here (point)
573 nil nil state))))))
574 ;;
575 ;; Make sure `prev' is non-nil after the loop
576 ;; only if it was set on the very last iteration.
577 (setq prev nil)))
578 ;;
579 ;; Clean up.
580 (and prev (remove-text-properties prev end '(face nil)))))
9bfbb130
SM
581\f
582;;; Additional text property functions.
583
584;; The following three text property functions are not generally available (and
585;; it's not certain that they should be) so they are inlined for speed.
586;; The case for `fillin-text-property' is simple; it may or not be generally
587;; useful. (Since it is used here, it is useful in at least one place.;-)
588;; However, the case for `append-text-property' and `prepend-text-property' is
589;; more complicated. Should they remove duplicate property values or not? If
590;; so, should the first or last duplicate item remain? Or the one that was
591;; added? In our implementation, the first duplicate remains.
592
593(defsubst font-lock-fillin-text-property (start end prop value &optional object)
594 "Fill in one property of the text from START to END.
595Arguments PROP and VALUE specify the property and value to put where none are
596already in place. Therefore existing property values are not overwritten.
597Optional argument OBJECT is the string or buffer containing the text."
598 (let ((start (text-property-any start end prop nil object)) next)
599 (while start
600 (setq next (next-single-property-change start prop object end))
601 (put-text-property start next prop value object)
602 (setq start (text-property-any next end prop nil object)))))
603
604;; This function (from simon's unique.el) is rewritten and inlined for speed.
605;(defun unique (list function)
606; "Uniquify LIST, deleting elements using FUNCTION.
607;Return the list with subsequent duplicate items removed by side effects.
608;FUNCTION is called with an element of LIST and a list of elements from LIST,
609;and should return the list of elements with occurrences of the element removed,
610;i.e., a function such as `delete' or `delq'.
611;This function will work even if LIST is unsorted. See also `uniq'."
612; (let ((list list))
613; (while list
614; (setq list (setcdr list (funcall function (car list) (cdr list))))))
615; list)
616
617(defsubst font-lock-unique (list)
618 "Uniquify LIST, deleting elements using `delq'.
619Return the list with subsequent duplicate items removed by side effects."
620 (let ((list list))
621 (while list
622 (setq list (setcdr list (delq (car list) (cdr list))))))
623 list)
624
625;; A generalisation of `facemenu-add-face' for any property, but without the
626;; removal of inactive faces via `facemenu-discard-redundant-faces' and special
627;; treatment of `default'. Uses `unique' to remove duplicate property values.
628(defsubst font-lock-prepend-text-property (start end prop value &optional object)
629 "Prepend to one property of the text from START to END.
630Arguments PROP and VALUE specify the property and value to prepend to the value
631already in place. The resulting property values are always lists, and unique.
632Optional argument OBJECT is the string or buffer containing the text."
633 (let ((val (if (listp value) value (list value))) next prev)
634 (while (/= start end)
635 (setq next (next-single-property-change start prop object end)
636 prev (get-text-property start prop object))
637 (put-text-property
638 start next prop
639 (font-lock-unique (append val (if (listp prev) prev (list prev))))
640 object)
641 (setq start next))))
642
643(defsubst font-lock-append-text-property (start end prop value &optional object)
644 "Append to one property of the text from START to END.
645Arguments PROP and VALUE specify the property and value to append to the value
646already in place. The resulting property values are always lists, and unique.
647Optional argument OBJECT is the string or buffer containing the text."
648 (let ((val (if (listp value) value (list value))) next prev)
649 (while (/= start end)
650 (setq next (next-single-property-change start prop object end)
651 prev (get-text-property start prop object))
652 (put-text-property
653 start next prop
654 (font-lock-unique (append (if (listp prev) prev (list prev)) val))
655 object)
656 (setq start next))))
657\f
658;;; Regexp fontification functions.
659
660(defsubst font-lock-apply-highlight (highlight)
661 "Apply HIGHLIGHT following a match.
662HIGHLIGHT should be of the form MATCH-HIGHLIGHT, see `font-lock-keywords'."
663 (let* ((match (nth 0 highlight))
664 (start (match-beginning match)) (end (match-end match))
665 (override (nth 2 highlight)))
666 (cond ((not start)
667 ;; No match but we might not signal an error.
668 (or (nth 3 highlight)
669 (error "No match %d in highlight %S" match highlight)))
670 ((not override)
671 ;; Cannot override existing fontification.
672 (or (text-property-not-all start end 'face nil)
673 (put-text-property start end 'face (eval (nth 1 highlight)))))
674 ((eq override t)
675 ;; Override existing fontification.
676 (put-text-property start end 'face (eval (nth 1 highlight))))
677 ((eq override 'keep)
678 ;; Keep existing fontification.
679 (font-lock-fillin-text-property start end 'face
680 (eval (nth 1 highlight))))
681 ((eq override 'prepend)
682 ;; Prepend to existing fontification.
683 (font-lock-prepend-text-property start end 'face
684 (eval (nth 1 highlight))))
685 ((eq override 'append)
686 ;; Append to existing fontification.
687 (font-lock-append-text-property start end 'face
688 (eval (nth 1 highlight)))))))
689
690(defsubst font-lock-fontify-anchored-keywords (keywords limit)
691 "Fontify according to KEYWORDS until LIMIT.
692KEYWORDS should be of the form MATCH-ANCHORED, see `font-lock-keywords'."
693 (let ((matcher (nth 0 keywords)) (lowdarks (nthcdr 3 keywords)) highlights)
876f2438
SM
694 ;; Until we come up with a cleaner solution, we make LIMIT the end of line.
695 (save-excursion (end-of-line) (setq limit (min limit (point))))
696 ;; Evaluate PRE-MATCH-FORM.
9bfbb130
SM
697 (eval (nth 1 keywords))
698 (save-match-data
876f2438 699 ;; Find an occurrence of `matcher' before `limit'.
9bfbb130
SM
700 (while (if (stringp matcher)
701 (re-search-forward matcher limit t)
702 (funcall matcher limit))
876f2438 703 ;; Apply each highlight to this instance of `matcher'.
9bfbb130
SM
704 (setq highlights lowdarks)
705 (while highlights
706 (font-lock-apply-highlight (car highlights))
707 (setq highlights (cdr highlights)))))
876f2438 708 ;; Evaluate POST-MATCH-FORM.
9bfbb130
SM
709 (eval (nth 2 keywords))))
710
711(defun font-lock-fontify-keywords-region (start end &optional loudly)
712 "Fontify according to `font-lock-keywords' between START and END.
713START should be at the beginning of a line."
714 (let ((case-fold-search font-lock-keywords-case-fold-search)
715 (keywords (cdr (if (eq (car-safe font-lock-keywords) t)
716 font-lock-keywords
717 (font-lock-compile-keywords))))
9bfbb130 718 (bufname (buffer-name)) (count 0)
876f2438
SM
719 keyword matcher highlights)
720 ;;
721 ;; Fontify each item in `font-lock-keywords' from `start' to `end'.
722 (while keywords
723 (if loudly (message "Fontifying %s... (regexps..%s)" bufname
724 (make-string (setq count (1+ count)) ?.)))
9bfbb130 725 ;;
876f2438
SM
726 ;; Find an occurrence of `matcher' from `start' to `end'.
727 (setq keyword (car keywords) matcher (car keyword))
728 (goto-char start)
729 (while (if (stringp matcher)
730 (re-search-forward matcher end t)
731 (funcall matcher end))
732 ;; Apply each highlight to this instance of `matcher', which may be
733 ;; specific highlights or more keywords anchored to `matcher'.
734 (setq highlights (cdr keyword))
735 (while highlights
736 (if (numberp (car (car highlights)))
737 (font-lock-apply-highlight (car highlights))
738 (font-lock-fontify-anchored-keywords (car highlights) end))
739 (setq highlights (cdr highlights))))
740 (setq keywords (cdr keywords)))))
9bfbb130
SM
741\f
742;; Various functions.
743
744;; Turn off other related packages if they're on. I prefer a hook. --sm.
745;; These explicit calls are easier to understand
746;; because people know what they will do.
747;; A hook is a mystery because it might do anything whatever. --rms.
748(defun font-lock-thing-lock-cleanup ()
749 (cond ((and (boundp 'fast-lock-mode) fast-lock-mode)
750 (fast-lock-mode -1))
751 ((and (boundp 'lazy-lock-mode) lazy-lock-mode)
752 (lazy-lock-mode -1))))
753
754;; Do something special for these packages after fontifying. I prefer a hook.
755(defun font-lock-after-fontify-buffer ()
756 (cond ((and (boundp 'fast-lock-mode) fast-lock-mode)
757 (fast-lock-after-fontify-buffer))
758 ((and (boundp 'lazy-lock-mode) lazy-lock-mode)
759 (lazy-lock-after-fontify-buffer))))
760
761;; If the buffer is about to be reverted, it won't be fontified afterward.
762(defun font-lock-revert-setup ()
763 (setq font-lock-fontified nil))
764
765;; If the buffer has just been reverted, normally that turns off
766;; Font Lock mode. So turn the mode back on if necessary.
767(defalias 'font-lock-revert-cleanup 'turn-on-font-lock)
768
769(defun font-lock-compile-keywords (&optional keywords)
770 ;; Compile `font-lock-keywords' into the form (t KEYWORD ...) where KEYWORD
771 ;; is the (MATCHER HIGHLIGHT ...) shown in the variable's doc string.
772 (let ((keywords (or keywords font-lock-keywords)))
773 (setq font-lock-keywords
774 (if (eq (car-safe keywords) t)
775 keywords
776 (cons t
777 (mapcar
778 (function (lambda (item)
779 (cond ((nlistp item)
780 (list item '(0 font-lock-keyword-face)))
781 ((numberp (cdr item))
782 (list (car item) (list (cdr item) 'font-lock-keyword-face)))
783 ((symbolp (cdr item))
784 (list (car item) (list 0 (cdr item))))
785 ((nlistp (nth 1 item))
786 (list (car item) (cdr item)))
787 (t
788 item))))
789 keywords))))))
d46c21ec
SM
790
791(defun font-lock-choose-keywords (keywords level)
792 ;; Return LEVELth element of KEYWORDS. A LEVEL of nil is equal to a
793 ;; LEVEL of 0, a LEVEL of t is equal to (1- (length KEYWORDS)).
9bfbb130
SM
794 (let ((level (if (not (consp level))
795 level
796 (cdr (or (assq major-mode level) (assq t level))))))
797 (cond ((symbolp keywords)
798 keywords)
799 ((numberp level)
800 (or (nth level keywords) (car (reverse keywords))))
801 ((eq level t)
802 (car (reverse keywords)))
803 (t
804 (car keywords)))))
d46c21ec
SM
805
806(defun font-lock-set-defaults ()
807 "Set fontification defaults appropriately for this mode.
9bfbb130
SM
808Sets `font-lock-keywords', `font-lock-keywords-only', `font-lock-syntax-table',
809`font-lock-beginning-of-syntax-function' and
810`font-lock-keywords-case-fold-search' using `font-lock-defaults' (or, if nil,
811using `font-lock-defaults-alist') and `font-lock-maximum-decoration'."
d46c21ec
SM
812 ;; Set face defaults.
813 (font-lock-make-faces)
814 ;; Set fontification defaults.
815 (or font-lock-keywords
9bfbb130
SM
816 (let* ((defaults (or font-lock-defaults
817 (cdr (assq major-mode font-lock-defaults-alist))))
818 (keywords (font-lock-choose-keywords
819 (nth 0 defaults) font-lock-maximum-decoration)))
d46c21ec 820 ;; Keywords?
9bfbb130
SM
821 (setq font-lock-keywords (if (fboundp keywords)
822 (funcall keywords)
823 (eval keywords)))
d46c21ec
SM
824 ;; Syntactic?
825 (if (nth 1 defaults)
9bfbb130 826 (set (make-local-variable 'font-lock-keywords-only) t))
d46c21ec
SM
827 ;; Case fold?
828 (if (nth 2 defaults)
829 (set (make-local-variable 'font-lock-keywords-case-fold-search) t))
830 ;; Syntax table?
831 (if (nth 3 defaults)
832 (let ((slist (nth 3 defaults)))
833 (set (make-local-variable 'font-lock-syntax-table)
834 (copy-syntax-table (syntax-table)))
835 (while slist
836 (modify-syntax-entry (car (car slist)) (cdr (car slist))
837 font-lock-syntax-table)
838 (setq slist (cdr slist)))))
9bfbb130 839 ;; Syntax function?
d46c21ec
SM
840 (if (nth 4 defaults)
841 (set (make-local-variable 'font-lock-beginning-of-syntax-function)
842 (nth 4 defaults))))))
030f4a35 843\f
9bfbb130
SM
844;; Colour etc. support.
845
846(defvar font-lock-display-type nil
847 "A symbol indicating the display Emacs is running under.
848The symbol should be one of `color', `grayscale' or `mono'.
849If Emacs guesses this display attribute wrongly, either set this variable in
850your `~/.emacs' or set the resource `Emacs.displayType' in your `~/.Xdefaults'.
851See also `font-lock-background-mode' and `font-lock-face-attributes'.")
852
853(defvar font-lock-background-mode nil
854 "A symbol indicating the Emacs background brightness.
855The symbol should be one of `light' or `dark'.
856If Emacs guesses this frame attribute wrongly, either set this variable in
857your `~/.emacs' or set the resource `Emacs.backgroundMode' in your
858`~/.Xdefaults'.
859See also `font-lock-display-type' and `font-lock-face-attributes'.")
860
861(defvar font-lock-face-attributes nil
862 "A list of default attributes to use for face attributes.
863Each element of the list should be of the form
864
865 (FACE FOREGROUND BACKGROUND BOLD-P ITALIC-P UNDERLINE-P)
866
867where FACE should be one of the face symbols `font-lock-comment-face',
868`font-lock-string-face', `font-lock-keyword-face', `font-lock-type-face',
869`font-lock-function-name-face', `font-lock-variable-name-face', and
870`font-lock-reference-face'. A form for each of these face symbols should be
871provided in the list, but other face symbols and attributes may be given and
872used in highlighting. See `font-lock-keywords'.
873
874Subsequent element items should be the attributes for the corresponding
875Font Lock mode faces. Attributes FOREGROUND and BACKGROUND should be strings
876\(default if nil), while BOLD-P, ITALIC-P, and UNDERLINE-P should specify the
877corresponding face attributes (yes if non-nil).
878
879Emacs uses default attributes based on display type and background brightness.
880See variables `font-lock-display-type' and `font-lock-background-mode'.
881
882Resources can be used to over-ride these face attributes. For example, the
883resource `Emacs.font-lock-comment-face.attributeUnderline' can be used to
884specify the UNDERLINE-P attribute for face `font-lock-comment-face'.")
885
886(defun font-lock-make-faces (&optional override)
887 "Make faces from `font-lock-face-attributes'.
888A default list is used if this is nil.
889If optional OVERRIDE is non-nil, faces that already exist are reset.
890See `font-lock-make-face' and `list-faces-display'."
891 ;; We don't need to `setq' any of these variables, but the user can see what
892 ;; is being used if we do.
893 (if (null font-lock-display-type)
894 (setq font-lock-display-type
895 (let ((display-resource (x-get-resource ".displayType"
896 "DisplayType")))
897 (cond (display-resource (intern (downcase display-resource)))
898 ((x-display-color-p) 'color)
899 ((x-display-grayscale-p) 'grayscale)
900 (t 'mono)))))
901 (if (null font-lock-background-mode)
902 (setq font-lock-background-mode
903 (let ((bg-resource (x-get-resource ".backgroundMode"
904 "BackgroundMode"))
905 (params (frame-parameters)))
906 (cond (bg-resource (intern (downcase bg-resource)))
03a84c34
RS
907 ((eq system-type 'ms-dos)
908 (if (string-match "light"
909 (cdr (assq 'background-color params)))
910 'light
911 'dark))
9bfbb130
SM
912 ((< (apply '+ (x-color-values
913 (cdr (assq 'background-color params))))
914 (/ (apply '+ (x-color-values "white")) 3))
915 'dark)
916 (t 'light)))))
917 (if (null font-lock-face-attributes)
918 (setq font-lock-face-attributes
919 (let ((light-bg (eq font-lock-background-mode 'light)))
920 (cond ((memq font-lock-display-type '(mono monochrome))
921 ;; Emacs 19.25's font-lock defaults:
922 ;;'((font-lock-comment-face nil nil nil t nil)
923 ;; (font-lock-string-face nil nil nil nil t)
924 ;; (font-lock-keyword-face nil nil t nil nil)
925 ;; (font-lock-function-name-face nil nil t t nil)
926 ;; (font-lock-type-face nil nil nil t nil))
927 (list '(font-lock-comment-face nil nil t t nil)
928 '(font-lock-string-face nil nil nil t nil)
929 '(font-lock-keyword-face nil nil t nil nil)
930 (list
931 'font-lock-function-name-face
932 (cdr (assq 'background-color (frame-parameters)))
933 (cdr (assq 'foreground-color (frame-parameters)))
934 t nil nil)
935 '(font-lock-variable-name-face nil nil t t nil)
936 '(font-lock-type-face nil nil t nil t)
937 '(font-lock-reference-face nil nil t nil t)))
938 ((memq font-lock-display-type '(grayscale greyscale
939 grayshade greyshade))
940 (list
941 (list 'font-lock-comment-face
942 nil (if light-bg "Gray80" "DimGray") t t nil)
943 (list 'font-lock-string-face
944 nil (if light-bg "Gray50" "LightGray") nil t nil)
945 (list 'font-lock-keyword-face
946 nil (if light-bg "Gray90" "DimGray") t nil nil)
947 (list 'font-lock-function-name-face
948 (cdr (assq 'background-color (frame-parameters)))
949 (cdr (assq 'foreground-color (frame-parameters)))
950 t nil nil)
951 (list 'font-lock-variable-name-face
952 nil (if light-bg "Gray90" "DimGray") t t nil)
953 (list 'font-lock-type-face
954 nil (if light-bg "Gray80" "DimGray") t nil t)
955 (list 'font-lock-reference-face
956 nil (if light-bg "LightGray" "Gray50") t nil t)))
957 (light-bg ; light colour background
958 '((font-lock-comment-face "Firebrick")
959 (font-lock-string-face "RosyBrown")
960 (font-lock-keyword-face "Purple")
961 (font-lock-function-name-face "Blue")
962 (font-lock-variable-name-face "DarkGoldenrod")
963 (font-lock-type-face "DarkOliveGreen")
964 (font-lock-reference-face "CadetBlue")))
965 (t ; dark colour background
966 '((font-lock-comment-face "OrangeRed")
967 (font-lock-string-face "LightSalmon")
968 (font-lock-keyword-face "LightSteelBlue")
969 (font-lock-function-name-face "LightSkyBlue")
970 (font-lock-variable-name-face "LightGoldenrod")
971 (font-lock-type-face "PaleGreen")
972 (font-lock-reference-face "Aquamarine")))))))
973 ;; Now make the faces if we have to.
974 (mapcar (function
975 (lambda (face-attributes)
976 (let ((face (nth 0 face-attributes)))
977 (cond (override
978 ;; We can stomp all over it anyway. Get outta my face!
979 (font-lock-make-face face-attributes))
980 ((and (boundp face) (facep (symbol-value face)))
981 ;; The variable exists and is already bound to a face.
982 nil)
983 ((facep face)
984 ;; We already have a face so we bind the variable to it.
985 (set face face))
986 (t
987 ;; No variable or no face.
988 (font-lock-make-face face-attributes))))))
989 font-lock-face-attributes))
990
991(defun font-lock-make-face (face-attributes)
992 "Make a face from FACE-ATTRIBUTES.
993FACE-ATTRIBUTES should be like an element `font-lock-face-attributes', so that
994the face name is the first item in the list. A variable with the same name as
995the face is also set; its value is the face name."
996 (let* ((face (nth 0 face-attributes))
997 (face-name (symbol-name face))
998 (set-p (function (lambda (face-name resource)
999 (x-get-resource (concat face-name ".attribute" resource)
1000 (concat "Face.Attribute" resource)))))
1001 (on-p (function (lambda (face-name resource)
1002 (let ((set (funcall set-p face-name resource)))
1003 (and set (member (downcase set) '("on" "true"))))))))
1004 (make-face face)
876f2438 1005 (add-to-list 'facemenu-unlisted-faces face)
9bfbb130
SM
1006 ;; Set attributes not set from X resources (and therefore `make-face').
1007 (or (funcall set-p face-name "Foreground")
1008 (condition-case nil
1009 (set-face-foreground face (nth 1 face-attributes))
1010 (error nil)))
1011 (or (funcall set-p face-name "Background")
1012 (condition-case nil
1013 (set-face-background face (nth 2 face-attributes))
1014 (error nil)))
1015 (if (funcall set-p face-name "Bold")
1016 (and (funcall on-p face-name "Bold") (make-face-bold face nil t))
1017 (and (nth 3 face-attributes) (make-face-bold face nil t)))
1018 (if (funcall set-p face-name "Italic")
1019 (and (funcall on-p face-name "Italic") (make-face-italic face nil t))
1020 (and (nth 4 face-attributes) (make-face-italic face nil t)))
1021 (or (funcall set-p face-name "Underline")
1022 (set-face-underline-p face (nth 5 face-attributes)))
1023 (set face face)))
1024\f
1025;;; Various regexp information shared by several modes.
a1eb1cf1 1026;;; Information specific to a single mode should go in its load library.
030f4a35 1027
030f4a35 1028(defconst lisp-font-lock-keywords-1
a1eb1cf1 1029 (list
9bfbb130 1030 ;; Anything not a variable or type declaration is fontified as a function.
d46c21ec
SM
1031 ;; It would be cleaner to allow preceding whitespace, but it would also be
1032 ;; about five times slower.
1033 (list (concat "^(\\(def\\("
1034 ;; Variable declarations.
1035 "\\(const\\(\\|ant\\)\\|ine-key\\(\\|-after\\)\\|var\\)\\|"
1036 ;; Structure declarations.
1037 "\\(class\\|struct\\|type\\)\\|"
1038 ;; Everything else is a function declaration.
1039 "\\([^ \t\n\(\)]+\\)"
1040 "\\)\\)\\>"
1041 ;; Any whitespace and declared object.
1042 "[ \t'\(]*"
1043 "\\([^ \t\n\)]+\\)?")
1044 '(1 font-lock-keyword-face)
1045 '(8 (cond ((match-beginning 3) font-lock-variable-name-face)
1046 ((match-beginning 6) font-lock-type-face)
1047 (t font-lock-function-name-face))
9bfbb130
SM
1048 nil t))
1049 )
fb512de9 1050 "Subdued level highlighting Lisp modes.")
030f4a35
RS
1051
1052(defconst lisp-font-lock-keywords-2
799761f0 1053 (append lisp-font-lock-keywords-1
9bfbb130
SM
1054 (list
1055 ;;
1056 ;; Control structures. ELisp and CLisp combined.
d46c21ec
SM
1057; (make-regexp
1058; '("cond" "if" "while" "let\\*?" "prog[nv12*]?" "catch" "throw"
1059; "save-restriction" "save-excursion" "save-window-excursion"
1060; "save-selected-window" "save-match-data" "unwind-protect"
1061; "condition-case" "track-mouse"
1062; "eval-after-load" "eval-and-compile" "eval-when-compile"
1063; "when" "unless" "do" "flet" "labels" "return" "return-from"))
9bfbb130
SM
1064 (cons
1065 (concat
1066 "(\\("
1067 "\\(c\\(atch\\|ond\\(\\|ition-case\\)\\)\\|do\\|"
1068 "eval-\\(a\\(fter-load\\|nd-compile\\)\\|when-compile\\)\\|flet\\|"
1069 "if\\|l\\(abels\\|et\\*?\\)\\|prog[nv12*]?\\|return\\(\\|-from\\)\\|"
1070 "save-\\(excursion\\|match-data\\|restriction\\|selected-window\\|"
1071 "window-excursion\\)\\|t\\(hrow\\|rack-mouse\\)\\|"
1072 "un\\(less\\|wind-protect\\)\\|wh\\(en\\|ile\\)\\)"
1073 "\\)\\>") 1)
1074 ;;
1075 ;; Words inside \\[] tend to be for `substitute-command-keys'.
1076 '("\\\\\\\\\\[\\(\\sw+\\)]" 1 font-lock-reference-face prepend)
1077 ;;
1078 ;; Words inside `' tend to be symbol names.
1079 '("`\\(\\sw\\sw+\\)'" 1 font-lock-reference-face prepend)
1080 ;;
1081 ;; CLisp `:' keywords as references.
1082 '("\\<:\\sw+\\>" 0 font-lock-reference-face prepend)
1083 ;;
1084 ;; ELisp and CLisp `&' keywords as types.
1085 '("\\<\\&\\(optional\\|rest\\|whole\\)\\>" . font-lock-type-face)
1086 ))
fb512de9 1087 "Gaudy level highlighting for Lisp modes.")
030f4a35 1088
fb512de9
SM
1089(defvar lisp-font-lock-keywords lisp-font-lock-keywords-1
1090 "Default expressions to highlight in Lisp modes.")
030f4a35
RS
1091
1092
d46c21ec 1093(defvar scheme-font-lock-keywords
9bfbb130
SM
1094 (eval-when-compile
1095 (list
1096 ;;
1097 ;; Declarations. Hannes Haug <hannes.haug@student.uni-tuebingen.de> says
1098 ;; this works for SOS, STklos, SCOOPS, Meroon and Tiny CLOS.
1099 (list (concat "(\\(define\\("
1100 ;; Function names.
1101 "\\(\\|-\\(generic\\(\\|-procedure\\)\\|method\\)\\)\\|"
1102 ;; Macro names, as variable names. A bit dubious, this.
1103 "\\(-syntax\\)\\|"
1104 ;; Class names.
1105 "\\(-class\\)"
1106 "\\)\\)\\>"
1107 ;; Any whitespace and declared object.
1108 "[ \t]*(?"
1109 "\\(\\sw+\\)?")
1110 '(1 font-lock-keyword-face)
1111 '(8 (cond ((match-beginning 3) font-lock-function-name-face)
1112 ((match-beginning 6) font-lock-variable-name-face)
1113 (t font-lock-type-face))
1114 nil t))
1115 ;;
1116 ;; Control structures.
d46c21ec
SM
1117;(make-regexp '("begin" "call-with-current-continuation" "call/cc"
1118; "call-with-input-file" "call-with-output-file" "case" "cond"
9bfbb130
SM
1119; "do" "else" "for-each" "if" "lambda"
1120; "let\\*?" "let-syntax" "letrec" "letrec-syntax"
1121; ;; Hannes Haug <hannes.haug@student.uni-tuebingen.de> wants:
1122; "and" "or" "delay"
1123; ;; Stefan Monnier <stefan.monnier@epfl.ch> says don't bother:
d46c21ec
SM
1124; ;;"quasiquote" "quote" "unquote" "unquote-splicing"
1125; "map" "syntax" "syntax-rules"))
9bfbb130
SM
1126 (cons
1127 (concat "(\\("
1128 "and\\|begin\\|c\\(a\\(ll\\(-with-\\(current-continuation\\|"
1129 "input-file\\|output-file\\)\\|/cc\\)\\|se\\)\\|ond\\)\\|"
1130 "d\\(elay\\|o\\)\\|else\\|for-each\\|if\\|"
1131 "l\\(ambda\\|et\\(-syntax\\|\\*?\\|rec\\(\\|-syntax\\)\\)\\)\\|"
1132 "map\\|or\\|syntax\\(\\|-rules\\)"
1133 "\\)\\>") 1)
1134 ;;
1135 ;; David Fox <fox@graphics.cs.nyu.edu> for SOS/STklos class specifiers.
1136 '("\\<<\\sw+>\\>" . font-lock-type-face)
1137 ;;
1138 ;; Scheme `:' keywords as references.
1139 '("\\<:\\sw+\\>" . font-lock-reference-face)
1140 ))
1141"Default expressions to highlight in Scheme modes.")
d46c21ec
SM
1142
1143
030f4a35 1144(defconst c-font-lock-keywords-1 nil
fb512de9 1145 "Subdued level highlighting for C modes.")
030f4a35
RS
1146
1147(defconst c-font-lock-keywords-2 nil
9bfbb130
SM
1148 "Medium level highlighting for C modes.")
1149
1150(defconst c-font-lock-keywords-3 nil
fb512de9 1151 "Gaudy level highlighting for C modes.")
030f4a35 1152
1bd50840 1153(defconst c++-font-lock-keywords-1 nil
fb512de9 1154 "Subdued level highlighting for C++ modes.")
1bd50840
RS
1155
1156(defconst c++-font-lock-keywords-2 nil
9bfbb130
SM
1157 "Medium level highlighting for C++ modes.")
1158
1159(defconst c++-font-lock-keywords-3 nil
fb512de9 1160 "Gaudy level highlighting for C++ modes.")
1bd50840 1161
9bfbb130
SM
1162(defun font-lock-match-c++-style-declaration-item-and-skip-to-next (limit)
1163 ;; Match, and move over, any declaration/definition item after point.
1164 ;; The expect syntax of an item is "word" or "word::word", possibly ending
1165 ;; with optional whitespace and a "(". Everything following the item (but
1166 ;; belonging to it) is expected to by skip-able by `forward-sexp', and items
1167 ;; are expected to be separated with a "," or ";".
1168 (if (looking-at "[ \t*&]*\\(\\sw+\\)\\(::\\(\\sw+\\)\\)?[ \t]*\\((\\)?")
1169 (save-match-data
1170 (condition-case nil
1171 (save-restriction
876f2438
SM
1172 ;; Restrict to the end of line, currently guaranteed to be LIMIT.
1173 (narrow-to-region (point-min) limit)
9bfbb130
SM
1174 (goto-char (match-end 1))
1175 ;; Move over any item value, etc., to the next item.
1176 (while (not (looking-at "[ \t]*\\([,;]\\|$\\)"))
1177 (goto-char (or (scan-sexps (point) 1) (point-max))))
1178 (goto-char (match-end 0)))
1179 (error t)))))
1180
b89e1134
SM
1181(let ((c-keywords
1182; ("break" "continue" "do" "else" "for" "if" "return" "switch" "while")
1183 "break\\|continue\\|do\\|else\\|for\\|if\\|return\\|switch\\|while")
1184 (c-type-types
a1eb1cf1
RS
1185; ("auto" "extern" "register" "static" "typedef" "struct" "union" "enum"
1186; "signed" "unsigned" "short" "long" "int" "char" "float" "double"
b89e1134
SM
1187; "void" "volatile" "const")
1188 (concat "auto\\|c\\(har\\|onst\\)\\|double\\|e\\(num\\|xtern\\)\\|"
1189 "float\\|int\\|long\\|register\\|"
1190 "s\\(hort\\|igned\\|t\\(atic\\|ruct\\)\\)\\|typedef\\|"
1191 "un\\(ion\\|signed\\)\\|vo\\(id\\|latile\\)")) ; 6 ()s deep.
1192 (c++-keywords
1193; ("break" "continue" "do" "else" "for" "if" "return" "switch" "while"
1194; "asm" "catch" "delete" "new" "operator" "sizeof" "this" "throw" "try"
1195; "protected" "private" "public")
1196 (concat "asm\\|break\\|c\\(atch\\|ontinue\\)\\|d\\(elete\\|o\\)\\|"
9bfbb130 1197 "else\\|for\\|if\\|new\\|"
b89e1134
SM
1198 "p\\(r\\(ivate\\|otected\\)\\|ublic\\)\\|return\\|"
1199 "s\\(izeof\\|witch\\)\\|t\\(h\\(is\\|row\\)\\|ry\\)\\|while"))
1200 (c++-type-types
1201; ("auto" "extern" "register" "static" "typedef" "struct" "union" "enum"
1202; "signed" "unsigned" "short" "long" "int" "char" "float" "double"
1203; "void" "volatile" "const" "class" "inline" "friend" "bool"
1204; "virtual" "complex" "template")
1205 (concat "auto\\|bool\\|c\\(har\\|lass\\|o\\(mplex\\|nst\\)\\)\\|"
1206 "double\\|e\\(num\\|xtern\\)\\|f\\(loat\\|riend\\)\\|"
1207 "in\\(line\\|t\\)\\|long\\|register\\|"
1208 "s\\(hort\\|igned\\|t\\(atic\\|ruct\\)\\)\\|"
1209 "t\\(emplate\\|ypedef\\)\\|un\\(ion\\|signed\\)\\|"
1210 "v\\(irtual\\|o\\(id\\|latile\\)\\)")) ; 11 ()s deep.
9bfbb130 1211 )
f60f18ae
KH
1212 (setq c-font-lock-keywords-1
1213 (list
f60f18ae 1214 ;;
9bfbb130
SM
1215 ;; These are all anchored at the beginning of line for speed.
1216 ;;
1217 ;; Fontify function name definitions (GNU style; without type on line).
1218 (list (concat "^\\(\\sw+\\)[ \t]*(") 1 'font-lock-function-name-face)
1219 ;;
1220 ;; Fontify filenames in #include <...> preprocessor directives as strings.
f60f18ae
KH
1221 '("^#[ \t]*include[ \t]+\\(<[^>\"\n]+>\\)" 1 font-lock-string-face)
1222 ;;
a1eb1cf1
RS
1223 ;; Fontify function macro names.
1224 '("^#[ \t]*define[ \t]+\\(\\(\\sw+\\)(\\)" 2 font-lock-function-name-face)
f60f18ae 1225 ;;
9bfbb130
SM
1226 ;; Fontify symbol names in #if ... defined preprocessor directives.
1227 '("^#[ \t]*if\\>"
1228 ("\\<\\(defined\\)\\>[ \t]*(?\\(\\sw+\\)?" nil nil
1229 (1 font-lock-reference-face) (2 font-lock-variable-name-face nil t)))
1230 ;;
a1eb1cf1
RS
1231 ;; Fontify otherwise as symbol names, and the preprocessor directive names.
1232 '("^\\(#[ \t]*[a-z]+\\)\\>[ \t]*\\(\\sw+\\)?"
1233 (1 font-lock-reference-face) (2 font-lock-variable-name-face nil t))
f60f18ae
KH
1234 ))
1235
1236 (setq c-font-lock-keywords-2
1237 (append c-font-lock-keywords-1
030f4a35 1238 (list
030f4a35 1239 ;;
9bfbb130 1240 ;; Simple regexps for speed.
b89e1134 1241 ;;
9bfbb130
SM
1242 ;; Fontify all type specifiers.
1243 (cons (concat "\\<\\(" c-type-types "\\)\\>") 'font-lock-type-face)
030f4a35 1244 ;;
b89e1134 1245 ;; Fontify all builtin keywords (except case, default and goto; see below).
9bfbb130 1246 (cons (concat "\\<\\(" c-keywords "\\)\\>") 'font-lock-keyword-face)
030f4a35 1247 ;;
9bfbb130 1248 ;; Fontify case/goto keywords and targets, and case default/goto tags.
a1eb1cf1
RS
1249 '("\\<\\(case\\|goto\\)\\>[ \t]*\\([^ \t\n:;]+\\)?"
1250 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
1251 '("^[ \t]*\\(\\sw+\\)[ \t]*:" 1 font-lock-reference-face)
f60f18ae 1252 )))
1bd50840 1253
9bfbb130
SM
1254 (setq c-font-lock-keywords-3
1255 (append c-font-lock-keywords-2
1256 ;;
1257 ;; More complicated regexps for more complete highlighting for types.
1258 ;; We still have to fontify type specifiers individually, as C is so hairy.
1259 (list
1260 ;;
1261 ;; Fontify all storage classes and type specifiers, plus their items.
1262 (list (concat "\\<\\(" c-type-types "\\)\\>"
1263 "\\([ \t*&]+\\sw+\\>\\)*")
1264 ;; Fontify each declaration item.
1265 '(font-lock-match-c++-style-declaration-item-and-skip-to-next
1266 ;; Start with point after all type specifiers.
1267 (goto-char (or (match-beginning 8) (match-end 1)))
1268 ;; Finish with point after first type specifier.
1269 (goto-char (match-end 1))
1270 ;; Fontify as a variable or function name.
1271 (1 (if (match-beginning 4)
1272 font-lock-function-name-face
1273 font-lock-variable-name-face))))
1274 ;;
1275 ;; Fontify structures, or typedef names, plus their items.
1276 '("\\(}\\)[ \t*]*\\sw"
1277 (font-lock-match-c++-style-declaration-item-and-skip-to-next
1278 (goto-char (match-end 1)) nil
1279 (1 (if (match-beginning 4)
1280 font-lock-function-name-face
1281 font-lock-variable-name-face))))
1282 ;;
1283 ;; Fontify anything at beginning of line as a declaration or definition.
1284 '("^\\(\\sw+\\)\\>\\([ \t*]+\\sw+\\>\\)*"
1285 (1 font-lock-type-face)
1286 (font-lock-match-c++-style-declaration-item-and-skip-to-next
1287 (goto-char (or (match-beginning 2) (match-end 1))) nil
1288 (1 (if (match-beginning 4)
1289 font-lock-function-name-face
1290 font-lock-variable-name-face))))
1291 )))
1292
1293 (setq c++-font-lock-keywords-1
1294 (append
1295 ;;
1296 ;; The list `c-font-lock-keywords-1' less that for function names.
1297 (cdr c-font-lock-keywords-1)
1298 ;;
1299 ;; Fontify function name definitions, possibly incorporating class name.
1300 (list
1301 '("^\\(\\sw+\\)\\(::\\(\\sw+\\)\\)?[ \t]*("
1302 (1 (if (match-beginning 2)
1303 font-lock-type-face
1304 font-lock-function-name-face))
1305 (3 (if (match-beginning 2) font-lock-function-name-face) nil t))
1306 )))
1307
1bd50840 1308 (setq c++-font-lock-keywords-2
b89e1134 1309 (append c++-font-lock-keywords-1
a1eb1cf1 1310 (list
9bfbb130
SM
1311 ;;
1312 ;; The list `c-font-lock-keywords-2' for C++ plus operator overloading.
b89e1134 1313 (cons (concat "\\<\\(" c++-type-types "\\)\\>") 'font-lock-type-face)
9bfbb130
SM
1314 ;;
1315 ;; Fontify operator function name overloading.
1316 '("\\<\\(operator\\)\\>[ \t]*\\([][)(><!=+-][][)(><!=+-]?\\)?"
1317 (1 font-lock-keyword-face) (2 font-lock-function-name-face nil t))
1318 ;;
1319 ;; Fontify case/goto keywords and targets, and case default/goto tags.
b89e1134
SM
1320 '("\\<\\(case\\|goto\\)\\>[ \t]*\\([^ \t\n:;]+\\)?"
1321 (1 font-lock-keyword-face) (2 font-lock-reference-face nil t))
9bfbb130
SM
1322 '("^[ \t]*\\(\\sw+\\)[ \t]*:[^:]" 1 font-lock-reference-face)
1323 ;;
1324 ;; Fontify other builtin keywords.
1325 (cons (concat "\\<\\(" c++-keywords "\\)\\>") 'font-lock-keyword-face)
1326 )))
1327
1328 (setq c++-font-lock-keywords-3
1329 (append c++-font-lock-keywords-2
1330 ;;
1331 ;; More complicated regexps for more complete highlighting for types.
1332 (list
1333 ;;
1334 ;; Fontify all storage classes and type specifiers, plus their items.
1335 (list (concat "\\<\\(" c++-type-types "\\)\\>"
1336 "\\([ \t*&]+\\sw+\\>\\)*")
1337 ;; Fontify each declaration item.
1338 '(font-lock-match-c++-style-declaration-item-and-skip-to-next
1339 ;; Start with point after all type specifiers.
1340 (goto-char (or (match-beginning 13) (match-end 1)))
1341 ;; Finish with point after first type specifier.
1342 (goto-char (match-end 1))
1343 ;; Fontify as a variable or function name.
1344 (1 (cond ((match-beginning 2) font-lock-type-face)
1345 ((match-beginning 4) font-lock-function-name-face)
1346 (t font-lock-variable-name-face)))
1347 (3 (if (match-beginning 4)
1348 font-lock-function-name-face
1349 font-lock-variable-name-face) nil t)))
1350 ;;
1351 ;; Fontify structures, or typedef names, plus their items.
1352 '("\\(}\\)[ \t*]*\\sw"
1353 (font-lock-match-c++-style-declaration-item-and-skip-to-next
1354 (goto-char (match-end 1)) nil
1355 (1 (if (match-beginning 4)
1356 font-lock-function-name-face
1357 font-lock-variable-name-face))))
1358 ;;
1359 ;; Fontify anything at beginning of line as a declaration or definition.
1360 '("^\\(\\sw+\\)\\>\\([ \t*]+\\sw+\\>\\)*"
1361 (1 font-lock-type-face)
1362 (font-lock-match-c++-style-declaration-item-and-skip-to-next
1363 (goto-char (or (match-beginning 2) (match-end 1))) nil
1364 (1 (cond ((match-beginning 2) font-lock-type-face)
1365 ((match-beginning 4) font-lock-function-name-face)
1366 (t font-lock-variable-name-face)))
1367 (3 (if (match-beginning 4)
1368 font-lock-function-name-face
1369 font-lock-variable-name-face) nil t)))
1370 )))
f60f18ae 1371 )
030f4a35 1372
fb512de9
SM
1373(defvar c-font-lock-keywords c-font-lock-keywords-1
1374 "Default expressions to highlight in C mode.")
030f4a35 1375
fb512de9
SM
1376(defvar c++-font-lock-keywords c++-font-lock-keywords-1
1377 "Default expressions to highlight in C++ mode.")
030f4a35 1378
d46c21ec 1379
030f4a35 1380(defvar tex-font-lock-keywords
d46c21ec
SM
1381; ;; Regexps updated with help from Ulrik Dickow <dickow@nbi.dk>.
1382; '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
1383; 2 font-lock-function-name-face)
1384; ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
1385; 2 font-lock-reference-face)
1386; ;; It seems a bit dubious to use `bold' and `italic' faces since we might
1387; ;; not be able to display those fonts.
1388; ("{\\\\bf\\([^}]+\\)}" 1 'bold keep)
1389; ("{\\\\\\(em\\|it\\|sl\\)\\([^}]+\\)}" 2 'italic keep)
1390; ("\\\\\\([a-zA-Z@]+\\|.\\)" . font-lock-keyword-face)
1391; ("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face keep))
1392 ;; Rewritten and extended for LaTeX2e by Ulrik Dickow <dickow@nbi.dk>.
826b2925
SM
1393 '(("\\\\\\(begin\\|end\\|newcommand\\){\\([a-zA-Z0-9\\*]+\\)}"
1394 2 font-lock-function-name-face)
1395 ("\\\\\\(cite\\|label\\|pageref\\|ref\\){\\([^} \t\n]+\\)}"
1396 2 font-lock-reference-face)
d46c21ec 1397 ("^[ \t]*\\\\def\\\\\\(\\(\\w\\|@\\)+\\)" 1 font-lock-function-name-face)
9bfbb130 1398 "\\\\\\([a-zA-Z@]+\\|.\\)"
826b2925
SM
1399 ;; It seems a bit dubious to use `bold' and `italic' faces since we might
1400 ;; not be able to display those fonts.
d46c21ec
SM
1401 ;; LaTeX2e: \emph{This is emphasized}.
1402 ("\\\\emph{\\([^}]+\\)}" 1 'italic keep)
1403 ;; LaTeX2e: \textbf{This is bold}, \textit{...}, \textsl{...}
1404 ("\\\\text\\(\\(bf\\)\\|it\\|sl\\){\\([^}]+\\)}"
1405 3 (if (match-beginning 2) 'bold 'italic) keep)
1406 ;; Old-style bf/em/it/sl. Stop at `\\' and un-escaped `&', for good tables.
1407 ("\\\\\\(\\(bf\\)\\|em\\|it\\|sl\\)\\>\\(\\([^}&\\]\\|\\\\[^\\]\\)+\\)"
1408 3 (if (match-beginning 2) 'bold 'italic) keep))
9bfbb130 1409 "Default expressions to highlight in TeX modes.")
d46c21ec 1410\f
a1eb1cf1
RS
1411;; Install ourselves:
1412
a1eb1cf1
RS
1413(or (assq 'font-lock-mode minor-mode-alist)
1414 (setq minor-mode-alist (cons '(font-lock-mode " Font") minor-mode-alist)))
1415
1416;; Provide ourselves:
8f261d40 1417
030f4a35
RS
1418(provide 'font-lock)
1419
1420;;; font-lock.el ends here