Mercurial > emacs
annotate lisp/font-lock.el @ 4643:004c38daf0ae
(mkdir, rmdir): Use wait_for_termination to wait.
Redirect descriptors 0...2 to /dev/null.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 15 Aug 1993 04:28:05 +0000 |
parents | 2d8f7239f2ca |
children | 1d8de7410270 |
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) | |
153 (setq state (parse-partial-sexp beg (point) nil nil state)))) | |
154 ;; Likewise for a comment. | |
155 (if (or (nth 4 state) (nth 7 state)) | |
156 (let ((beg (point))) | |
157 (while (and (re-search-forward (if comment-end | |
158 (concat "\\s>\\|" | |
159 (regexp-quote comment-end)) | |
160 "\\s>") | |
161 end 'move) | |
162 (nth 3 (parse-partial-sexp beg (point) | |
163 nil nil state)))) | |
164 (put-text-property beg (point) 'face font-lock-comment-face) | |
165 (setq state (parse-partial-sexp beg (point) nil nil state)))) | |
166 ;; Find each interesting place between here and END. | |
167 (while (and (< (point) end) | |
168 (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
|
169 (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
|
170 (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
|
171 "\\s\"") |
2d8f7239f2ca
(font-lock-fontify-region): Handle comment-start-skip = nil.
Richard M. Stallman <rms@gnu.org>
parents:
4239
diff
changeset
|
172 end t) |
4053 | 173 ;; Clear out the fonts of what we skip over. |
174 (progn (remove-text-properties prev (point) '(face nil)) t) | |
175 ;; Verify the state at that place | |
176 ;; so we don't get fooled by \" or \;. | |
177 (setq state (parse-partial-sexp prev (point) | |
178 nil nil state))) | |
179 (let ((here (point))) | |
180 (if (or (nth 4 state) (nth 7 state)) | |
181 ;; We found a real comment start. | |
182 (let ((beg (match-beginning 0))) | |
183 (goto-char beg) | |
184 (save-restriction | |
185 (narrow-to-region (point-min) end) | |
186 (condition-case nil | |
187 (progn | |
188 (forward-comment 1) | |
189 ;; forward-comment skips all whitespace, | |
190 ;; so go back to the real end of the comment. | |
191 (skip-chars-backward " \t")) | |
192 (error (goto-char end)))) | |
193 (put-text-property beg (point) 'face font-lock-comment-face) | |
194 (setq state (parse-partial-sexp here (point) nil nil state))) | |
195 (if (nth 3 state) | |
196 (let ((beg (match-beginning 0))) | |
197 (while (and (re-search-forward "\\s\"" end 'move) | |
198 (nth 3 (parse-partial-sexp here (point) | |
199 nil nil state)))) | |
200 (put-text-property beg (point) 'face font-lock-string-face) | |
201 (setq state (parse-partial-sexp here (point) nil nil state)))) | |
202 )) | |
203 ;; Make sure PREV is non-nil after the loop | |
204 ;; only if it was set on the very last iteration. | |
205 (setq prev nil)) | |
206 (and prev | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
207 (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
|
208 (set-buffer-modified-p modified)))) |
4053 | 209 |
210 ;; This code used to be used to show a string on reaching the end of it. | |
211 ;; It is probably not needed due to later changes to handle strings | |
212 ;; starting before the region in question. | |
213 ;; (if (and (null (nth 3 state)) | |
214 ;; (eq (char-syntax (preceding-char)) ?\") | |
215 ;; (save-excursion | |
216 ;; (nth 3 (parse-partial-sexp prev (1- (point)) | |
217 ;; nil nil prevstate)))) | |
218 ;; ;; We found the end of a string. | |
219 ;; (save-excursion | |
220 ;; (setq foo2 (point)) | |
221 ;; (let ((ept (point))) | |
222 ;; (forward-sexp -1) | |
223 ;; ;; Highlight the string when we see the end. | |
224 ;; ;; Doing it at the start leads to trouble: | |
225 ;; ;; either it fails to handle multiline strings | |
226 ;; ;; or it can run away when an unmatched " is inserted. | |
227 ;; (put-text-property (point) ept 'face | |
228 ;; (if (= (car state) 1) | |
229 ;; font-lock-doc-string-face | |
230 ;; font-lock-string-face))))) | |
231 | |
232 (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
|
233 (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
|
234 (buffer-read-only nil)) |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
235 (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
|
236 (set-buffer-modified-p modified))) |
4053 | 237 |
238 ;; Called when any modification is made to buffer text. | |
239 (defun font-lock-after-change-function (beg end old-len) | |
240 (save-excursion | |
241 (save-match-data | |
242 (goto-char beg) | |
243 ;; Discard the cache info if text before it has changed. | |
244 (and font-lock-cache-position | |
245 (> font-lock-cache-position beg) | |
246 (setq font-lock-cache-position nil)) | |
247 ;; Rescan till end of line. yes! | |
248 (goto-char end) | |
249 (end-of-line) | |
250 (setq end (point)) | |
251 (goto-char beg) | |
252 (beginning-of-line) | |
253 (setq beg (point)) | |
4239
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
254 ;; First scan for strings and comments. |
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
255 ;; Must scan from line start in case of |
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
256 ;; inserting space into `intfoo () {}'. |
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
257 (font-lock-fontify-region beg (1+ end)) |
4053 | 258 ;; Now scan for keywords. |
259 (font-lock-hack-keywords beg end)))) | |
260 | |
261 ;;; Fontifying arbitrary patterns | |
262 | |
263 (defsubst font-lock-any-properties-p (start end) | |
264 (or (get-text-property start 'font-lock) | |
265 (let ((next (next-single-property-change start 'font-lock))) | |
266 (and next (< next end))))) | |
267 | |
268 (defun font-lock-hack-keywords (start end &optional loudly) | |
269 (goto-char start) | |
270 (let ((case-fold-search font-lock-keywords-case-fold-search) | |
271 (rest font-lock-keywords) | |
272 (count 0) | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
273 (buffer-read-only nil) |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
274 (modified (buffer-modified-p)) |
4053 | 275 first str match face s e allow-overlap-p) |
276 (while rest | |
277 (setq first (car rest) rest (cdr rest)) | |
278 (goto-char start) | |
279 (cond ((consp first) | |
280 (setq str (car first)) | |
281 (cond ((consp (cdr first)) | |
282 (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
|
283 face (eval (nth 2 first)) |
4053 | 284 allow-overlap-p (nth 3 first))) |
285 ((symbolp (cdr first)) | |
286 (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
|
287 face (eval (cdr first)))) |
4053 | 288 (t |
289 (setq match (cdr first) | |
290 allow-overlap-p nil | |
291 face font-lock-keyword-face)))) | |
292 (t | |
293 (setq str first match 0 allow-overlap-p nil | |
294 face font-lock-keyword-face))) | |
295 ;(message "regexp: %s" str) | |
296 (while (re-search-forward str end t) | |
297 (setq s (match-beginning match) | |
298 e (match-end match)) | |
299 (or s (error "expression did not match subexpression %d" match)) | |
300 ;; don't fontify this keyword if we're already in some other context. | |
301 (or (if allow-overlap-p nil (font-lock-any-properties-p s e)) | |
302 (progn | |
303 (put-text-property s e 'face face)))) | |
304 (if loudly (message "Fontifying %s... (regexps...%s)" | |
305 (buffer-name) | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
306 (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
|
307 (set-buffer-modified-p modified))) |
4053 | 308 |
309 ;; The user level functions | |
310 | |
311 (defvar font-lock-mode nil) ; for modeline | |
312 (or (assq 'font-lock-mode minor-mode-alist) | |
313 (setq minor-mode-alist | |
314 (append minor-mode-alist | |
315 '((font-lock-mode " Font"))))) | |
316 | |
317 (defvar font-lock-fontified nil) ; whether we have hacked this buffer | |
318 (put 'font-lock-fontified 'permanent-local t) | |
319 | |
320 ;;;###autoload | |
321 (defun font-lock-mode (&optional arg) | |
322 "Toggle Font Lock mode. | |
323 With arg, turn Font Lock mode on if and only if arg is positive. | |
324 | |
325 When Font Lock mode is enabled, text is fontified as you type it: | |
326 | |
327 - comments are displayed in `font-lock-comment-face'; | |
328 (That is a variable whose value should be a face name.) | |
329 - strings are displayed in `font-lock-string-face'; | |
330 - documentation strings are displayed in `font-lock-doc-string-face'; | |
331 - function and variable names in their defining forms are displayed | |
332 in `font-lock-function-name-face'; | |
333 - and certain other expressions are displayed in other faces | |
334 according to the value of the variable `font-lock-keywords'. | |
335 | |
336 When you turn Font Lock mode on/off, the buffer is fontified/defontified. | |
337 To fontify a buffer without having newly typed text become fontified, you | |
338 can use \\[font-lock-fontify-buffer]." | |
339 (interactive "P") | |
340 (let ((on-p (if (null arg) | |
341 (not font-lock-mode) | |
342 (> (prefix-numeric-value arg) 0)))) | |
343 (if (equal (buffer-name) " *Compiler Input*") ; hack for bytecomp... | |
344 (setq on-p nil)) | |
345 (or (memq after-change-function | |
346 '(nil font-lock-after-change-function)) | |
347 (error "after-change-function is %s" after-change-function)) | |
348 (set (make-local-variable 'after-change-function) | |
349 (if on-p 'font-lock-after-change-function nil)) | |
350 (set (make-local-variable 'font-lock-mode) on-p) | |
351 (cond (on-p | |
352 (font-lock-set-defaults) | |
353 (run-hooks 'font-lock-mode-hook) | |
354 (or font-lock-fontified (font-lock-fontify-buffer))) | |
355 (font-lock-fontified | |
356 (setq font-lock-fontified nil) | |
357 (font-lock-unfontify-region (point-min) (point-max)))) | |
358 (force-mode-line-update))) | |
359 | |
360 | |
361 (defun font-lock-fontify-buffer () | |
362 "Fontify the current buffer the way `font-lock-mode' would: | |
363 | |
364 - comments are displayed in `font-lock-comment-face'; | |
365 - strings are displayed in `font-lock-string-face'; | |
366 - documentation strings are displayed in `font-lock-doc-string-face'; | |
367 - function and variable names in their defining forms are displayed | |
368 in `font-lock-function-name-face'; | |
369 - and certain other expressions are displayed in other faces | |
370 according to the value of the variable `font-lock-keywords'. | |
371 | |
372 This can take a while for large buffers." | |
373 (interactive) | |
374 (let ((was-on font-lock-mode) | |
375 (font-lock-verbose (or font-lock-verbose (interactive-p)))) | |
376 (if font-lock-verbose (message "Fontifying %s..." (buffer-name))) | |
377 ;; Turn it on to run hooks and get the right font-lock-keywords. | |
378 (or was-on (font-lock-mode 1)) | |
379 (font-lock-unfontify-region (point-min) (point-max)) | |
380 (if font-lock-verbose (message "Fontifying %s... (syntactically...)" | |
381 (buffer-name))) | |
382 ;; (buffer-syntactic-context-flush-cache) | |
383 (save-excursion | |
384 (font-lock-fontify-region (point-min) (point-max)) | |
385 (if font-lock-verbose (message "Fontifying %s... (regexps...)" | |
386 (buffer-name))) | |
387 (font-lock-hack-keywords (point-min) (point-max) font-lock-verbose)) | |
388 (or was-on (font-lock-mode 0)) ; turn it off if it was off. | |
389 (set (make-local-variable 'font-lock-fontified) t) | |
390 (if font-lock-verbose (message "Fontifying %s... done." (buffer-name))) | |
391 )) | |
392 | |
393 | |
394 ;;; Various mode-specific information. | |
395 | |
396 (defun font-lock-set-defaults () | |
397 "sets font-lock-keywords to something appropriate for this mode." | |
398 (setq font-lock-keywords | |
399 (cond ((eq major-mode 'lisp-mode) lisp-font-lock-keywords) | |
400 ((eq major-mode 'emacs-lisp-mode) lisp-font-lock-keywords) | |
401 ((eq major-mode 'c-mode) c-font-lock-keywords) | |
402 ((eq major-mode 'c++-c-mode) c-font-lock-keywords) | |
403 ((eq major-mode 'c++-mode) c++-font-lock-keywords) | |
404 ((eq major-mode 'perl-mode) perl-font-lock-keywords) | |
405 ((eq major-mode 'tex-mode) tex-font-lock-keywords) | |
406 ((eq major-mode 'texinfo-mode) texi-font-lock-keywords) | |
407 (t nil)))) | |
408 | |
409 (defconst lisp-font-lock-keywords-1 | |
410 '(;; | |
411 ;; highlight defining forms. This doesn't work too nicely for | |
412 ;; (defun (setf foo) ...) but it does work for (defvar foo) which | |
413 ;; is more important. | |
414 ("^(def[-a-z]+\\s +\\([^ \t\n\)]+\\)" 1 font-lock-function-name-face) | |
415 ;; | |
416 ;; highlight CL keywords | |
417 ("\\s :\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1) | |
418 ;; | |
419 ;; this is highlights things like (def* (setf foo) (bar baz)), but may | |
420 ;; be slower (I haven't really thought about it) | |
421 ; ("^(def[-a-z]+\\s +\\(\\s(\\S)*\\s)\\|\\S(\\S *\\)" | |
422 ; 1 font-lock-function-name-face) | |
423 ) | |
424 "For consideration as a value of `lisp-font-lock-keywords'. | |
425 This does fairly subdued highlighting.") | |
426 | |
427 (defconst lisp-font-lock-keywords-2 | |
428 (append | |
429 lisp-font-lock-keywords-1 | |
430 '(;; | |
431 ;; Highlight control structures | |
432 ("(\\(cond\\|if\\|when\\|unless\\|[ec]?\\(type\\)?case\\)[ \t\n]" . 1) | |
433 ("(\\(while\\|do\\|let*?\\|flet\\|labels\\|prog[nv12*]?\\)[ \t\n]" . 1) | |
434 ("(\\(catch\\|\\throw\\|block\\|return\\|return-from\\)[ \t\n]" . 1) | |
435 ("(\\(save-restriction\\|save-window-restriction\\)[ \t\n]" . 1) | |
436 ("(\\(save-excursion\\|unwind-protect\\|condition-case\\)[ \t\n]" . 1) | |
437 ;; | |
438 ;; highlight function names in emacs-lisp docstrings (in the syntax | |
439 ;; that substitute-command-keys understands.) | |
440 ("\\\\\\\\\\[\\([^]\\\n]+\\)]" 1 font-lock-keyword-face t) | |
441 ;; | |
442 ;; highlight words inside `' which tend to be function names | |
443 ("`\\([-a-zA-Z0-9_][-a-zA-Z0-9_][-a-zA-Z0-9_.]+\\)'" | |
444 1 font-lock-keyword-face t) | |
445 )) | |
446 "For consideration as a value of `lisp-font-lock-keywords'. | |
447 This does a lot more highlighting.") | |
448 | |
449 ;; default to the gaudier variety? | |
450 ;(defvar lisp-font-lock-keywords lisp-font-lock-keywords-2 | |
451 ; "Additional expressions to highlight in Lisp modes.") | |
452 (defvar lisp-font-lock-keywords lisp-font-lock-keywords-1 | |
453 "Additional expressions to highlight in Lisp modes.") | |
454 | |
455 | |
456 (defconst c-font-lock-keywords-1 nil | |
457 "For consideration as a value of `c-font-lock-keywords'. | |
458 This does fairly subdued highlighting.") | |
459 | |
460 (defconst c-font-lock-keywords-2 nil | |
461 "For consideration as a value of `c-font-lock-keywords'. | |
462 This does a lot more highlighting.") | |
463 | |
464 (let ((storage "auto\\|extern\\|register\\|static\\|volatile") | |
465 (prefixes "unsigned\\|short\\|long") | |
466 (types (concat "int\\|char\\|float\\|double\\|void\\|struct\\|" | |
467 "union\\|enum\\|typedef")) | |
468 (ctoken "[a-zA-Z0-9_:~*]+") | |
469 ) | |
470 (setq c-font-lock-keywords-1 | |
471 (list | |
472 ;; fontify preprocessor directives as comments. | |
473 '("^#[ \t]*[a-z]+" . font-lock-comment-face) | |
474 ;; | |
475 ;; fontify names being defined. | |
476 '("^#[ \t]*\\(define\\|undef\\)[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)" 2 | |
477 font-lock-function-name-face) | |
478 ;; | |
479 ;; fontify other preprocessor lines. | |
480 '("^#[ \t]*\\(if\\|ifn?def\\)[ \t]+\\([^\n]+\\)" | |
481 2 font-lock-function-name-face t) | |
482 ;; | |
483 ;; fontify the filename in #include <...> | |
484 ;; don't need to do this for #include "..." because those were | |
485 ;; already fontified as strings by the syntactic pass. | |
486 '("^#[ \t]*include[ \t]+\\(<[^>\"\n]+>\\)" 1 font-lock-string-face) | |
487 ;; | |
488 ;; fontify the names of functions being defined. | |
489 (list (concat | |
490 "^\\(" ctoken "[ \t]+\\)?" ; type specs; there can be no | |
491 "\\(" ctoken "[ \t]+\\)?" ; more than 3 tokens, right? | |
492 "\\(" ctoken "[ \t]+\\)?" | |
4239
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
493 "\\([*&]+[ \t]*\\)?" ; pointer |
4053 | 494 "\\(" ctoken "\\)[ \t]*(") ; name |
495 5 'font-lock-function-name-face) | |
496 ;; | |
497 ;; | |
498 ;; Fontify structure names (in structure definition form). | |
499 (list (concat "^\\(typedef[ \t]+struct\\|struct\\|static[ \t]+struct\\)" | |
500 "[ \t]+\\(" ctoken "\\)[ \t]*\\(\{\\|$\\)") | |
501 2 'font-lock-function-name-face) | |
502 ;; | |
503 ;; Fontify case clauses. This is fast because its anchored on the left. | |
504 '("case[ \t]+\\(\\(\\sw\\|\\s_\\)+\\):". 1) | |
505 '("\\<\\(default\\):". 1) | |
506 )) | |
507 | |
508 (setq c-font-lock-keywords-2 | |
509 (append c-font-lock-keywords-1 | |
510 (list | |
511 ;; | |
512 ;; fontify all storage classes and type specifiers | |
513 (cons (concat "\\<\\(" storage "\\)\\>") 'font-lock-type-face) | |
514 (cons (concat "\\<\\(" types "\\)\\>") 'font-lock-type-face) | |
515 (cons (concat "\\<\\(" prefixes "[ \t]+" types "\\)\\>") | |
516 'font-lock-type-face) | |
517 ;; | |
518 ;; fontify all builtin tokens | |
519 (cons (concat | |
520 "[ \t]\\(" | |
521 (mapconcat 'identity | |
522 '("for" "while" "do" "return" "goto" "case" "break" "switch" | |
523 "if" "then" "else if" "else" "return" "default" "continue" | |
524 "default" | |
525 ) | |
526 "\\|") | |
527 "\\)[ \t\n(){};,]") | |
528 1) | |
529 ;; | |
530 ;; fontify case targets and goto-tags. This is slow because the | |
531 ;; expression is anchored on the right. | |
532 "\\(\\(\\sw\\|\\s_\\)+\\):" | |
533 ;; | |
534 ;; Fontify variables declared with structures, or typedef names. | |
535 '("}[ \t*]*\\(\\(\\sw\\|\\s_\\)+\\)[ \t]*[,;]" | |
536 1 font-lock-function-name-face) | |
537 ;; | |
538 ;; Fontify global variables without a type. | |
539 ; '("^\\([_a-zA-Z0-9:~*]+\\)[ \t]*[[;={]" 1 font-lock-function-name-face) | |
540 | |
541 ))) | |
542 ) | |
543 | |
544 ; default to the gaudier variety? | |
545 ;(defvar c-font-lock-keywords c-font-lock-keywords-2 | |
546 ; "Additional expressions to highlight in C mode.") | |
547 (defvar c-font-lock-keywords c-font-lock-keywords-1 | |
548 "Additional expressions to highlight in C mode.") | |
549 | |
550 (defvar c++-font-lock-keywords c-font-lock-keywords | |
551 "Additional expressions to highlight in C++ mode.") | |
552 | |
553 | |
554 (defvar perl-font-lock-keywords | |
555 (list | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
556 (cons (concat "[ \n\t{]*\\(" |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
557 (mapconcat 'identity |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
558 '("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
|
559 "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
|
560 "redo" "return" "local" "exec") |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
561 "\\|") |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
562 "\\)[ \n\t;(]") 1) |
4053 | 563 (mapconcat 'identity |
564 '("#endif" "#else" "#ifdef" "#ifndef" "#if" "#include" | |
565 "#define" "#undef") | |
566 "\\|") | |
4239
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
567 '("^[ \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
|
568 '("[ \n\t{]*\\(eval\\)[ \n\t(;]" 1 font-lock-function-name-face) |
4053 | 569 '("\\(--- .* ---\\|=== .* ===\\)" . font-lock-doc-string-face) |
570 ) | |
571 "Additional expressions to highlight in Perl mode.") | |
572 | |
573 (defvar tex-font-lock-keywords | |
574 (list | |
575 '("\\(\\\\\\w+\\)" 1 font-lock-keyword-face t) | |
576 '("{\\\\em\\([^}]+\\)}" 1 font-lock-comment-face t) | |
577 '("{\\\\bf\\([^}]+\\)}" 1 font-lock-keyword-face t) | |
578 '("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face t) | |
579 '("\\\\\\(begin\\|end\\){\\([a-zA-Z0-9\\*]+\\)}" | |
580 2 font-lock-function-name-face t) | |
581 '("[^\\\\]\\$\\([^$]*\\)\\$" 1 font-lock-string-face t) | |
582 ; '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t) | |
583 ) | |
584 "Additional expressions to highlight in TeX mode.") | |
585 | |
586 (defvar texi-font-lock-keywords | |
587 (list | |
588 "@\\(@\\|[^}\t \n{]+\\)" ;commands | |
589 '("^\\(@c\\|@comment\\)[ \t].*$" . font-lock-comment-face) ;comments | |
590 '("^\\(*.*\\)[\t ]*$" 1 font-lock-function-name-face t) ;menu items | |
591 '("@\\(emph\\|strong\\|b\\|i\\){\\([^}]+\\)" 2 font-lock-comment-face t) | |
592 '("@\\(file\\|kbd\\|key\\){\\([^}]+\\)" 2 font-lock-string-face t) | |
593 '("@\\(samp\\|code\\|var\\){\\([^}]+\\)" 2 font-lock-function-name-face t) | |
594 '("@\\(xref\\|pxref\\){\\([^}]+\\)" 2 font-lock-keyword-face t) | |
595 '("@end *\\([a-zA-Z0-9]+\\)[ \t]*$" 1 font-lock-function-name-face t) | |
596 '("@item \\(.*\\)$" 1 font-lock-function-name-face t) | |
597 '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t) | |
598 ) | |
599 "Additional expressions to highlight in TeXinfo mode.") | |
600 | |
601 (provide 'font-lock) | |
602 | |
603 ;;; font-lock.el ends here |