Mercurial > emacs
annotate lisp/font-lock.el @ 6160:5a40bc311e2f
(completion-list-mode): Set completion-reference-buffer
to the buffer for which the completions were requested.
(completion-reference-buffer): New variable.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 02 Mar 1994 23:09:40 +0000 |
parents | 00cee8387866 |
children | d960f0463014 |
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 | |
4727
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
90 \"string\" ; A regexp to highlight in the |
4053 | 91 ; `font-lock-keyword-face'. |
4727
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
92 (\"string\" . N) ; Highlight subexpression N of the regexp. |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
93 (\"string\" . face-name) ; Use the named face |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
94 (\"string\" N face-name) ; Both of the above |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
95 (\"string\" N face-name t) ; This allows highlighting to override |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
96 ; already-highlighted regions. |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
97 (\"string\" N face-name keep) ; This allows highlighting to occur |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
98 ; even if some parts of what STRING matches |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
99 ; are already highlighted--but does not alter |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
100 ; the existing highlighting of those parts. |
4053 | 101 |
102 These regular expressions should not match text which spans lines. | |
103 While \\[font-lock-fontify-buffer] handles multi-line patterns correctly, | |
104 updating when you edit the buffer does not, | |
105 since it considers text one line at a time. | |
106 | |
107 Be careful composing regexps for this list; the wrong pattern can dramatically | |
108 slow things down!") | |
109 | |
110 (defvar font-lock-keywords-case-fold-search nil | |
111 "*Non-nil means the patterns in `font-lock-keywords' are case-insensitive.") | |
112 | |
113 (defvar font-lock-verbose t | |
114 "*Non-nil means `font-lock-fontify-buffer' should print status messages.") | |
115 | |
4054 | 116 ;;;###autoload |
4053 | 117 (defvar font-lock-mode-hook nil |
118 "Function or functions to run on entry to Font Lock mode.") | |
119 | |
120 ;;; These variables record, for each buffer, | |
121 ;;; the parse state at a particular position, always the start of a line. | |
122 ;;; This is used to make font-lock-fontify-region faster. | |
123 (defvar font-lock-cache-position nil) | |
124 (defvar font-lock-cache-state nil) | |
125 (make-variable-buffer-local 'font-lock-cache-position) | |
126 (make-variable-buffer-local 'font-lock-cache-state) | |
127 | |
128 (defun font-lock-fontify-region (start end) | |
129 "Put proper face on each string and comment between START and END." | |
130 (save-excursion | |
131 (goto-char start) | |
132 (beginning-of-line) | |
133 (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
|
134 (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
|
135 state startline prev prevstate |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
136 (modified (buffer-modified-p))) |
4053 | 137 ;; Find the state at the line-beginning before START. |
138 (setq startline (point)) | |
139 (if (eq (point) font-lock-cache-position) | |
140 (setq state font-lock-cache-state) | |
141 ;; Find outermost containing sexp. | |
142 (beginning-of-defun) | |
143 ;; Find the state at STARTLINE. | |
144 (while (< (point) startline) | |
145 (setq state (parse-partial-sexp (point) startline 0))) | |
146 (setq font-lock-cache-state state | |
147 font-lock-cache-position (point))) | |
148 ;; Now find the state precisely at START. | |
149 (setq state (parse-partial-sexp (point) start nil nil state)) | |
150 ;; If the region starts inside a string, show the extent of it. | |
151 (if (nth 3 state) | |
152 (let ((beg (point))) | |
153 (while (and (re-search-forward "\\s\"" end 'move) | |
154 (nth 3 (parse-partial-sexp beg (point) | |
155 nil nil state)))) | |
156 (put-text-property beg (point) 'face font-lock-string-face) | |
157 (setq state (parse-partial-sexp beg (point) nil nil state)))) | |
158 ;; Likewise for a comment. | |
159 (if (or (nth 4 state) (nth 7 state)) | |
160 (let ((beg (point))) | |
161 (while (and (re-search-forward (if comment-end | |
162 (concat "\\s>\\|" | |
163 (regexp-quote comment-end)) | |
164 "\\s>") | |
165 end 'move) | |
166 (nth 3 (parse-partial-sexp beg (point) | |
167 nil nil state)))) | |
168 (put-text-property beg (point) 'face font-lock-comment-face) | |
169 (setq state (parse-partial-sexp beg (point) nil nil state)))) | |
170 ;; Find each interesting place between here and END. | |
171 (while (and (< (point) end) | |
172 (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
|
173 (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
|
174 (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
|
175 "\\s\"") |
2d8f7239f2ca
(font-lock-fontify-region): Handle comment-start-skip = nil.
Richard M. Stallman <rms@gnu.org>
parents:
4239
diff
changeset
|
176 end t) |
4053 | 177 ;; Clear out the fonts of what we skip over. |
178 (progn (remove-text-properties prev (point) '(face nil)) t) | |
179 ;; Verify the state at that place | |
180 ;; so we don't get fooled by \" or \;. | |
181 (setq state (parse-partial-sexp prev (point) | |
182 nil nil state))) | |
183 (let ((here (point))) | |
184 (if (or (nth 4 state) (nth 7 state)) | |
185 ;; We found a real comment start. | |
186 (let ((beg (match-beginning 0))) | |
187 (goto-char beg) | |
188 (save-restriction | |
189 (narrow-to-region (point-min) end) | |
190 (condition-case nil | |
191 (progn | |
192 (forward-comment 1) | |
193 ;; forward-comment skips all whitespace, | |
194 ;; so go back to the real end of the comment. | |
195 (skip-chars-backward " \t")) | |
196 (error (goto-char end)))) | |
197 (put-text-property beg (point) 'face font-lock-comment-face) | |
198 (setq state (parse-partial-sexp here (point) nil nil state))) | |
199 (if (nth 3 state) | |
200 (let ((beg (match-beginning 0))) | |
201 (while (and (re-search-forward "\\s\"" end 'move) | |
202 (nth 3 (parse-partial-sexp here (point) | |
203 nil nil state)))) | |
204 (put-text-property beg (point) 'face font-lock-string-face) | |
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) | |
4727
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
268 (or (get-text-property start 'face) |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
269 (let ((next (next-single-property-change start 'face))) |
4053 | 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)) | |
4727
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
306 (if (not (memq allow-overlap-p '(t nil))) |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
307 (save-excursion |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
308 (goto-char s) |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
309 (save-restriction |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
310 (narrow-to-region s e) |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
311 (while (not (eobp)) |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
312 (let ((next (next-single-property-change (point) 'face))) |
5056
64211dda414c
(font-lock-hack-keywords):
Richard M. Stallman <rms@gnu.org>
parents:
4897
diff
changeset
|
313 (if (or (null next) (> next (point-max))) |
4727
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
314 (setq next (point-max))) |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
315 (if (not (get-text-property (point) 'face)) |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
316 (put-text-property (point) next 'face face)) |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
317 (goto-char next))))) |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
318 (put-text-property s e 'face face)))) |
4053 | 319 (if loudly (message "Fontifying %s... (regexps...%s)" |
320 (buffer-name) | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
321 (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
|
322 (set-buffer-modified-p modified))) |
4053 | 323 |
324 ;; The user level functions | |
325 | |
326 (defvar font-lock-mode nil) ; for modeline | |
327 (or (assq 'font-lock-mode minor-mode-alist) | |
328 (setq minor-mode-alist | |
329 (append minor-mode-alist | |
330 '((font-lock-mode " Font"))))) | |
331 | |
332 (defvar font-lock-fontified nil) ; whether we have hacked this buffer | |
333 (put 'font-lock-fontified 'permanent-local t) | |
334 | |
335 ;;;###autoload | |
336 (defun font-lock-mode (&optional arg) | |
337 "Toggle Font Lock mode. | |
338 With arg, turn Font Lock mode on if and only if arg is positive. | |
339 | |
340 When Font Lock mode is enabled, text is fontified as you type it: | |
341 | |
342 - comments are displayed in `font-lock-comment-face'; | |
343 (That is a variable whose value should be a face name.) | |
344 - strings are displayed in `font-lock-string-face'; | |
345 - documentation strings are displayed in `font-lock-doc-string-face'; | |
346 - function and variable names in their defining forms are displayed | |
347 in `font-lock-function-name-face'; | |
348 - and certain other expressions are displayed in other faces | |
349 according to the value of the variable `font-lock-keywords'. | |
350 | |
351 When you turn Font Lock mode on/off, the buffer is fontified/defontified. | |
352 To fontify a buffer without having newly typed text become fontified, you | |
353 can use \\[font-lock-fontify-buffer]." | |
354 (interactive "P") | |
355 (let ((on-p (if (null arg) | |
356 (not font-lock-mode) | |
357 (> (prefix-numeric-value arg) 0)))) | |
358 (if (equal (buffer-name) " *Compiler Input*") ; hack for bytecomp... | |
359 (setq on-p nil)) | |
360 (or (memq after-change-function | |
361 '(nil font-lock-after-change-function)) | |
362 (error "after-change-function is %s" after-change-function)) | |
363 (set (make-local-variable 'after-change-function) | |
364 (if on-p 'font-lock-after-change-function nil)) | |
365 (set (make-local-variable 'font-lock-mode) on-p) | |
366 (cond (on-p | |
367 (font-lock-set-defaults) | |
5717
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
368 (make-local-variable 'before-revert-hook) |
5625
24f92f49a07f
(font-lock-mode): Set after-revert-hook
Richard M. Stallman <rms@gnu.org>
parents:
5360
diff
changeset
|
369 (make-local-variable 'after-revert-hook) |
5717
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
370 ;; If buffer is reverted, must clean up the state. |
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
371 (add-hook 'before-revert-hook 'font-lock-revert-setup) |
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
372 (add-hook 'after-revert-hook 'font-lock-revert-cleanup) |
4053 | 373 (run-hooks 'font-lock-mode-hook) |
374 (or font-lock-fontified (font-lock-fontify-buffer))) | |
375 (font-lock-fontified | |
376 (setq font-lock-fontified nil) | |
5717
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
377 (remove-hook 'before-revert-hook 'font-lock-revert-setup) |
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
378 (remove-hook 'after-revert-hook 'font-lock-revert-cleanup) |
4053 | 379 (font-lock-unfontify-region (point-min) (point-max)))) |
380 (force-mode-line-update))) | |
381 | |
5717
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
382 ;; If the buffer is about to be reverted, it won't be fontified. |
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
383 (defun font-lock-revert-setup () |
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
384 (setq font-lock-fontified nil)) |
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
385 |
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
386 ;; If the buffer has just been reverted, we might not even be in font-lock |
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
387 ;; mode anymore, and if we are, the buffer may or may not have already been |
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
388 ;; refontified. Refontify here if it looks like we need to. |
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
389 (defun font-lock-revert-cleanup () |
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
390 (and font-lock-mode |
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
391 (not font-lock-fontified) |
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
392 (font-lock-mode 1))) |
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
393 |
4053 | 394 (defun font-lock-fontify-buffer () |
395 "Fontify the current buffer the way `font-lock-mode' would: | |
396 | |
397 - comments are displayed in `font-lock-comment-face'; | |
398 - strings are displayed in `font-lock-string-face'; | |
399 - documentation strings are displayed in `font-lock-doc-string-face'; | |
400 - function and variable names in their defining forms are displayed | |
401 in `font-lock-function-name-face'; | |
402 - and certain other expressions are displayed in other faces | |
403 according to the value of the variable `font-lock-keywords'. | |
404 | |
405 This can take a while for large buffers." | |
406 (interactive) | |
407 (let ((was-on font-lock-mode) | |
408 (font-lock-verbose (or font-lock-verbose (interactive-p)))) | |
409 (if font-lock-verbose (message "Fontifying %s..." (buffer-name))) | |
410 ;; Turn it on to run hooks and get the right font-lock-keywords. | |
4897
c3db6fd69f1f
(font-lock-fontify-buffer): Don't turn
Richard M. Stallman <rms@gnu.org>
parents:
4727
diff
changeset
|
411 (or was-on (font-lock-set-defaults)) |
4053 | 412 (font-lock-unfontify-region (point-min) (point-max)) |
413 (if font-lock-verbose (message "Fontifying %s... (syntactically...)" | |
414 (buffer-name))) | |
415 ;; (buffer-syntactic-context-flush-cache) | |
416 (save-excursion | |
417 (font-lock-fontify-region (point-min) (point-max)) | |
418 (if font-lock-verbose (message "Fontifying %s... (regexps...)" | |
419 (buffer-name))) | |
420 (font-lock-hack-keywords (point-min) (point-max) font-lock-verbose)) | |
421 (set (make-local-variable 'font-lock-fontified) t) | |
422 (if font-lock-verbose (message "Fontifying %s... done." (buffer-name))) | |
423 )) | |
424 | |
425 | |
426 ;;; Various mode-specific information. | |
427 | |
428 (defun font-lock-set-defaults () | |
4727
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
429 "Set `font-lock-keywords' to something appropriate for this mode." |
5294
f5fdaf66b013
(font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents:
5056
diff
changeset
|
430 (if (not font-lock-keywords) ; if not already set. |
f5fdaf66b013
(font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents:
5056
diff
changeset
|
431 (setq font-lock-keywords |
f5fdaf66b013
(font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents:
5056
diff
changeset
|
432 (cond ((eq major-mode 'lisp-mode) lisp-font-lock-keywords) |
f5fdaf66b013
(font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents:
5056
diff
changeset
|
433 ((eq major-mode 'emacs-lisp-mode) lisp-font-lock-keywords) |
f5fdaf66b013
(font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents:
5056
diff
changeset
|
434 ((eq major-mode 'c-mode) c-font-lock-keywords) |
f5fdaf66b013
(font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents:
5056
diff
changeset
|
435 ((eq major-mode 'c++-c-mode) c-font-lock-keywords) |
f5fdaf66b013
(font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents:
5056
diff
changeset
|
436 ((eq major-mode 'c++-mode) c++-font-lock-keywords) |
f5fdaf66b013
(font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents:
5056
diff
changeset
|
437 ((eq major-mode 'perl-mode) perl-font-lock-keywords) |
f5fdaf66b013
(font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents:
5056
diff
changeset
|
438 ((eq major-mode 'tex-mode) tex-font-lock-keywords) |
f5fdaf66b013
(font-lock-set-defaults): Do nothing if font-lock-keywords is already set.
Richard M. Stallman <rms@gnu.org>
parents:
5056
diff
changeset
|
439 ((eq major-mode 'texinfo-mode) texi-font-lock-keywords) |
5726
781af712e68c
(font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents:
5717
diff
changeset
|
440 ((eq major-mode 'shell-mode) shell-font-lock-keywords) |
5752
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
441 ((eq major-mode 'dired-mode) dired-font-lock-keywords) |
5360
7e5fce72b793
(font-lock-set-defaults): Add missing paren.
Richard M. Stallman <rms@gnu.org>
parents:
5294
diff
changeset
|
442 (t nil))))) |
4053 | 443 |
444 (defconst lisp-font-lock-keywords-1 | |
445 '(;; | |
446 ;; highlight defining forms. This doesn't work too nicely for | |
447 ;; (defun (setf foo) ...) but it does work for (defvar foo) which | |
448 ;; is more important. | |
449 ("^(def[-a-z]+\\s +\\([^ \t\n\)]+\\)" 1 font-lock-function-name-face) | |
450 ;; | |
451 ;; highlight CL keywords | |
452 ("\\s :\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1) | |
453 ;; | |
454 ;; this is highlights things like (def* (setf foo) (bar baz)), but may | |
455 ;; be slower (I haven't really thought about it) | |
456 ; ("^(def[-a-z]+\\s +\\(\\s(\\S)*\\s)\\|\\S(\\S *\\)" | |
457 ; 1 font-lock-function-name-face) | |
458 ) | |
459 "For consideration as a value of `lisp-font-lock-keywords'. | |
460 This does fairly subdued highlighting.") | |
461 | |
462 (defconst lisp-font-lock-keywords-2 | |
463 (append | |
464 lisp-font-lock-keywords-1 | |
465 '(;; | |
466 ;; Highlight control structures | |
467 ("(\\(cond\\|if\\|when\\|unless\\|[ec]?\\(type\\)?case\\)[ \t\n]" . 1) | |
5878
044cb853edbd
(lisp-font-lock-keywords-2): Quote the * in let*.
Richard M. Stallman <rms@gnu.org>
parents:
5752
diff
changeset
|
468 ("(\\(while\\|do\\|let\\*?\\|flet\\|labels\\|prog[nv12*]?\\)[ \t\n]" . 1) |
4053 | 469 ("(\\(catch\\|\\throw\\|block\\|return\\|return-from\\)[ \t\n]" . 1) |
470 ("(\\(save-restriction\\|save-window-restriction\\)[ \t\n]" . 1) | |
471 ("(\\(save-excursion\\|unwind-protect\\|condition-case\\)[ \t\n]" . 1) | |
472 ;; | |
473 ;; highlight function names in emacs-lisp docstrings (in the syntax | |
474 ;; that substitute-command-keys understands.) | |
475 ("\\\\\\\\\\[\\([^]\\\n]+\\)]" 1 font-lock-keyword-face t) | |
476 ;; | |
477 ;; highlight words inside `' which tend to be function names | |
478 ("`\\([-a-zA-Z0-9_][-a-zA-Z0-9_][-a-zA-Z0-9_.]+\\)'" | |
479 1 font-lock-keyword-face t) | |
480 )) | |
481 "For consideration as a value of `lisp-font-lock-keywords'. | |
482 This does a lot more highlighting.") | |
483 | |
484 ;; default to the gaudier variety? | |
485 ;(defvar lisp-font-lock-keywords lisp-font-lock-keywords-2 | |
486 ; "Additional expressions to highlight in Lisp modes.") | |
487 (defvar lisp-font-lock-keywords lisp-font-lock-keywords-1 | |
488 "Additional expressions to highlight in Lisp modes.") | |
489 | |
490 | |
491 (defconst c-font-lock-keywords-1 nil | |
492 "For consideration as a value of `c-font-lock-keywords'. | |
493 This does fairly subdued highlighting.") | |
494 | |
495 (defconst c-font-lock-keywords-2 nil | |
496 "For consideration as a value of `c-font-lock-keywords'. | |
497 This does a lot more highlighting.") | |
498 | |
6093
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
499 (let* ((storage "auto\\|extern\\|register\\|static\\|typedef") |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
500 (struct "struct\\|union\\|enum") |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
501 (prefixes "signed\\|unsigned\\|short\\|long") |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
502 (types (concat prefixes "\\|int\\|char\\|float\\|double\\|void")) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
503 (ctoken "[a-zA-Z0-9_:~*]+")) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
504 (setq c-font-lock-keywords-1 |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
505 (list |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
506 ;; fontify preprocessor directives as comments. |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
507 '("^#[ \t]*[a-z]+" . font-lock-comment-face) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
508 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
509 ;; fontify names being defined. |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
510 '("^#[ \t]*\\(define\\|undef\\)[ \t]+\\(\\(\\sw\\|\\s_\\)+\\)" 2 |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
511 font-lock-function-name-face) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
512 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
513 ;; fontify other preprocessor lines. |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
514 '("^#[ \t]*\\(if\\|elif\\|else\\|endif\\)[ \t]+\\([^\n]+\\)" |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
515 2 font-lock-function-name-face keep) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
516 '("^#[ \t]*\\(ifn?def\\)[ \t]+\\([^ \t\n]+\\)" |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
517 2 font-lock-function-name-face t) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
518 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
519 ;; fontify the filename in #include <...> |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
520 ;; don't need to do this for #include "..." because those were |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
521 ;; already fontified as strings by the syntactic pass. |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
522 '("^#[ \t]*include[ \t]+\\(<[^>\"\n]+>\\)" 1 font-lock-string-face) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
523 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
524 ;; fontify the names of functions being defined. |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
525 (list (concat |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
526 "^\\(" ctoken "[ \t]+\\)?" ; type specs; there can be no |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
527 "\\(" ctoken "[ \t]+\\)?" ; more than 3 tokens, right? |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
528 "\\(" ctoken "[ \t]+\\)?" |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
529 "\\([*&]+[ \t]*\\)?" ; pointer |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
530 "\\(" ctoken "\\)[ \t]*(") ; name |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
531 5 'font-lock-function-name-face) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
532 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
533 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
534 ;; Fontify structure names (in structure definition form). |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
535 (list (concat "^\\(" storage "\\)?[ \t]*\\<\\(" struct "\\)" |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
536 "[ \t]+\\(" ctoken "\\)[ \t]*\\(\{\\|$\\)") |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
537 3 'font-lock-function-name-face) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
538 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
539 ;; Fontify declarations of simple identifiers (including typedefs). |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
540 ;; (Should this be in c-font-lock-keywords-2 instead?) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
541 (list (concat "^[ \t]*\\(\\(" storage "\\)[ \t]+\\)?\\(\\(\\(" prefixes |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
542 "\\)\\>[ \t]*\\)*\\(" types "\\)\\)[ \t]+\\(" ctoken |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
543 "\\)[ \t]*[=;]") |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
544 7 'font-lock-function-name-face 'keep) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
545 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
546 ;; And likewise for structs |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
547 (list (concat "^[ \t]*\\(\\(" storage "\\)[ \t]+\\)?\\(" struct |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
548 "\\)[ \t]+" ctoken "[ \t]+\\(" ctoken "\\);") |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
549 4 'font-lock-function-name-face 'keep) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
550 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
551 ;; Fontify case clauses. This is fast because its anchored on the left. |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
552 '("case[ \t]+\\(\\(\\sw\\|\\s_\\)+\\):". 1) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
553 '("\\<\\(default\\):". 1) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
554 )) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
555 |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
556 (setq c-font-lock-keywords-2 |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
557 (append c-font-lock-keywords-1 |
4053 | 558 (list |
559 ;; | |
6093
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
560 ;; fontify all storage classes and type specifiers |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
561 (cons (concat "\\<\\(" storage "\\)\\>") 'font-lock-type-face) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
562 (cons (concat "\\<\\(\\(\\(" prefixes "\\)\\>[ \t]*\\)*\\(" types |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
563 "\\)\\)\\>") |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
564 'font-lock-type-face) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
565 (list (concat "\\<\\(" struct "\\)[ \t]+" ctoken) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
566 0 'font-lock-type-face 'keep) |
4053 | 567 ;; |
6093
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
568 ;; fontify all builtin tokens |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
569 (cons (concat |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
570 "[ \t]\\(" |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
571 (mapconcat 'identity |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
572 '("for" "while" "do" "return" "goto" "case" "break" "switch" |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
573 "if" "else" "default" "continue" "default") |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
574 "\\|") |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
575 "\\)[ \t\n(){};,]") |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
576 1) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
577 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
578 ;; fontify case targets and goto-tags. This is slow because the |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
579 ;; expression is anchored on the right. |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
580 "\\(\\(\\sw\\|\\s_\\)+\\):" |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
581 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
582 ;; Fontify variables declared with structures, or typedef names. |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
583 '("}[ \t*]*\\(\\(\\sw\\|\\s_\\)+\\)[ \t]*[,;]" |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
584 1 font-lock-function-name-face) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
585 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
586 ;; Fontify global variables without a type. |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
587 ; '("^\\([_a-zA-Z0-9:~*]+\\)[ \t]*[[;={]" 1 font-lock-function-name-face) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
588 ))) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
589 ) |
4053 | 590 |
591 ; default to the gaudier variety? | |
592 ;(defvar c-font-lock-keywords c-font-lock-keywords-2 | |
593 ; "Additional expressions to highlight in C mode.") | |
594 (defvar c-font-lock-keywords c-font-lock-keywords-1 | |
595 "Additional expressions to highlight in C mode.") | |
596 | |
597 (defvar c++-font-lock-keywords c-font-lock-keywords | |
598 "Additional expressions to highlight in C++ mode.") | |
599 | |
600 | |
601 (defvar perl-font-lock-keywords | |
602 (list | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
603 (cons (concat "[ \n\t{]*\\(" |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
604 (mapconcat 'identity |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
605 '("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
|
606 "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
|
607 "redo" "return" "local" "exec") |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
608 "\\|") |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
609 "\\)[ \n\t;(]") 1) |
4053 | 610 (mapconcat 'identity |
611 '("#endif" "#else" "#ifdef" "#ifndef" "#if" "#include" | |
612 "#define" "#undef") | |
613 "\\|") | |
4239
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
614 '("^[ \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
|
615 '("[ \n\t{]*\\(eval\\)[ \n\t(;]" 1 font-lock-function-name-face) |
4053 | 616 '("\\(--- .* ---\\|=== .* ===\\)" . font-lock-doc-string-face) |
617 ) | |
618 "Additional expressions to highlight in Perl mode.") | |
619 | |
620 (defvar tex-font-lock-keywords | |
621 (list | |
622 '("\\(\\\\\\w+\\)" 1 font-lock-keyword-face t) | |
623 '("{\\\\em\\([^}]+\\)}" 1 font-lock-comment-face t) | |
624 '("{\\\\bf\\([^}]+\\)}" 1 font-lock-keyword-face t) | |
625 '("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face t) | |
626 '("\\\\\\(begin\\|end\\){\\([a-zA-Z0-9\\*]+\\)}" | |
627 2 font-lock-function-name-face t) | |
628 '("[^\\\\]\\$\\([^$]*\\)\\$" 1 font-lock-string-face t) | |
629 ; '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t) | |
630 ) | |
631 "Additional expressions to highlight in TeX mode.") | |
632 | |
633 (defvar texi-font-lock-keywords | |
634 (list | |
635 "@\\(@\\|[^}\t \n{]+\\)" ;commands | |
636 '("^\\(@c\\|@comment\\)[ \t].*$" . font-lock-comment-face) ;comments | |
637 '("^\\(*.*\\)[\t ]*$" 1 font-lock-function-name-face t) ;menu items | |
638 '("@\\(emph\\|strong\\|b\\|i\\){\\([^}]+\\)" 2 font-lock-comment-face t) | |
639 '("@\\(file\\|kbd\\|key\\){\\([^}]+\\)" 2 font-lock-string-face t) | |
640 '("@\\(samp\\|code\\|var\\){\\([^}]+\\)" 2 font-lock-function-name-face t) | |
641 '("@\\(xref\\|pxref\\){\\([^}]+\\)" 2 font-lock-keyword-face t) | |
642 '("@end *\\([a-zA-Z0-9]+\\)[ \t]*$" 1 font-lock-function-name-face t) | |
643 '("@item \\(.*\\)$" 1 font-lock-function-name-face t) | |
644 '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t) | |
645 ) | |
646 "Additional expressions to highlight in TeXinfo mode.") | |
647 | |
5726
781af712e68c
(font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents:
5717
diff
changeset
|
648 (defvar shell-font-lock-keywords |
781af712e68c
(font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents:
5717
diff
changeset
|
649 (list (cons shell-prompt-pattern 'font-lock-keyword-face) |
781af712e68c
(font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents:
5717
diff
changeset
|
650 (list (concat shell-prompt-pattern "\\([^ \t]+\\)") |
781af712e68c
(font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents:
5717
diff
changeset
|
651 1 'font-lock-function-name-face) |
781af712e68c
(font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents:
5717
diff
changeset
|
652 '("[ \t]\\([+-][^ \t\n]+\\)" 1 font-lock-comment-face) |
781af712e68c
(font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents:
5717
diff
changeset
|
653 '("^[^ \t]+:.*$" . font-lock-string-face) |
781af712e68c
(font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents:
5717
diff
changeset
|
654 '("^\\[[1-9][0-9]*\\]" . font-lock-string-face)) |
5744
c870cde64544
(shell-font-lock-keywords): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
5726
diff
changeset
|
655 "Additional expressions to highlight in Shell mode.") |
5726
781af712e68c
(font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents:
5717
diff
changeset
|
656 |
5752
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
657 (defvar dired-font-lock-keywords |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
658 '(;; Put directory headers in italics. |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
659 ("^ \\(/.+\\)$" 1 font-lock-type-face) |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
660 ;; Put symlinks in bold italics. |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
661 ("\\([^ ]+\\) -> [^ ]+$" . font-lock-function-name-face) |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
662 ;; Put marks in bold. |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
663 ("^\\([^ ]\\).*$" 1 font-lock-keyword-face t) |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
664 ;; Put files that are subdirectories in bold. |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
665 ("^..d.* \\([^ ]+\\)$" 1 font-lock-keyword-face)) |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
666 "Additional expressions to highlight in Dired mode.") |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
667 |
4053 | 668 (provide 'font-lock) |
669 | |
670 ;;; font-lock.el ends here |