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