Mercurial > emacs
annotate lisp/font-lock.el @ 8313:589abdc989e1
(add-log-current-defun): Skip doc string
correctly even if it ends with line that starts space.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 24 Jul 1994 02:50:50 +0000 |
parents | 970912d4f413 |
children | c0492d7043b2 |
rev | line source |
---|---|
4053 | 1 ;; Electric Font Lock Mode |
7298 | 2 ;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc. |
4053 | 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 | |
6578
de72ddd5a3c0
Check for existence of windowing system.
Karl Heuer <kwzh@gnu.org>
parents:
6219
diff
changeset
|
57 (or window-system |
de72ddd5a3c0
Check for existence of windowing system.
Karl Heuer <kwzh@gnu.org>
parents:
6219
diff
changeset
|
58 (error "Can't fontify on an ASCII terminal")) |
de72ddd5a3c0
Check for existence of windowing system.
Karl Heuer <kwzh@gnu.org>
parents:
6219
diff
changeset
|
59 |
4053 | 60 (defvar font-lock-comment-face |
61 'italic | |
62 "Face to use for comments.") | |
63 | |
64 (defvar font-lock-doc-string-face | |
65 'italic | |
66 "Face to use for documentation strings.") | |
67 | |
68 (defvar font-lock-string-face | |
69 'underline | |
70 "Face to use for string constants.") | |
71 | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
72 (defvar font-lock-function-name-face |
4053 | 73 'bold-italic |
74 "Face to use for function names.") | |
75 | |
76 (defvar font-lock-keyword-face | |
77 'bold | |
78 "Face to use for keywords.") | |
79 | |
80 (defvar font-lock-type-face | |
81 'italic | |
82 "Face to use for data types.") | |
83 | |
7491
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
84 (defvar font-lock-no-comments nil |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
85 "Non-nil means Font-Lock shouldn't check for comments or strings.") |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
86 |
4053 | 87 (make-variable-buffer-local 'font-lock-keywords) |
88 (defvar font-lock-keywords nil | |
89 "*The keywords to highlight. | |
90 If this is a list, then elements may be of the forms: | |
91 | |
4727
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
92 \"string\" ; A regexp to highlight in the |
4053 | 93 ; `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
|
94 (\"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
|
95 (\"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
|
96 (\"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
|
97 (\"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
|
98 ; already-highlighted regions. |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
99 (\"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
|
100 ; 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
|
101 ; 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
|
102 ; the existing highlighting of those parts. |
4053 | 103 |
104 These regular expressions should not match text which spans lines. | |
105 While \\[font-lock-fontify-buffer] handles multi-line patterns correctly, | |
106 updating when you edit the buffer does not, | |
107 since it considers text one line at a time. | |
108 | |
109 Be careful composing regexps for this list; the wrong pattern can dramatically | |
110 slow things down!") | |
111 | |
112 (defvar font-lock-keywords-case-fold-search nil | |
113 "*Non-nil means the patterns in `font-lock-keywords' are case-insensitive.") | |
114 | |
115 (defvar font-lock-verbose t | |
116 "*Non-nil means `font-lock-fontify-buffer' should print status messages.") | |
117 | |
4054 | 118 ;;;###autoload |
4053 | 119 (defvar font-lock-mode-hook nil |
120 "Function or functions to run on entry to Font Lock mode.") | |
121 | |
122 ;;; These variables record, for each buffer, | |
123 ;;; the parse state at a particular position, always the start of a line. | |
124 ;;; This is used to make font-lock-fontify-region faster. | |
125 (defvar font-lock-cache-position nil) | |
126 (defvar font-lock-cache-state nil) | |
127 (make-variable-buffer-local 'font-lock-cache-position) | |
128 (make-variable-buffer-local 'font-lock-cache-state) | |
129 | |
130 (defun font-lock-fontify-region (start end) | |
131 "Put proper face on each string and comment between START and END." | |
132 (save-excursion | |
133 (goto-char start) | |
134 (beginning-of-line) | |
135 (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
|
136 (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
|
137 state startline prev prevstate |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
138 (modified (buffer-modified-p))) |
4053 | 139 ;; Find the state at the line-beginning before START. |
140 (setq startline (point)) | |
141 (if (eq (point) font-lock-cache-position) | |
142 (setq state font-lock-cache-state) | |
143 ;; Find outermost containing sexp. | |
144 (beginning-of-defun) | |
145 ;; Find the state at STARTLINE. | |
146 (while (< (point) startline) | |
147 (setq state (parse-partial-sexp (point) startline 0))) | |
148 (setq font-lock-cache-state state | |
149 font-lock-cache-position (point))) | |
150 ;; Now find the state precisely at START. | |
151 (setq state (parse-partial-sexp (point) start nil nil state)) | |
152 ;; If the region starts inside a string, show the extent of it. | |
153 (if (nth 3 state) | |
154 (let ((beg (point))) | |
155 (while (and (re-search-forward "\\s\"" end 'move) | |
156 (nth 3 (parse-partial-sexp beg (point) | |
157 nil nil state)))) | |
158 (put-text-property beg (point) 'face font-lock-string-face) | |
159 (setq state (parse-partial-sexp beg (point) nil nil state)))) | |
160 ;; Likewise for a comment. | |
161 (if (or (nth 4 state) (nth 7 state)) | |
162 (let ((beg (point))) | |
163 (while (and (re-search-forward (if comment-end | |
164 (concat "\\s>\\|" | |
165 (regexp-quote comment-end)) | |
166 "\\s>") | |
167 end 'move) | |
168 (nth 3 (parse-partial-sexp beg (point) | |
169 nil nil state)))) | |
170 (put-text-property beg (point) 'face font-lock-comment-face) | |
171 (setq state (parse-partial-sexp beg (point) nil nil state)))) | |
172 ;; Find each interesting place between here and END. | |
173 (while (and (< (point) end) | |
174 (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
|
175 (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
|
176 (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
|
177 "\\s\"") |
2d8f7239f2ca
(font-lock-fontify-region): Handle comment-start-skip = nil.
Richard M. Stallman <rms@gnu.org>
parents:
4239
diff
changeset
|
178 end t) |
4053 | 179 ;; Clear out the fonts of what we skip over. |
180 (progn (remove-text-properties prev (point) '(face nil)) t) | |
181 ;; Verify the state at that place | |
182 ;; so we don't get fooled by \" or \;. | |
183 (setq state (parse-partial-sexp prev (point) | |
184 nil nil state))) | |
185 (let ((here (point))) | |
186 (if (or (nth 4 state) (nth 7 state)) | |
187 ;; We found a real comment start. | |
188 (let ((beg (match-beginning 0))) | |
189 (goto-char beg) | |
190 (save-restriction | |
191 (narrow-to-region (point-min) end) | |
192 (condition-case nil | |
193 (progn | |
194 (forward-comment 1) | |
195 ;; forward-comment skips all whitespace, | |
196 ;; so go back to the real end of the comment. | |
197 (skip-chars-backward " \t")) | |
198 (error (goto-char end)))) | |
199 (put-text-property beg (point) 'face font-lock-comment-face) | |
200 (setq state (parse-partial-sexp here (point) nil nil state))) | |
201 (if (nth 3 state) | |
202 (let ((beg (match-beginning 0))) | |
203 (while (and (re-search-forward "\\s\"" end 'move) | |
204 (nth 3 (parse-partial-sexp here (point) | |
205 nil nil state)))) | |
206 (put-text-property beg (point) 'face font-lock-string-face) | |
207 (setq state (parse-partial-sexp here (point) nil nil state)))) | |
208 )) | |
209 ;; Make sure PREV is non-nil after the loop | |
210 ;; only if it was set on the very last iteration. | |
211 (setq prev nil)) | |
212 (and prev | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
213 (remove-text-properties prev end '(face nil))) |
7915
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
214 (and (buffer-modified-p) |
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
215 (not modified) |
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
216 (set-buffer-modified-p nil))))) |
4053 | 217 |
218 ;; This code used to be used to show a string on reaching the end of it. | |
219 ;; It is probably not needed due to later changes to handle strings | |
220 ;; starting before the region in question. | |
221 ;; (if (and (null (nth 3 state)) | |
222 ;; (eq (char-syntax (preceding-char)) ?\") | |
223 ;; (save-excursion | |
224 ;; (nth 3 (parse-partial-sexp prev (1- (point)) | |
225 ;; nil nil prevstate)))) | |
226 ;; ;; We found the end of a string. | |
227 ;; (save-excursion | |
228 ;; (setq foo2 (point)) | |
229 ;; (let ((ept (point))) | |
230 ;; (forward-sexp -1) | |
231 ;; ;; Highlight the string when we see the end. | |
232 ;; ;; Doing it at the start leads to trouble: | |
233 ;; ;; either it fails to handle multiline strings | |
234 ;; ;; or it can run away when an unmatched " is inserted. | |
235 ;; (put-text-property (point) ept 'face | |
236 ;; (if (= (car state) 1) | |
237 ;; font-lock-doc-string-face | |
238 ;; font-lock-string-face))))) | |
239 | |
240 (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
|
241 (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
|
242 (buffer-read-only nil)) |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
243 (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
|
244 (set-buffer-modified-p modified))) |
4053 | 245 |
246 ;; Called when any modification is made to buffer text. | |
247 (defun font-lock-after-change-function (beg end old-len) | |
248 (save-excursion | |
249 (save-match-data | |
250 (goto-char beg) | |
251 ;; Discard the cache info if text before it has changed. | |
252 (and font-lock-cache-position | |
253 (> font-lock-cache-position beg) | |
254 (setq font-lock-cache-position nil)) | |
255 ;; Rescan till end of line. yes! | |
256 (goto-char end) | |
257 (end-of-line) | |
258 (setq end (point)) | |
259 (goto-char beg) | |
260 (beginning-of-line) | |
261 (setq beg (point)) | |
4239
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
262 ;; First scan for strings and comments. |
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
263 ;; Must scan from line start in case of |
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
264 ;; inserting space into `intfoo () {}'. |
7491
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
265 (if font-lock-no-comments |
7546
b05a6824c512
(font-lock-after-change-function): Fix typo in prev chg.
Richard M. Stallman <rms@gnu.org>
parents:
7491
diff
changeset
|
266 (remove-text-properties beg (min (1+ end) (point-max)) '(face nil)) |
7491
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
267 (font-lock-fontify-region beg (min (1+ end) (point-max)))) |
4053 | 268 ;; Now scan for keywords. |
269 (font-lock-hack-keywords beg end)))) | |
270 | |
271 ;;; Fontifying arbitrary patterns | |
272 | |
273 (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
|
274 (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
|
275 (let ((next (next-single-property-change start 'face))) |
4053 | 276 (and next (< next end))))) |
277 | |
278 (defun font-lock-hack-keywords (start end &optional loudly) | |
279 (goto-char start) | |
280 (let ((case-fold-search font-lock-keywords-case-fold-search) | |
281 (rest font-lock-keywords) | |
282 (count 0) | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
283 (buffer-read-only nil) |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
284 (modified (buffer-modified-p)) |
4053 | 285 first str match face s e allow-overlap-p) |
286 (while rest | |
287 (setq first (car rest) rest (cdr rest)) | |
288 (goto-char start) | |
289 (cond ((consp first) | |
290 (setq str (car first)) | |
291 (cond ((consp (cdr first)) | |
292 (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
|
293 face (eval (nth 2 first)) |
4053 | 294 allow-overlap-p (nth 3 first))) |
295 ((symbolp (cdr first)) | |
296 (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
|
297 face (eval (cdr first)))) |
4053 | 298 (t |
299 (setq match (cdr first) | |
300 allow-overlap-p nil | |
301 face font-lock-keyword-face)))) | |
302 (t | |
303 (setq str first match 0 allow-overlap-p nil | |
304 face font-lock-keyword-face))) | |
305 ;(message "regexp: %s" str) | |
306 (while (re-search-forward str end t) | |
307 (setq s (match-beginning match) | |
308 e (match-end match)) | |
309 (or s (error "expression did not match subexpression %d" match)) | |
310 ;; don't fontify this keyword if we're already in some other context. | |
311 (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
|
312 (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
|
313 (save-excursion |
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
314 (goto-char s) |
7915
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
315 (while (< (point) e) |
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
316 (let ((next (next-single-property-change (point) 'face |
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
317 nil e))) |
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
318 (if (or (null next) (> next e)) |
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
319 (setq next e)) |
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
320 (if (not (get-text-property (point) 'face)) |
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
321 (put-text-property (point) next 'face face)) |
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
322 (goto-char next)))) |
4727
ca337641008d
(font-lock-fontify-region): Don't add `font-lock' props.
Richard M. Stallman <rms@gnu.org>
parents:
4700
diff
changeset
|
323 (put-text-property s e 'face face)))) |
4053 | 324 (if loudly (message "Fontifying %s... (regexps...%s)" |
325 (buffer-name) | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
326 (make-string (setq count (1+ count)) ?.)))) |
7915
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
327 (and (buffer-modified-p) |
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
328 (not modified) |
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
329 (set-buffer-modified-p nil)))) |
4053 | 330 |
331 ;; The user level functions | |
332 | |
333 (defvar font-lock-mode nil) ; for modeline | |
334 (or (assq 'font-lock-mode minor-mode-alist) | |
335 (setq minor-mode-alist | |
336 (append minor-mode-alist | |
337 '((font-lock-mode " Font"))))) | |
338 | |
339 (defvar font-lock-fontified nil) ; whether we have hacked this buffer | |
340 (put 'font-lock-fontified 'permanent-local t) | |
341 | |
342 ;;;###autoload | |
343 (defun font-lock-mode (&optional arg) | |
344 "Toggle Font Lock mode. | |
345 With arg, turn Font Lock mode on if and only if arg is positive. | |
346 | |
347 When Font Lock mode is enabled, text is fontified as you type it: | |
348 | |
349 - comments are displayed in `font-lock-comment-face'; | |
350 (That is a variable whose value should be a face name.) | |
351 - strings are displayed in `font-lock-string-face'; | |
352 - documentation strings are displayed in `font-lock-doc-string-face'; | |
353 - function and variable names in their defining forms are displayed | |
354 in `font-lock-function-name-face'; | |
355 - and certain other expressions are displayed in other faces | |
356 according to the value of the variable `font-lock-keywords'. | |
357 | |
358 When you turn Font Lock mode on/off, the buffer is fontified/defontified. | |
359 To fontify a buffer without having newly typed text become fontified, you | |
360 can use \\[font-lock-fontify-buffer]." | |
361 (interactive "P") | |
362 (let ((on-p (if (null arg) | |
363 (not font-lock-mode) | |
364 (> (prefix-numeric-value arg) 0)))) | |
365 (if (equal (buffer-name) " *Compiler Input*") ; hack for bytecomp... | |
366 (setq on-p nil)) | |
7546
b05a6824c512
(font-lock-after-change-function): Fix typo in prev chg.
Richard M. Stallman <rms@gnu.org>
parents:
7491
diff
changeset
|
367 (make-local-variable 'after-change-functions) |
b05a6824c512
(font-lock-after-change-function): Fix typo in prev chg.
Richard M. Stallman <rms@gnu.org>
parents:
7491
diff
changeset
|
368 (if on-p |
b05a6824c512
(font-lock-after-change-function): Fix typo in prev chg.
Richard M. Stallman <rms@gnu.org>
parents:
7491
diff
changeset
|
369 (or (memq 'font-lock-after-change-function after-change-functions) |
b05a6824c512
(font-lock-after-change-function): Fix typo in prev chg.
Richard M. Stallman <rms@gnu.org>
parents:
7491
diff
changeset
|
370 (setq after-change-functions (cons 'font-lock-after-change-function |
b05a6824c512
(font-lock-after-change-function): Fix typo in prev chg.
Richard M. Stallman <rms@gnu.org>
parents:
7491
diff
changeset
|
371 after-change-functions))) |
b05a6824c512
(font-lock-after-change-function): Fix typo in prev chg.
Richard M. Stallman <rms@gnu.org>
parents:
7491
diff
changeset
|
372 (setq after-change-functions |
b05a6824c512
(font-lock-after-change-function): Fix typo in prev chg.
Richard M. Stallman <rms@gnu.org>
parents:
7491
diff
changeset
|
373 (delq 'font-lock-after-change-function |
b05a6824c512
(font-lock-after-change-function): Fix typo in prev chg.
Richard M. Stallman <rms@gnu.org>
parents:
7491
diff
changeset
|
374 (copy-sequence after-change-functions)))) |
4053 | 375 (set (make-local-variable 'font-lock-mode) on-p) |
7491
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
376 (make-local-variable 'font-lock-no-comments) |
4053 | 377 (cond (on-p |
378 (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
|
379 (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
|
380 (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
|
381 ;; 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
|
382 (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
|
383 (add-hook 'after-revert-hook 'font-lock-revert-cleanup) |
4053 | 384 (run-hooks 'font-lock-mode-hook) |
385 (or font-lock-fontified (font-lock-fontify-buffer))) | |
386 (font-lock-fontified | |
387 (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
|
388 (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
|
389 (remove-hook 'after-revert-hook 'font-lock-revert-cleanup) |
4053 | 390 (font-lock-unfontify-region (point-min) (point-max)))) |
391 (force-mode-line-update))) | |
392 | |
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
|
393 ;; 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
|
394 (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
|
395 (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
|
396 |
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
397 ;; 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
|
398 ;; 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
|
399 ;; 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
|
400 (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
|
401 (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
|
402 (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
|
403 (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
|
404 |
4053 | 405 (defun font-lock-fontify-buffer () |
406 "Fontify the current buffer the way `font-lock-mode' would: | |
407 | |
408 - comments are displayed in `font-lock-comment-face'; | |
409 - strings are displayed in `font-lock-string-face'; | |
410 - documentation strings are displayed in `font-lock-doc-string-face'; | |
411 - function and variable names in their defining forms are displayed | |
412 in `font-lock-function-name-face'; | |
413 - and certain other expressions are displayed in other faces | |
414 according to the value of the variable `font-lock-keywords'. | |
415 | |
416 This can take a while for large buffers." | |
417 (interactive) | |
418 (let ((was-on font-lock-mode) | |
419 (font-lock-verbose (or font-lock-verbose (interactive-p)))) | |
420 (if font-lock-verbose (message "Fontifying %s..." (buffer-name))) | |
421 ;; 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
|
422 (or was-on (font-lock-set-defaults)) |
4053 | 423 (font-lock-unfontify-region (point-min) (point-max)) |
7491
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
424 (if (and font-lock-verbose (not font-lock-no-comments)) |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
425 (message "Fontifying %s... (syntactically...)" (buffer-name))) |
4053 | 426 (save-excursion |
7491
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
427 (or font-lock-no-comments |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
428 (font-lock-fontify-region (point-min) (point-max))) |
4053 | 429 (if font-lock-verbose (message "Fontifying %s... (regexps...)" |
430 (buffer-name))) | |
431 (font-lock-hack-keywords (point-min) (point-max) font-lock-verbose)) | |
432 (set (make-local-variable 'font-lock-fontified) t) | |
433 (if font-lock-verbose (message "Fontifying %s... done." (buffer-name))) | |
434 )) | |
435 | |
436 | |
437 ;;; Various mode-specific information. | |
438 | |
439 (defconst lisp-font-lock-keywords-1 | |
440 '(;; | |
441 ;; highlight defining forms. This doesn't work too nicely for | |
442 ;; (defun (setf foo) ...) but it does work for (defvar foo) which | |
443 ;; is more important. | |
444 ("^(def[-a-z]+\\s +\\([^ \t\n\)]+\\)" 1 font-lock-function-name-face) | |
445 ;; | |
446 ;; highlight CL keywords | |
447 ("\\s :\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1) | |
448 ;; | |
449 ;; this is highlights things like (def* (setf foo) (bar baz)), but may | |
450 ;; be slower (I haven't really thought about it) | |
451 ; ("^(def[-a-z]+\\s +\\(\\s(\\S)*\\s)\\|\\S(\\S *\\)" | |
452 ; 1 font-lock-function-name-face) | |
453 ) | |
454 "For consideration as a value of `lisp-font-lock-keywords'. | |
455 This does fairly subdued highlighting.") | |
456 | |
457 (defconst lisp-font-lock-keywords-2 | |
458 (append | |
459 lisp-font-lock-keywords-1 | |
460 '(;; | |
461 ;; Highlight control structures | |
462 ("(\\(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
|
463 ("(\\(while\\|do\\|let\\*?\\|flet\\|labels\\|prog[nv12*]?\\)[ \t\n]" . 1) |
4053 | 464 ("(\\(catch\\|\\throw\\|block\\|return\\|return-from\\)[ \t\n]" . 1) |
465 ("(\\(save-restriction\\|save-window-restriction\\)[ \t\n]" . 1) | |
466 ("(\\(save-excursion\\|unwind-protect\\|condition-case\\)[ \t\n]" . 1) | |
467 ;; | |
468 ;; highlight function names in emacs-lisp docstrings (in the syntax | |
469 ;; that substitute-command-keys understands.) | |
470 ("\\\\\\\\\\[\\([^]\\\n]+\\)]" 1 font-lock-keyword-face t) | |
471 ;; | |
472 ;; highlight words inside `' which tend to be function names | |
473 ("`\\([-a-zA-Z0-9_][-a-zA-Z0-9_][-a-zA-Z0-9_.]+\\)'" | |
474 1 font-lock-keyword-face t) | |
475 )) | |
476 "For consideration as a value of `lisp-font-lock-keywords'. | |
477 This does a lot more highlighting.") | |
478 | |
479 ;; default to the gaudier variety? | |
480 ;(defvar lisp-font-lock-keywords lisp-font-lock-keywords-2 | |
481 ; "Additional expressions to highlight in Lisp modes.") | |
482 (defvar lisp-font-lock-keywords lisp-font-lock-keywords-1 | |
483 "Additional expressions to highlight in Lisp modes.") | |
484 | |
485 | |
486 (defconst c-font-lock-keywords-1 nil | |
487 "For consideration as a value of `c-font-lock-keywords'. | |
488 This does fairly subdued highlighting.") | |
489 | |
490 (defconst c-font-lock-keywords-2 nil | |
491 "For consideration as a value of `c-font-lock-keywords'. | |
492 This does a lot more highlighting.") | |
493 | |
6219
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
494 (defconst c++-font-lock-keywords-1 nil |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
495 "For consideration as a value of `c++-font-lock-keywords'. |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
496 This does fairly subdued highlighting.") |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
497 |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
498 (defconst c++-font-lock-keywords-2 nil |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
499 "For consideration as a value of `c++-font-lock-keywords'. |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
500 This does a lot more highlighting.") |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
501 |
6093
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
502 (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
|
503 (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
|
504 (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
|
505 (types (concat prefixes "\\|int\\|char\\|float\\|double\\|void")) |
6219
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
506 (ctoken "[a-zA-Z0-9_:~*]+") |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
507 (c++-things (concat |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
508 "const\\|class\\|protected:\\|private:\\|public:\\|inline\\|" |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
509 "new\\|delete"))) |
6093
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
510 (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
|
511 (list |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
512 ;; 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
|
513 '("^#[ \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
|
514 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
515 ;; 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
|
516 '("^#[ \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
|
517 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
|
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 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
|
520 '("^#[ \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
|
521 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
|
522 '("^#[ \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
|
523 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
|
524 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
525 ;; 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
|
526 ;; 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
|
527 ;; 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
|
528 '("^#[ \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
|
529 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
530 ;; 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
|
531 (list (concat |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
532 "^\\(" 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
|
533 "\\(" 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
|
534 "\\(" ctoken "[ \t]+\\)?" |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
535 "\\([*&]+[ \t]*\\)?" ; pointer |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
536 "\\(" 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
|
537 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
|
538 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
539 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
540 ;; 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
|
541 (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
|
542 "[ \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
|
543 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
|
544 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
545 ;; 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
|
546 ;; (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
|
547 (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
|
548 "\\)\\>[ \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
|
549 "\\)[ \t]*[=;]") |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
550 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
|
551 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
552 ;; 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
|
553 (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
|
554 "\\)[ \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
|
555 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
|
556 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
557 ;; 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
|
558 '("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
|
559 '("\\<\\(default\\):". 1) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
560 )) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
561 |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
562 (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
|
563 (append c-font-lock-keywords-1 |
4053 | 564 (list |
565 ;; | |
6093
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
566 ;; 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
|
567 (cons (concat "\\<\\(" storage "\\)\\>") 'font-lock-type-face) |
6219
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
568 (cons (concat "\\<\\(" types "\\)\\>") 'font-lock-type-face) |
6093
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 "\\<\\(\\(\\(" 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
|
570 "\\)\\)\\>") |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
571 '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
|
572 (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
|
573 0 'font-lock-type-face 'keep) |
4053 | 574 ;; |
6093
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
575 ;; 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
|
576 (cons (concat |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
577 "[ \t]\\(" |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
578 (mapconcat 'identity |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
579 '("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
|
580 "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
|
581 "\\|") |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
582 "\\)[ \t\n(){};,]") |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
583 1) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
584 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
585 ;; 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
|
586 ;; expression is anchored on the right. |
7915
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
587 '("[ \t\n]\\(\\(\\sw\\|\\s_\\)+\\):" . 1) |
6093
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 ;; 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
|
590 '("}[ \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
|
591 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
|
592 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
593 ;; 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
|
594 ; '("^\\([_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
|
595 ))) |
6219
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
596 |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
597 (setq c++-font-lock-keywords-1 |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
598 (cons |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
599 (concat "\\(" c++-things "\\)[ \t\n]") |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
600 c-font-lock-keywords-1)) |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
601 (setq c++-font-lock-keywords-2 |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
602 (cons |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
603 (cons (concat "\\<\\(" c++-things "\\)\\>") 'font-lock-type-face) |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
604 c-font-lock-keywords-2)) |
6093
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
605 ) |
4053 | 606 |
607 ; default to the gaudier variety? | |
608 (defvar c-font-lock-keywords c-font-lock-keywords-1 | |
609 "Additional expressions to highlight in C mode.") | |
610 | |
6219
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
611 (defvar c++-font-lock-keywords c++-font-lock-keywords-1 |
4053 | 612 "Additional expressions to highlight in C++ mode.") |
613 | |
614 | |
615 (defvar perl-font-lock-keywords | |
616 (list | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
617 (cons (concat "[ \n\t{]*\\(" |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
618 (mapconcat 'identity |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
619 '("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
|
620 "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
|
621 "redo" "return" "local" "exec") |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
622 "\\|") |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
623 "\\)[ \n\t;(]") 1) |
4053 | 624 (mapconcat 'identity |
625 '("#endif" "#else" "#ifdef" "#ifndef" "#if" "#include" | |
626 "#define" "#undef") | |
627 "\\|") | |
4239
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
628 '("^[ \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
|
629 '("[ \n\t{]*\\(eval\\)[ \n\t(;]" 1 font-lock-function-name-face) |
4053 | 630 '("\\(--- .* ---\\|=== .* ===\\)" . font-lock-doc-string-face) |
631 ) | |
632 "Additional expressions to highlight in Perl mode.") | |
633 | |
634 (defvar tex-font-lock-keywords | |
635 (list | |
7847
43045a12cb34
(tex-font-lock-keywords): Make the pattern for
Richard M. Stallman <rms@gnu.org>
parents:
7751
diff
changeset
|
636 '("\\(\\\\\\([a-zA-Z@]+\\|.\\)\\)" 1 font-lock-keyword-face t) |
4053 | 637 '("{\\\\em\\([^}]+\\)}" 1 font-lock-comment-face t) |
638 '("{\\\\bf\\([^}]+\\)}" 1 font-lock-keyword-face t) | |
639 '("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face t) | |
640 '("\\\\\\(begin\\|end\\){\\([a-zA-Z0-9\\*]+\\)}" | |
641 2 font-lock-function-name-face t) | |
642 '("[^\\\\]\\$\\([^$]*\\)\\$" 1 font-lock-string-face t) | |
643 ; '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t) | |
644 ) | |
645 "Additional expressions to highlight in TeX mode.") | |
646 | |
647 (defvar texi-font-lock-keywords | |
648 (list | |
649 "@\\(@\\|[^}\t \n{]+\\)" ;commands | |
650 '("^\\(@c\\|@comment\\)[ \t].*$" . font-lock-comment-face) ;comments | |
651 '("^\\(*.*\\)[\t ]*$" 1 font-lock-function-name-face t) ;menu items | |
652 '("@\\(emph\\|strong\\|b\\|i\\){\\([^}]+\\)" 2 font-lock-comment-face t) | |
653 '("@\\(file\\|kbd\\|key\\){\\([^}]+\\)" 2 font-lock-string-face t) | |
654 '("@\\(samp\\|code\\|var\\){\\([^}]+\\)" 2 font-lock-function-name-face t) | |
655 '("@\\(xref\\|pxref\\){\\([^}]+\\)" 2 font-lock-keyword-face t) | |
656 '("@end *\\([a-zA-Z0-9]+\\)[ \t]*$" 1 font-lock-function-name-face t) | |
657 '("@item \\(.*\\)$" 1 font-lock-function-name-face t) | |
658 '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t) | |
659 ) | |
660 "Additional expressions to highlight in TeXinfo mode.") | |
661 | |
5726
781af712e68c
(font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents:
5717
diff
changeset
|
662 (defvar shell-font-lock-keywords |
781af712e68c
(font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents:
5717
diff
changeset
|
663 (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
|
664 '("[ \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
|
665 '("^[^ \t]+:.*$" . font-lock-string-face) |
781af712e68c
(font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents:
5717
diff
changeset
|
666 '("^\\[[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
|
667 "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
|
668 |
5752
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
669 (defvar dired-font-lock-keywords |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
670 '(;; Put directory headers in italics. |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
671 ("^ \\(/.+\\)$" 1 font-lock-type-face) |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
672 ;; Put symlinks in bold italics. |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
673 ("\\([^ ]+\\) -> [^ ]+$" . font-lock-function-name-face) |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
674 ;; Put marks in bold. |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
675 ("^\\([^ ]\\).*$" 1 font-lock-keyword-face t) |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
676 ;; Put files that are subdirectories in bold. |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
677 ("^..d.* \\([^ ]+\\)$" 1 font-lock-keyword-face)) |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
678 "Additional expressions to highlight in Dired mode.") |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
679 |
7018
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
680 (defvar rmail-font-lock-keywords |
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
681 '(;; Put From field in bold. |
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
682 ("^From: \\(.*\\)$" 1 font-lock-keyword-face) |
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
683 ;; Put subject in bold italics |
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
684 ("^Subject: \\(.*\\)$" 1 font-lock-function-name-face)) |
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
685 "Additional expressions to highlight in Rmail mode.") |
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
686 |
7751
422b83beb015
(shell-font-lock-keywords): Removed regexp for commands.
Richard M. Stallman <rms@gnu.org>
parents:
7546
diff
changeset
|
687 (defvar rmail-summary-font-lock-keywords |
422b83beb015
(shell-font-lock-keywords): Removed regexp for commands.
Richard M. Stallman <rms@gnu.org>
parents:
7546
diff
changeset
|
688 '(("^\\s *[0-9]+D.*$" . font-lock-doc-string-face) |
422b83beb015
(shell-font-lock-keywords): Removed regexp for commands.
Richard M. Stallman <rms@gnu.org>
parents:
7546
diff
changeset
|
689 ("^\\s *[0-9]+-.*$" . font-lock-keyword-face)) |
422b83beb015
(shell-font-lock-keywords): Removed regexp for commands.
Richard M. Stallman <rms@gnu.org>
parents:
7546
diff
changeset
|
690 "Additional expressions to highlight in Rmail Summary mode.") |
422b83beb015
(shell-font-lock-keywords): Removed regexp for commands.
Richard M. Stallman <rms@gnu.org>
parents:
7546
diff
changeset
|
691 |
7018
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
692 (defvar compilation-mode-font-lock-keywords |
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
693 '(("^\\([^\n:]*:\\([0-9]+:\\)+\\)\\(.*\\)$" 1 font-lock-function-name-face)) |
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
694 ;;; ("^\\([^\n:]*:\\([0-9]+:\\)+\\)\\(.*\\)$" 0 font-lock-keyword-face keep) |
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
695 "Additional expressions to highlight in Compilation mode.") |
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
696 |
7491
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
697 (defun font-lock-set-defaults () |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
698 "Set `font-lock-keywords' to something appropriate for this mode." |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
699 (if (memq major-mode '(rmail-mode dired-mode compilation-mode shell-mode)) |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
700 (setq font-lock-no-comments t)) |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
701 (if (not font-lock-keywords) ; if not already set. |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
702 (setq font-lock-keywords |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
703 (cond ((eq major-mode 'lisp-mode) lisp-font-lock-keywords) |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
704 ((eq major-mode 'emacs-lisp-mode) lisp-font-lock-keywords) |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
705 ((eq major-mode 'c-mode) c-font-lock-keywords) |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
706 ((eq major-mode 'c++-c-mode) c-font-lock-keywords) |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
707 ((eq major-mode 'c++-mode) c++-font-lock-keywords) |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
708 ((eq major-mode 'perl-mode) perl-font-lock-keywords) |
7847
43045a12cb34
(tex-font-lock-keywords): Make the pattern for
Richard M. Stallman <rms@gnu.org>
parents:
7751
diff
changeset
|
709 ((eq major-mode 'plain-tex-mode) tex-font-lock-keywords) |
43045a12cb34
(tex-font-lock-keywords): Make the pattern for
Richard M. Stallman <rms@gnu.org>
parents:
7751
diff
changeset
|
710 ((eq major-mode 'latex-mode) tex-font-lock-keywords) |
43045a12cb34
(tex-font-lock-keywords): Make the pattern for
Richard M. Stallman <rms@gnu.org>
parents:
7751
diff
changeset
|
711 ((eq major-mode 'slitex-mode) tex-font-lock-keywords) |
7491
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
712 ((eq major-mode 'texinfo-mode) texi-font-lock-keywords) |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
713 ((eq major-mode 'shell-mode) shell-font-lock-keywords) |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
714 ((eq major-mode 'dired-mode) dired-font-lock-keywords) |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
715 ((eq major-mode 'rmail-mode) rmail-font-lock-keywords) |
7751
422b83beb015
(shell-font-lock-keywords): Removed regexp for commands.
Richard M. Stallman <rms@gnu.org>
parents:
7546
diff
changeset
|
716 ((eq major-mode 'rmail-summary-mode) |
422b83beb015
(shell-font-lock-keywords): Removed regexp for commands.
Richard M. Stallman <rms@gnu.org>
parents:
7546
diff
changeset
|
717 rmail-summary-font-lock-keywords) |
7491
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
718 ((eq major-mode 'compilation-mode) |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
719 compilation-mode-font-lock-keywords) |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
720 (t nil))))) |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
721 |
4053 | 722 (provide 'font-lock) |
723 | |
724 ;;; font-lock.el ends here |