Mercurial > emacs
annotate lisp/font-lock.el @ 4725:126cf4bdfd35
(vc-version-other-window): New function.
(vc-backend-checkout): Add optional arg workfile, which specifies where
to put the working file.
author | Paul Eggert <eggert@twinsun.com> |
---|---|
date | Wed, 15 Sep 1993 23:19:13 +0000 |
parents | 1d8de7410270 |
children | ca337641008d |
rev | line source |
---|---|
4053 | 1 ;; Electric Font Lock Mode |
2 ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc. | |
3 | |
4 ;; Author: jwz, then rms | |
5 ;; Maintainer: FSF | |
6 ;; Keywords: languages, faces | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
23 | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; Font-lock-mode is a minor mode that causes your comments to be | |
28 ;; displayed in one face, strings in another, reserved words in another, | |
29 ;; documentation strings in another, and so on. | |
30 ;; | |
31 ;; Comments will be displayed in `font-lock-comment-face'. | |
32 ;; Strings will be displayed in `font-lock-string-face'. | |
33 ;; Doc strings will be displayed in `font-lock-doc-string-face'. | |
34 ;; Function and variable names (in their defining forms) will be | |
35 ;; displayed in `font-lock-function-name-face'. | |
36 ;; Reserved words will be displayed in `font-lock-keyword-face'. | |
37 ;; | |
38 ;; To make the text you type be fontified, use M-x font-lock-mode. | |
39 ;; When this minor mode is on, the fonts of the current line are | |
40 ;; updated with every insertion or deletion. | |
41 ;; | |
42 ;; To define new reserved words or other patterns to highlight, use | |
43 ;; the `font-lock-keywords' variable. This should be mode-local. | |
44 ;; | |
45 ;; To turn this on automatically, add this to your .emacs file: | |
46 ;; | |
47 ;; (setq emacs-lisp-mode-hook '(lambda () (font-lock-mode 1))) | |
48 ;; | |
49 ;; On a Sparc2, the initial fontification takes about 12 seconds for a 120k | |
50 ;; file of C code, using the default configuration. You can speed this up | |
51 ;; substantially by removing some of the patterns that are highlighted by | |
52 ;; default. Fontifying Lisp code is significantly faster, because Lisp has a | |
53 ;; more regular syntax than C, so the expressions don't have to be as hairy. | |
54 | |
55 ;;; Code: | |
56 | |
57 (or (internal-find-face 'underline) | |
58 (copy-face 'default 'underline)) | |
59 (set-face-underline-p 'underline t) | |
60 | |
61 (defvar font-lock-comment-face | |
62 'italic | |
63 "Face to use for comments.") | |
64 | |
65 (defvar font-lock-doc-string-face | |
66 'italic | |
67 "Face to use for documentation strings.") | |
68 | |
69 (defvar font-lock-string-face | |
70 'underline | |
71 "Face to use for string constants.") | |
72 | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
73 (defvar font-lock-function-name-face |
4053 | 74 'bold-italic |
75 "Face to use for function names.") | |
76 | |
77 (defvar font-lock-keyword-face | |
78 'bold | |
79 "Face to use for keywords.") | |
80 | |
81 (defvar font-lock-type-face | |
82 'italic | |
83 "Face to use for data types.") | |
84 | |
85 (make-variable-buffer-local 'font-lock-keywords) | |
86 (defvar font-lock-keywords nil | |
87 "*The keywords to highlight. | |
88 If this is a list, then elements may be of the forms: | |
89 | |
90 \"string\" ; a regexp to highlight in the | |
91 ; `font-lock-keyword-face'. | |
92 (\"string\" . integer) ; match N of the regexp will be highlighted | |
93 (\"string\" . face-name) ; use the named face | |
94 (\"string\" integer face-name) ; both of the above | |
95 (\"string\" integer face-name t) ; this allows highlighting to overlap | |
96 ; with already-highlighted regions. | |
97 | |
98 These regular expressions should not match text which spans lines. | |
99 While \\[font-lock-fontify-buffer] handles multi-line patterns correctly, | |
100 updating when you edit the buffer does not, | |
101 since it considers text one line at a time. | |
102 | |
103 Be careful composing regexps for this list; the wrong pattern can dramatically | |
104 slow things down!") | |
105 | |
106 (defvar font-lock-keywords-case-fold-search nil | |
107 "*Non-nil means the patterns in `font-lock-keywords' are case-insensitive.") | |
108 | |
109 (defvar font-lock-verbose t | |
110 "*Non-nil means `font-lock-fontify-buffer' should print status messages.") | |
111 | |
4054 | 112 ;;;###autoload |
4053 | 113 (defvar font-lock-mode-hook nil |
114 "Function or functions to run on entry to Font Lock mode.") | |
115 | |
116 ;;; These variables record, for each buffer, | |
117 ;;; the parse state at a particular position, always the start of a line. | |
118 ;;; This is used to make font-lock-fontify-region faster. | |
119 (defvar font-lock-cache-position nil) | |
120 (defvar font-lock-cache-state nil) | |
121 (make-variable-buffer-local 'font-lock-cache-position) | |
122 (make-variable-buffer-local 'font-lock-cache-state) | |
123 | |
124 (defun font-lock-fontify-region (start end) | |
125 "Put proper face on each string and comment between START and END." | |
126 (save-excursion | |
127 (goto-char start) | |
128 (beginning-of-line) | |
129 (setq end (min end (point-max))) | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
130 (let ((buffer-read-only nil) |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
131 state startline prev prevstate |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
132 (modified (buffer-modified-p))) |
4053 | 133 ;; Find the state at the line-beginning before START. |
134 (setq startline (point)) | |
135 (if (eq (point) font-lock-cache-position) | |
136 (setq state font-lock-cache-state) | |
137 ;; Find outermost containing sexp. | |
138 (beginning-of-defun) | |
139 ;; Find the state at STARTLINE. | |
140 (while (< (point) startline) | |
141 (setq state (parse-partial-sexp (point) startline 0))) | |
142 (setq font-lock-cache-state state | |
143 font-lock-cache-position (point))) | |
144 ;; Now find the state precisely at START. | |
145 (setq state (parse-partial-sexp (point) start nil nil state)) | |
146 ;; If the region starts inside a string, show the extent of it. | |
147 (if (nth 3 state) | |
148 (let ((beg (point))) | |
149 (while (and (re-search-forward "\\s\"" end 'move) | |
150 (nth 3 (parse-partial-sexp beg (point) | |
151 nil nil state)))) | |
152 (put-text-property beg (point) 'face font-lock-string-face) | |
4700
1d8de7410270
(font-lock-fontify-region): Put on `font-lock'
Richard M. Stallman <rms@gnu.org>
parents:
4459
diff
changeset
|
153 (put-text-property beg (point) 'font-lock t) |
4053 | 154 (setq state (parse-partial-sexp beg (point) nil nil state)))) |
155 ;; Likewise for a comment. | |
156 (if (or (nth 4 state) (nth 7 state)) | |
157 (let ((beg (point))) | |
158 (while (and (re-search-forward (if comment-end | |
159 (concat "\\s>\\|" | |
160 (regexp-quote comment-end)) | |
161 "\\s>") | |
162 end 'move) | |
163 (nth 3 (parse-partial-sexp beg (point) | |
164 nil nil state)))) | |
165 (put-text-property beg (point) 'face font-lock-comment-face) | |
4700
1d8de7410270
(font-lock-fontify-region): Put on `font-lock'
Richard M. Stallman <rms@gnu.org>
parents:
4459
diff
changeset
|
166 (put-text-property beg (point) 'font-lock t) |
4053 | 167 (setq state (parse-partial-sexp beg (point) nil nil state)))) |
168 ;; Find each interesting place between here and END. | |
169 (while (and (< (point) end) | |
170 (setq prev (point) prevstate state) | |
4459
2d8f7239f2ca
(font-lock-fontify-region): Handle comment-start-skip = nil.
Richard M. Stallman <rms@gnu.org>
parents:
4239
diff
changeset
|
171 (re-search-forward (if comment-start-skip |
2d8f7239f2ca
(font-lock-fontify-region): Handle comment-start-skip = nil.
Richard M. Stallman <rms@gnu.org>
parents:
4239
diff
changeset
|
172 (concat "\\s\"\\|" comment-start-skip) |
2d8f7239f2ca
(font-lock-fontify-region): Handle comment-start-skip = nil.
Richard M. Stallman <rms@gnu.org>
parents:
4239
diff
changeset
|
173 "\\s\"") |
2d8f7239f2ca
(font-lock-fontify-region): Handle comment-start-skip = nil.
Richard M. Stallman <rms@gnu.org>
parents:
4239
diff
changeset
|
174 end t) |
4053 | 175 ;; Clear out the fonts of what we skip over. |
176 (progn (remove-text-properties prev (point) '(face nil)) t) | |
177 ;; Verify the state at that place | |
178 ;; so we don't get fooled by \" or \;. | |
179 (setq state (parse-partial-sexp prev (point) | |
180 nil nil state))) | |
181 (let ((here (point))) | |
182 (if (or (nth 4 state) (nth 7 state)) | |
183 ;; We found a real comment start. | |
184 (let ((beg (match-beginning 0))) | |
185 (goto-char beg) | |
186 (save-restriction | |
187 (narrow-to-region (point-min) end) | |
188 (condition-case nil | |
189 (progn | |
190 (forward-comment 1) | |
191 ;; forward-comment skips all whitespace, | |
192 ;; so go back to the real end of the comment. | |
193 (skip-chars-backward " \t")) | |
194 (error (goto-char end)))) | |
195 (put-text-property beg (point) 'face font-lock-comment-face) | |
4700
1d8de7410270
(font-lock-fontify-region): Put on `font-lock'
Richard M. Stallman <rms@gnu.org>
parents:
4459
diff
changeset
|
196 (put-text-property beg (point) 'font-lock t) |
4053 | 197 (setq state (parse-partial-sexp here (point) nil nil state))) |
198 (if (nth 3 state) | |
199 (let ((beg (match-beginning 0))) | |
200 (while (and (re-search-forward "\\s\"" end 'move) | |
201 (nth 3 (parse-partial-sexp here (point) | |
202 nil nil state)))) | |
203 (put-text-property beg (point) 'face font-lock-string-face) | |
4700
1d8de7410270
(font-lock-fontify-region): Put on `font-lock'
Richard M. Stallman <rms@gnu.org>
parents:
4459
diff
changeset
|
204 (put-text-property beg (point) 'font-lock t) |
4053 | 205 (setq state (parse-partial-sexp here (point) nil nil state)))) |
206 )) | |
207 ;; Make sure PREV is non-nil after the loop | |
208 ;; only if it was set on the very last iteration. | |
209 (setq prev nil)) | |
210 (and prev | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
211 (remove-text-properties prev end '(face nil))) |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
212 (set-buffer-modified-p modified)))) |
4053 | 213 |
214 ;; This code used to be used to show a string on reaching the end of it. | |
215 ;; It is probably not needed due to later changes to handle strings | |
216 ;; starting before the region in question. | |
217 ;; (if (and (null (nth 3 state)) | |
218 ;; (eq (char-syntax (preceding-char)) ?\") | |
219 ;; (save-excursion | |
220 ;; (nth 3 (parse-partial-sexp prev (1- (point)) | |
221 ;; nil nil prevstate)))) | |
222 ;; ;; We found the end of a string. | |
223 ;; (save-excursion | |
224 ;; (setq foo2 (point)) | |
225 ;; (let ((ept (point))) | |
226 ;; (forward-sexp -1) | |
227 ;; ;; Highlight the string when we see the end. | |
228 ;; ;; Doing it at the start leads to trouble: | |
229 ;; ;; either it fails to handle multiline strings | |
230 ;; ;; or it can run away when an unmatched " is inserted. | |
231 ;; (put-text-property (point) ept 'face | |
232 ;; (if (= (car state) 1) | |
233 ;; font-lock-doc-string-face | |
234 ;; font-lock-string-face))))) | |
235 | |
236 (defun font-lock-unfontify-region (beg end) | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
237 (let ((modified (buffer-modified-p)) |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
238 (buffer-read-only nil)) |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
239 (remove-text-properties beg end '(face nil)) |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
240 (set-buffer-modified-p modified))) |
4053 | 241 |
242 ;; Called when any modification is made to buffer text. | |
243 (defun font-lock-after-change-function (beg end old-len) | |
244 (save-excursion | |
245 (save-match-data | |
246 (goto-char beg) | |
247 ;; Discard the cache info if text before it has changed. | |
248 (and font-lock-cache-position | |
249 (> font-lock-cache-position beg) | |
250 (setq font-lock-cache-position nil)) | |
251 ;; Rescan till end of line. yes! | |
252 (goto-char end) | |
253 (end-of-line) | |
254 (setq end (point)) | |
255 (goto-char beg) | |
256 (beginning-of-line) | |
257 (setq beg (point)) | |
4239
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
258 ;; First scan for strings and comments. |
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
259 ;; Must scan from line start in case of |
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
260 ;; inserting space into `intfoo () {}'. |
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
261 (font-lock-fontify-region beg (1+ end)) |
4053 | 262 ;; Now scan for keywords. |
263 (font-lock-hack-keywords beg end)))) | |
264 | |
265 ;;; Fontifying arbitrary patterns | |
266 | |
267 (defsubst font-lock-any-properties-p (start end) | |
268 (or (get-text-property start 'font-lock) | |
269 (let ((next (next-single-property-change start 'font-lock))) | |
270 (and next (< next end))))) | |
271 | |
272 (defun font-lock-hack-keywords (start end &optional loudly) | |
273 (goto-char start) | |
274 (let ((case-fold-search font-lock-keywords-case-fold-search) | |
275 (rest font-lock-keywords) | |
276 (count 0) | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
277 (buffer-read-only nil) |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
278 (modified (buffer-modified-p)) |
4053 | 279 first str match face s e allow-overlap-p) |
280 (while rest | |
281 (setq first (car rest) rest (cdr rest)) | |
282 (goto-char start) | |
283 (cond ((consp first) | |
284 (setq str (car first)) | |
285 (cond ((consp (cdr first)) | |
286 (setq match (nth 1 first) | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
287 face (eval (nth 2 first)) |
4053 | 288 allow-overlap-p (nth 3 first))) |
289 ((symbolp (cdr first)) | |
290 (setq match 0 allow-overlap-p nil | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
291 face (eval (cdr first)))) |
4053 | 292 (t |
293 (setq match (cdr first) | |
294 allow-overlap-p nil | |
295 face font-lock-keyword-face)))) | |
296 (t | |
297 (setq str first match 0 allow-overlap-p nil | |
298 face font-lock-keyword-face))) | |
299 ;(message "regexp: %s" str) | |
300 (while (re-search-forward str end t) | |
301 (setq s (match-beginning match) | |
302 e (match-end match)) | |
303 (or s (error "expression did not match subexpression %d" match)) | |
304 ;; don't fontify this keyword if we're already in some other context. | |
305 (or (if allow-overlap-p nil (font-lock-any-properties-p s e)) | |
306 (progn | |
4700
1d8de7410270
(font-lock-fontify-region): Put on `font-lock'
Richard M. Stallman <rms@gnu.org>
parents:
4459
diff
changeset
|
307 (put-text-property s e 'face face) |
1d8de7410270
(font-lock-fontify-region): Put on `font-lock'
Richard M. Stallman <rms@gnu.org>
parents:
4459
diff
changeset
|
308 (put-text-property s e 'font-lock t)))) |
4053 | 309 (if loudly (message "Fontifying %s... (regexps...%s)" |
310 (buffer-name) | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
311 (make-string (setq count (1+ count)) ?.)))) |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
312 (set-buffer-modified-p modified))) |
4053 | 313 |
314 ;; The user level functions | |
315 | |
316 (defvar font-lock-mode nil) ; for modeline | |
317 (or (assq 'font-lock-mode minor-mode-alist) | |
318 (setq minor-mode-alist | |
319 (append minor-mode-alist | |
320 '((font-lock-mode " Font"))))) | |
321 | |
322 (defvar font-lock-fontified nil) ; whether we have hacked this buffer | |
323 (put 'font-lock-fontified 'permanent-local t) | |
324 | |
325 ;;;###autoload | |
326 (defun font-lock-mode (&optional arg) | |
327 "Toggle Font Lock mode. | |
328 With arg, turn Font Lock mode on if and only if arg is positive. | |
329 | |
330 When Font Lock mode is enabled, text is fontified as you type it: | |
331 | |
332 - comments are displayed in `font-lock-comment-face'; | |
333 (That is a variable whose value should be a face name.) | |
334 - strings are displayed in `font-lock-string-face'; | |
335 - documentation strings are displayed in `font-lock-doc-string-face'; | |
336 - function and variable names in their defining forms are displayed | |
337 in `font-lock-function-name-face'; | |
338 - and certain other expressions are displayed in other faces | |
339 according to the value of the variable `font-lock-keywords'. | |
340 | |
341 When you turn Font Lock mode on/off, the buffer is fontified/defontified. | |
342 To fontify a buffer without having newly typed text become fontified, you | |
343 can use \\[font-lock-fontify-buffer]." | |
344 (interactive "P") | |
345 (let ((on-p (if (null arg) | |
346 (not font-lock-mode) | |
347 (> (prefix-numeric-value arg) 0)))) | |
348 (if (equal (buffer-name) " *Compiler Input*") ; hack for bytecomp... | |
349 (setq on-p nil)) | |
350 (or (memq after-change-function | |
351 '(nil font-lock-after-change-function)) | |
352 (error "after-change-function is %s" after-change-function)) | |
353 (set (make-local-variable 'after-change-function) | |
354 (if on-p 'font-lock-after-change-function nil)) | |
355 (set (make-local-variable 'font-lock-mode) on-p) | |
356 (cond (on-p | |
357 (font-lock-set-defaults) | |
358 (run-hooks 'font-lock-mode-hook) | |
359 (or font-lock-fontified (font-lock-fontify-buffer))) | |
360 (font-lock-fontified | |
361 (setq font-lock-fontified nil) | |
362 (font-lock-unfontify-region (point-min) (point-max)))) | |
363 (force-mode-line-update))) | |
364 | |
365 | |
366 (defun font-lock-fontify-buffer () | |
367 "Fontify the current buffer the way `font-lock-mode' would: | |
368 | |
369 - comments are displayed in `font-lock-comment-face'; | |
370 - strings are displayed in `font-lock-string-face'; | |
371 - documentation strings are displayed in `font-lock-doc-string-face'; | |
372 - function and variable names in their defining forms are displayed | |
373 in `font-lock-function-name-face'; | |
374 - and certain other expressions are displayed in other faces | |
375 according to the value of the variable `font-lock-keywords'. | |
376 | |
377 This can take a while for large buffers." | |
378 (interactive) | |
379 (let ((was-on font-lock-mode) | |
380 (font-lock-verbose (or font-lock-verbose (interactive-p)))) | |
381 (if font-lock-verbose (message "Fontifying %s..." (buffer-name))) | |
382 ;; Turn it on to run hooks and get the right font-lock-keywords. | |
383 (or was-on (font-lock-mode 1)) | |
384 (font-lock-unfontify-region (point-min) (point-max)) | |
385 (if font-lock-verbose (message "Fontifying %s... (syntactically...)" | |
386 (buffer-name))) | |
387 ;; (buffer-syntactic-context-flush-cache) | |
388 (save-excursion | |
389 (font-lock-fontify-region (point-min) (point-max)) | |
390 (if font-lock-verbose (message "Fontifying %s... (regexps...)" | |
391 (buffer-name))) | |
392 (font-lock-hack-keywords (point-min) (point-max) font-lock-verbose)) | |
393 (or was-on (font-lock-mode 0)) ; turn it off if it was off. | |
394 (set (make-local-variable 'font-lock-fontified) t) | |
395 (if font-lock-verbose (message "Fontifying %s... done." (buffer-name))) | |
396 )) | |
397 | |
398 | |
399 ;;; Various mode-specific information. | |
400 | |
401 (defun font-lock-set-defaults () | |
402 "sets font-lock-keywords to something appropriate for this mode." | |
403 (setq font-lock-keywords | |
404 (cond ((eq major-mode 'lisp-mode) lisp-font-lock-keywords) | |
405 ((eq major-mode 'emacs-lisp-mode) lisp-font-lock-keywords) | |
406 ((eq major-mode 'c-mode) c-font-lock-keywords) | |
407 ((eq major-mode 'c++-c-mode) c-font-lock-keywords) | |
408 ((eq major-mode 'c++-mode) c++-font-lock-keywords) | |
409 ((eq major-mode 'perl-mode) perl-font-lock-keywords) | |
410 ((eq major-mode 'tex-mode) tex-font-lock-keywords) | |
411 ((eq major-mode 'texinfo-mode) texi-font-lock-keywords) | |
412 (t nil)))) | |
413 | |
414 (defconst lisp-font-lock-keywords-1 | |
415 '(;; | |
416 ;; highlight defining forms. This doesn't work too nicely for | |
417 ;; (defun (setf foo) ...) but it does work for (defvar foo) which | |
418 ;; is more important. | |
419 ("^(def[-a-z]+\\s +\\([^ \t\n\)]+\\)" 1 font-lock-function-name-face) | |
420 ;; | |
421 ;; highlight CL keywords | |
422 ("\\s :\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1) | |
423 ;; | |
424 ;; this is highlights things like (def* (setf foo) (bar baz)), but may | |
425 ;; be slower (I haven't really thought about it) | |
426 ; ("^(def[-a-z]+\\s +\\(\\s(\\S)*\\s)\\|\\S(\\S *\\)" | |
427 ; 1 font-lock-function-name-face) | |
428 ) | |
429 "For consideration as a value of `lisp-font-lock-keywords'. | |
430 This does fairly subdued highlighting.") | |
431 | |
432 (defconst lisp-font-lock-keywords-2 | |
433 (append | |
434 lisp-font-lock-keywords-1 | |
435 '(;; | |
436 ;; Highlight control structures | |
437 ("(\\(cond\\|if\\|when\\|unless\\|[ec]?\\(type\\)?case\\)[ \t\n]" . 1) | |
438 ("(\\(while\\|do\\|let*?\\|flet\\|labels\\|prog[nv12*]?\\)[ \t\n]" . 1) | |
439 ("(\\(catch\\|\\throw\\|block\\|return\\|return-from\\)[ \t\n]" . 1) | |
440 ("(\\(save-restriction\\|save-window-restriction\\)[ \t\n]" . 1) | |
441 ("(\\(save-excursion\\|unwind-protect\\|condition-case\\)[ \t\n]" . 1) | |
442 ;; | |
443 ;; highlight function names in emacs-lisp docstrings (in the syntax | |
444 ;; that substitute-command-keys understands.) | |
445 ("\\\\\\\\\\[\\([^]\\\n]+\\)]" 1 font-lock-keyword-face t) | |
446 ;; | |
447 ;; highlight words inside `' which tend to be function names | |
448 ("`\\([-a-zA-Z0-9_][-a-zA-Z0-9_][-a-zA-Z0-9_.]+\\)'" | |
449 1 font-lock-keyword-face t) | |
450 )) | |
451 "For consideration as a value of `lisp-font-lock-keywords'. | |
452 This does a lot more highlighting.") | |
453 | |
454 ;; default to the gaudier variety? | |
455 ;(defvar lisp-font-lock-keywords lisp-font-lock-keywords-2 | |
456 ; "Additional expressions to highlight in Lisp modes.") | |
457 (defvar lisp-font-lock-keywords lisp-font-lock-keywords-1 | |
458 "Additional expressions to highlight in Lisp modes.") | |
459 | |
460 | |
461 (defconst c-font-lock-keywords-1 nil | |
462 "For consideration as a value of `c-font-lock-keywords'. | |
463 This does fairly subdued highlighting.") | |
464 | |
465 (defconst c-font-lock-keywords-2 nil | |
466 "For consideration as a value of `c-font-lock-keywords'. | |
467 This does a lot more highlighting.") | |
468 | |
469 (let ((storage "auto\\|extern\\|register\\|static\\|volatile") | |
470 (prefixes "unsigned\\|short\\|long") | |
471 (types (concat "int\\|char\\|float\\|double\\|void\\|struct\\|" | |
472 "union\\|enum\\|typedef")) | |
473 (ctoken "[a-zA-Z0-9_:~*]+") | |
474 ) | |
475 (setq c-font-lock-keywords-1 | |
476 (list | |
477 ;; fontify preprocessor directives as comments. | |
478 '("^#[ \t]*[a-z]+" . font-lock-comment-face) | |
479 ;; | |
480 ;; fontify names being defined. | |
481 '("^#[ \t]*\\(define\\|undef\\)[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)" 2 | |
482 font-lock-function-name-face) | |
483 ;; | |
484 ;; fontify other preprocessor lines. | |
485 '("^#[ \t]*\\(if\\|ifn?def\\)[ \t]+\\([^\n]+\\)" | |
486 2 font-lock-function-name-face t) | |
487 ;; | |
488 ;; fontify the filename in #include <...> | |
489 ;; don't need to do this for #include "..." because those were | |
490 ;; already fontified as strings by the syntactic pass. | |
491 '("^#[ \t]*include[ \t]+\\(<[^>\"\n]+>\\)" 1 font-lock-string-face) | |
492 ;; | |
493 ;; fontify the names of functions being defined. | |
494 (list (concat | |
495 "^\\(" ctoken "[ \t]+\\)?" ; type specs; there can be no | |
496 "\\(" ctoken "[ \t]+\\)?" ; more than 3 tokens, right? | |
497 "\\(" ctoken "[ \t]+\\)?" | |
4239
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
498 "\\([*&]+[ \t]*\\)?" ; pointer |
4053 | 499 "\\(" ctoken "\\)[ \t]*(") ; name |
500 5 'font-lock-function-name-face) | |
501 ;; | |
502 ;; | |
503 ;; Fontify structure names (in structure definition form). | |
504 (list (concat "^\\(typedef[ \t]+struct\\|struct\\|static[ \t]+struct\\)" | |
505 "[ \t]+\\(" ctoken "\\)[ \t]*\\(\{\\|$\\)") | |
506 2 'font-lock-function-name-face) | |
507 ;; | |
508 ;; Fontify case clauses. This is fast because its anchored on the left. | |
509 '("case[ \t]+\\(\\(\\sw\\|\\s_\\)+\\):". 1) | |
510 '("\\<\\(default\\):". 1) | |
511 )) | |
512 | |
513 (setq c-font-lock-keywords-2 | |
514 (append c-font-lock-keywords-1 | |
515 (list | |
516 ;; | |
517 ;; fontify all storage classes and type specifiers | |
518 (cons (concat "\\<\\(" storage "\\)\\>") 'font-lock-type-face) | |
519 (cons (concat "\\<\\(" types "\\)\\>") 'font-lock-type-face) | |
520 (cons (concat "\\<\\(" prefixes "[ \t]+" types "\\)\\>") | |
521 'font-lock-type-face) | |
522 ;; | |
523 ;; fontify all builtin tokens | |
524 (cons (concat | |
525 "[ \t]\\(" | |
526 (mapconcat 'identity | |
527 '("for" "while" "do" "return" "goto" "case" "break" "switch" | |
528 "if" "then" "else if" "else" "return" "default" "continue" | |
529 "default" | |
530 ) | |
531 "\\|") | |
532 "\\)[ \t\n(){};,]") | |
533 1) | |
534 ;; | |
535 ;; fontify case targets and goto-tags. This is slow because the | |
536 ;; expression is anchored on the right. | |
537 "\\(\\(\\sw\\|\\s_\\)+\\):" | |
538 ;; | |
539 ;; Fontify variables declared with structures, or typedef names. | |
540 '("}[ \t*]*\\(\\(\\sw\\|\\s_\\)+\\)[ \t]*[,;]" | |
541 1 font-lock-function-name-face) | |
542 ;; | |
543 ;; Fontify global variables without a type. | |
544 ; '("^\\([_a-zA-Z0-9:~*]+\\)[ \t]*[[;={]" 1 font-lock-function-name-face) | |
545 | |
546 ))) | |
547 ) | |
548 | |
549 ; default to the gaudier variety? | |
550 ;(defvar c-font-lock-keywords c-font-lock-keywords-2 | |
551 ; "Additional expressions to highlight in C mode.") | |
552 (defvar c-font-lock-keywords c-font-lock-keywords-1 | |
553 "Additional expressions to highlight in C mode.") | |
554 | |
555 (defvar c++-font-lock-keywords c-font-lock-keywords | |
556 "Additional expressions to highlight in C++ mode.") | |
557 | |
558 | |
559 (defvar perl-font-lock-keywords | |
560 (list | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
561 (cons (concat "[ \n\t{]*\\(" |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
562 (mapconcat 'identity |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
563 '("if" "until" "while" "elsif" "else" "unless" "for" |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
564 "foreach" "continue" "exit" "die" "last" "goto" "next" |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
565 "redo" "return" "local" "exec") |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
566 "\\|") |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
567 "\\)[ \n\t;(]") 1) |
4053 | 568 (mapconcat 'identity |
569 '("#endif" "#else" "#ifdef" "#ifndef" "#if" "#include" | |
570 "#define" "#undef") | |
571 "\\|") | |
4239
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
572 '("^[ \n\t]*sub[ \t]+\\([^ \t{]+\\)[ \t]*[{]" 1 font-lock-function-name-face) |
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
573 '("[ \n\t{]*\\(eval\\)[ \n\t(;]" 1 font-lock-function-name-face) |
4053 | 574 '("\\(--- .* ---\\|=== .* ===\\)" . font-lock-doc-string-face) |
575 ) | |
576 "Additional expressions to highlight in Perl mode.") | |
577 | |
578 (defvar tex-font-lock-keywords | |
579 (list | |
580 '("\\(\\\\\\w+\\)" 1 font-lock-keyword-face t) | |
581 '("{\\\\em\\([^}]+\\)}" 1 font-lock-comment-face t) | |
582 '("{\\\\bf\\([^}]+\\)}" 1 font-lock-keyword-face t) | |
583 '("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face t) | |
584 '("\\\\\\(begin\\|end\\){\\([a-zA-Z0-9\\*]+\\)}" | |
585 2 font-lock-function-name-face t) | |
586 '("[^\\\\]\\$\\([^$]*\\)\\$" 1 font-lock-string-face t) | |
587 ; '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t) | |
588 ) | |
589 "Additional expressions to highlight in TeX mode.") | |
590 | |
591 (defvar texi-font-lock-keywords | |
592 (list | |
593 "@\\(@\\|[^}\t \n{]+\\)" ;commands | |
594 '("^\\(@c\\|@comment\\)[ \t].*$" . font-lock-comment-face) ;comments | |
595 '("^\\(*.*\\)[\t ]*$" 1 font-lock-function-name-face t) ;menu items | |
596 '("@\\(emph\\|strong\\|b\\|i\\){\\([^}]+\\)" 2 font-lock-comment-face t) | |
597 '("@\\(file\\|kbd\\|key\\){\\([^}]+\\)" 2 font-lock-string-face t) | |
598 '("@\\(samp\\|code\\|var\\){\\([^}]+\\)" 2 font-lock-function-name-face t) | |
599 '("@\\(xref\\|pxref\\){\\([^}]+\\)" 2 font-lock-keyword-face t) | |
600 '("@end *\\([a-zA-Z0-9]+\\)[ \t]*$" 1 font-lock-function-name-face t) | |
601 '("@item \\(.*\\)$" 1 font-lock-function-name-face t) | |
602 '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t) | |
603 ) | |
604 "Additional expressions to highlight in TeXinfo mode.") | |
605 | |
606 (provide 'font-lock) | |
607 | |
608 ;;; font-lock.el ends here |