Mercurial > emacs
annotate lisp/font-lock.el @ 8636:015bd32cdb38
Initial revision
author | David J. MacKenzie <djm@gnu.org> |
---|---|
date | Fri, 26 Aug 1994 14:57:46 +0000 |
parents | a465b1335c0b |
children | 85b9cce28fd3 |
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 | |
8457
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
115 (defvar font-lock-syntax-table nil |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
116 "*Non-nil means use this syntax table for fontifying. |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
117 If this is nil, the major mode's syntax table is used.") |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
118 |
4053 | 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))) |
7915
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
218 (and (buffer-modified-p) |
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
219 (not modified) |
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
220 (set-buffer-modified-p nil))))) |
4053 | 221 |
222 ;; This code used to be used to show a string on reaching the end of it. | |
223 ;; It is probably not needed due to later changes to handle strings | |
224 ;; starting before the region in question. | |
225 ;; (if (and (null (nth 3 state)) | |
226 ;; (eq (char-syntax (preceding-char)) ?\") | |
227 ;; (save-excursion | |
228 ;; (nth 3 (parse-partial-sexp prev (1- (point)) | |
229 ;; nil nil prevstate)))) | |
230 ;; ;; We found the end of a string. | |
231 ;; (save-excursion | |
232 ;; (setq foo2 (point)) | |
233 ;; (let ((ept (point))) | |
234 ;; (forward-sexp -1) | |
235 ;; ;; Highlight the string when we see the end. | |
236 ;; ;; Doing it at the start leads to trouble: | |
237 ;; ;; either it fails to handle multiline strings | |
238 ;; ;; or it can run away when an unmatched " is inserted. | |
239 ;; (put-text-property (point) ept 'face | |
240 ;; (if (= (car state) 1) | |
241 ;; font-lock-doc-string-face | |
242 ;; font-lock-string-face))))) | |
243 | |
244 (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
|
245 (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
|
246 (buffer-read-only nil)) |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
247 (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
|
248 (set-buffer-modified-p modified))) |
4053 | 249 |
250 ;; Called when any modification is made to buffer text. | |
251 (defun font-lock-after-change-function (beg end old-len) | |
252 (save-excursion | |
253 (save-match-data | |
254 (goto-char beg) | |
255 ;; Discard the cache info if text before it has changed. | |
256 (and font-lock-cache-position | |
257 (> font-lock-cache-position beg) | |
258 (setq font-lock-cache-position nil)) | |
259 ;; Rescan till end of line. yes! | |
260 (goto-char end) | |
261 (end-of-line) | |
262 (setq end (point)) | |
263 (goto-char beg) | |
264 (beginning-of-line) | |
265 (setq beg (point)) | |
4239
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
266 ;; First scan for strings and comments. |
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
267 ;; Must scan from line start in case of |
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
268 ;; inserting space into `intfoo () {}'. |
7491
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
269 (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
|
270 (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
|
271 (font-lock-fontify-region beg (min (1+ end) (point-max)))) |
4053 | 272 ;; Now scan for keywords. |
273 (font-lock-hack-keywords beg end)))) | |
274 | |
275 ;;; Fontifying arbitrary patterns | |
276 | |
277 (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
|
278 (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
|
279 (let ((next (next-single-property-change start 'face))) |
4053 | 280 (and next (< next end))))) |
281 | |
282 (defun font-lock-hack-keywords (start end &optional loudly) | |
283 (goto-char start) | |
284 (let ((case-fold-search font-lock-keywords-case-fold-search) | |
285 (rest font-lock-keywords) | |
286 (count 0) | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
287 (buffer-read-only nil) |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
288 (modified (buffer-modified-p)) |
8457
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
289 first str match face s e allow-overlap-p |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
290 (old-syntax (syntax-table))) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
291 (unwind-protect |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
292 (progn |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
293 (if font-lock-syntax-table |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
294 (set-syntax-table font-lock-syntax-table)) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
295 (while rest |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
296 (setq first (car rest) rest (cdr rest)) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
297 (goto-char start) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
298 (cond ((consp first) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
299 (setq str (car first)) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
300 (cond ((consp (cdr first)) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
301 (setq match (nth 1 first) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
302 face (eval (nth 2 first)) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
303 allow-overlap-p (nth 3 first))) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
304 ((symbolp (cdr first)) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
305 (setq match 0 allow-overlap-p nil |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
306 face (eval (cdr first)))) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
307 (t |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
308 (setq match (cdr first) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
309 allow-overlap-p nil |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
310 face font-lock-keyword-face)))) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
311 (t |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
312 (setq str first match 0 allow-overlap-p nil |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
313 face font-lock-keyword-face))) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
314 ;(message "regexp: %s" str) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
315 (while (re-search-forward str end t) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
316 (setq s (match-beginning match) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
317 e (match-end match)) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
318 (or s (error "expression did not match subexpression %d" match)) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
319 ;; don't fontify this keyword if we're already in some other context. |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
320 (or (if allow-overlap-p nil (font-lock-any-properties-p s e)) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
321 (if (not (memq allow-overlap-p '(t nil))) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
322 (save-excursion |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
323 (goto-char s) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
324 (while (< (point) e) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
325 (let ((next (next-single-property-change (point) 'face |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
326 nil e))) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
327 (if (or (null next) (> next e)) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
328 (setq next e)) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
329 (if (not (get-text-property (point) 'face)) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
330 (put-text-property (point) next 'face face)) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
331 (goto-char next)))) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
332 (put-text-property s e 'face face)))) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
333 (if loudly (message "Fontifying %s... (regexps...%s)" |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
334 (buffer-name) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
335 (make-string (setq count (1+ count)) ?.))))) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
336 (set-syntax-table old-syntax)) |
7915
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
337 (and (buffer-modified-p) |
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
338 (not modified) |
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
339 (set-buffer-modified-p nil)))) |
4053 | 340 |
341 ;; The user level functions | |
342 | |
343 (defvar font-lock-mode nil) ; for modeline | |
344 (or (assq 'font-lock-mode minor-mode-alist) | |
345 (setq minor-mode-alist | |
346 (append minor-mode-alist | |
347 '((font-lock-mode " Font"))))) | |
348 | |
349 (defvar font-lock-fontified nil) ; whether we have hacked this buffer | |
350 (put 'font-lock-fontified 'permanent-local t) | |
351 | |
352 ;;;###autoload | |
353 (defun font-lock-mode (&optional arg) | |
354 "Toggle Font Lock mode. | |
355 With arg, turn Font Lock mode on if and only if arg is positive. | |
356 | |
357 When Font Lock mode is enabled, text is fontified as you type it: | |
358 | |
359 - comments are displayed in `font-lock-comment-face'; | |
360 (That is a variable whose value should be a face name.) | |
361 - strings are displayed in `font-lock-string-face'; | |
362 - documentation strings are displayed in `font-lock-doc-string-face'; | |
363 - function and variable names in their defining forms are displayed | |
364 in `font-lock-function-name-face'; | |
365 - and certain other expressions are displayed in other faces | |
366 according to the value of the variable `font-lock-keywords'. | |
367 | |
368 When you turn Font Lock mode on/off, the buffer is fontified/defontified. | |
369 To fontify a buffer without having newly typed text become fontified, you | |
370 can use \\[font-lock-fontify-buffer]." | |
371 (interactive "P") | |
372 (let ((on-p (if (null arg) | |
373 (not font-lock-mode) | |
374 (> (prefix-numeric-value arg) 0)))) | |
375 (if (equal (buffer-name) " *Compiler Input*") ; hack for bytecomp... | |
376 (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
|
377 (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
|
378 (if on-p |
b05a6824c512
(font-lock-after-change-function): Fix typo in prev chg.
Richard M. Stallman <rms@gnu.org>
parents:
7491
diff
changeset
|
379 (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
|
380 (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
|
381 after-change-functions))) |
b05a6824c512
(font-lock-after-change-function): Fix typo in prev chg.
Richard M. Stallman <rms@gnu.org>
parents:
7491
diff
changeset
|
382 (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
|
383 (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
|
384 (copy-sequence after-change-functions)))) |
4053 | 385 (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
|
386 (make-local-variable 'font-lock-no-comments) |
4053 | 387 (cond (on-p |
388 (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
|
389 (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
|
390 (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
|
391 ;; 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
|
392 (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
|
393 (add-hook 'after-revert-hook 'font-lock-revert-cleanup) |
4053 | 394 (run-hooks 'font-lock-mode-hook) |
395 (or font-lock-fontified (font-lock-fontify-buffer))) | |
396 (font-lock-fontified | |
397 (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
|
398 (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
|
399 (remove-hook 'after-revert-hook 'font-lock-revert-cleanup) |
4053 | 400 (font-lock-unfontify-region (point-min) (point-max)))) |
401 (force-mode-line-update))) | |
402 | |
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
|
403 ;; 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
|
404 (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
|
405 (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
|
406 |
24e1180b507d
(font-lock-mode): Use the new hooks to get proper behavior on a revert.
Karl Heuer <kwzh@gnu.org>
parents:
5625
diff
changeset
|
407 ;; 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
|
408 ;; 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
|
409 ;; 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
|
410 (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
|
411 (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
|
412 (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
|
413 (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
|
414 |
4053 | 415 (defun font-lock-fontify-buffer () |
416 "Fontify the current buffer the way `font-lock-mode' would: | |
417 | |
418 - comments are displayed in `font-lock-comment-face'; | |
419 - strings are displayed in `font-lock-string-face'; | |
420 - documentation strings are displayed in `font-lock-doc-string-face'; | |
421 - function and variable names in their defining forms are displayed | |
422 in `font-lock-function-name-face'; | |
423 - and certain other expressions are displayed in other faces | |
424 according to the value of the variable `font-lock-keywords'. | |
425 | |
426 This can take a while for large buffers." | |
427 (interactive) | |
428 (let ((was-on font-lock-mode) | |
429 (font-lock-verbose (or font-lock-verbose (interactive-p)))) | |
430 (if font-lock-verbose (message "Fontifying %s..." (buffer-name))) | |
431 ;; 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
|
432 (or was-on (font-lock-set-defaults)) |
4053 | 433 (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
|
434 (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
|
435 (message "Fontifying %s... (syntactically...)" (buffer-name))) |
4053 | 436 (save-excursion |
7491
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
437 (or font-lock-no-comments |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
438 (font-lock-fontify-region (point-min) (point-max))) |
4053 | 439 (if font-lock-verbose (message "Fontifying %s... (regexps...)" |
440 (buffer-name))) | |
441 (font-lock-hack-keywords (point-min) (point-max) font-lock-verbose)) | |
442 (set (make-local-variable 'font-lock-fontified) t) | |
443 (if font-lock-verbose (message "Fontifying %s... done." (buffer-name))) | |
444 )) | |
445 | |
446 | |
447 ;;; Various mode-specific information. | |
448 | |
449 (defconst lisp-font-lock-keywords-1 | |
450 '(;; | |
451 ;; highlight defining forms. This doesn't work too nicely for | |
452 ;; (defun (setf foo) ...) but it does work for (defvar foo) which | |
453 ;; is more important. | |
454 ("^(def[-a-z]+\\s +\\([^ \t\n\)]+\\)" 1 font-lock-function-name-face) | |
455 ;; | |
456 ;; highlight CL keywords | |
457 ("\\s :\\(\\(\\sw\\|\\s_\\)+\\)\\>" . 1) | |
458 ;; | |
459 ;; this is highlights things like (def* (setf foo) (bar baz)), but may | |
460 ;; be slower (I haven't really thought about it) | |
461 ; ("^(def[-a-z]+\\s +\\(\\s(\\S)*\\s)\\|\\S(\\S *\\)" | |
462 ; 1 font-lock-function-name-face) | |
463 ) | |
464 "For consideration as a value of `lisp-font-lock-keywords'. | |
465 This does fairly subdued highlighting.") | |
466 | |
467 (defconst lisp-font-lock-keywords-2 | |
468 (append | |
469 lisp-font-lock-keywords-1 | |
470 '(;; | |
471 ;; Highlight control structures | |
472 ("(\\(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
|
473 ("(\\(while\\|do\\|let\\*?\\|flet\\|labels\\|prog[nv12*]?\\)[ \t\n]" . 1) |
4053 | 474 ("(\\(catch\\|\\throw\\|block\\|return\\|return-from\\)[ \t\n]" . 1) |
475 ("(\\(save-restriction\\|save-window-restriction\\)[ \t\n]" . 1) | |
476 ("(\\(save-excursion\\|unwind-protect\\|condition-case\\)[ \t\n]" . 1) | |
477 ;; | |
478 ;; highlight function names in emacs-lisp docstrings (in the syntax | |
479 ;; that substitute-command-keys understands.) | |
480 ("\\\\\\\\\\[\\([^]\\\n]+\\)]" 1 font-lock-keyword-face t) | |
481 ;; | |
482 ;; highlight words inside `' which tend to be function names | |
483 ("`\\([-a-zA-Z0-9_][-a-zA-Z0-9_][-a-zA-Z0-9_.]+\\)'" | |
484 1 font-lock-keyword-face t) | |
485 )) | |
486 "For consideration as a value of `lisp-font-lock-keywords'. | |
487 This does a lot more highlighting.") | |
488 | |
489 ;; default to the gaudier variety? | |
490 ;(defvar lisp-font-lock-keywords lisp-font-lock-keywords-2 | |
491 ; "Additional expressions to highlight in Lisp modes.") | |
492 (defvar lisp-font-lock-keywords lisp-font-lock-keywords-1 | |
493 "Additional expressions to highlight in Lisp modes.") | |
494 | |
495 | |
496 (defconst c-font-lock-keywords-1 nil | |
497 "For consideration as a value of `c-font-lock-keywords'. | |
498 This does fairly subdued highlighting.") | |
499 | |
500 (defconst c-font-lock-keywords-2 nil | |
501 "For consideration as a value of `c-font-lock-keywords'. | |
502 This does a lot more highlighting.") | |
503 | |
6219
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
504 (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
|
505 "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
|
506 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
|
507 |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
508 (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
|
509 "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
|
510 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
|
511 |
6093
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
512 (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
|
513 (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
|
514 (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
|
515 (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
|
516 (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
|
517 (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
|
518 "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
|
519 "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
|
520 (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
|
521 (list |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
522 ;; 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
|
523 '("^#[ \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
|
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 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
|
526 '("^#[ \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
|
527 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
|
528 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
529 ;; 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
|
530 '("^#[ \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
|
531 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
|
532 '("^#[ \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
|
533 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
|
534 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
535 ;; 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
|
536 ;; 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
|
537 ;; 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
|
538 '("^#[ \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
|
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 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
|
541 (list (concat |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
542 "^\\(" 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
|
543 "\\(" 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
|
544 "\\(" ctoken "[ \t]+\\)?" |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
545 "\\([*&]+[ \t]*\\)?" ; pointer |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
546 "\\(" 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
|
547 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
|
548 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
549 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
550 ;; 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
|
551 (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
|
552 "[ \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
|
553 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
|
554 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
555 ;; 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
|
556 ;; (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
|
557 (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
|
558 "\\)\\>[ \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
|
559 "\\)[ \t]*[=;]") |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
560 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
|
561 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
562 ;; 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
|
563 (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
|
564 "\\)[ \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
|
565 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
|
566 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
567 ;; 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
|
568 '("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
|
569 '("\\<\\(default\\):". 1) |
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 |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
572 (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
|
573 (append c-font-lock-keywords-1 |
4053 | 574 (list |
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 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
|
577 (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
|
578 (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
|
579 (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
|
580 "\\)\\)\\>") |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
581 '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
|
582 (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
|
583 0 'font-lock-type-face 'keep) |
4053 | 584 ;; |
6093
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
585 ;; 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
|
586 (cons (concat |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
587 "[ \t]\\(" |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
588 (mapconcat 'identity |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
589 '("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
|
590 "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
|
591 "\\|") |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
592 "\\)[ \t\n(){};,]") |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
593 1) |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
594 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
595 ;; 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
|
596 ;; expression is anchored on the right. |
7915
970912d4f413
Don't alter the underline face.
Richard M. Stallman <rms@gnu.org>
parents:
7847
diff
changeset
|
597 '("[ \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
|
598 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
599 ;; 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
|
600 '("}[ \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
|
601 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
|
602 ;; |
00cee8387866
Clean up c-font-lock-keywords; now slightly more consistent about highlighting
Karl Heuer <kwzh@gnu.org>
parents:
5878
diff
changeset
|
603 ;; 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
|
604 ; '("^\\([_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
|
605 ))) |
6219
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
606 |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
607 (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
|
608 (cons |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
609 (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
|
610 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
|
611 (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
|
612 (cons |
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
613 (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
|
614 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
|
615 ) |
4053 | 616 |
617 ; default to the gaudier variety? | |
618 (defvar c-font-lock-keywords c-font-lock-keywords-1 | |
619 "Additional expressions to highlight in C mode.") | |
620 | |
6219
d960f0463014
(c++-font-lock-keywords-1, c++-font-lock-keywords-2): New variables.
Richard M. Stallman <rms@gnu.org>
parents:
6093
diff
changeset
|
621 (defvar c++-font-lock-keywords c++-font-lock-keywords-1 |
4053 | 622 "Additional expressions to highlight in C++ mode.") |
623 | |
624 | |
625 (defvar perl-font-lock-keywords | |
626 (list | |
4219
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
627 (cons (concat "[ \n\t{]*\\(" |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
628 (mapconcat 'identity |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
629 '("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
|
630 "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
|
631 "redo" "return" "local" "exec") |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
632 "\\|") |
24f3ca095be9
(perl-font-lock-keywords): Add a `(... . 1)' to the
Richard M. Stallman <rms@gnu.org>
parents:
4054
diff
changeset
|
633 "\\)[ \n\t;(]") 1) |
4053 | 634 (mapconcat 'identity |
635 '("#endif" "#else" "#ifdef" "#ifndef" "#if" "#include" | |
636 "#define" "#undef") | |
637 "\\|") | |
4239
e8cf7a7d0102
(font-lock-after-change-function):
Richard M. Stallman <rms@gnu.org>
parents:
4219
diff
changeset
|
638 '("^[ \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
|
639 '("[ \n\t{]*\\(eval\\)[ \n\t(;]" 1 font-lock-function-name-face) |
4053 | 640 '("\\(--- .* ---\\|=== .* ===\\)" . font-lock-doc-string-face) |
641 ) | |
642 "Additional expressions to highlight in Perl mode.") | |
643 | |
644 (defvar tex-font-lock-keywords | |
645 (list | |
7847
43045a12cb34
(tex-font-lock-keywords): Make the pattern for
Richard M. Stallman <rms@gnu.org>
parents:
7751
diff
changeset
|
646 '("\\(\\\\\\([a-zA-Z@]+\\|.\\)\\)" 1 font-lock-keyword-face t) |
4053 | 647 '("{\\\\em\\([^}]+\\)}" 1 font-lock-comment-face t) |
648 '("{\\\\bf\\([^}]+\\)}" 1 font-lock-keyword-face t) | |
649 '("^[ \t\n]*\\\\def[\\\\@]\\(\\w+\\)" 1 font-lock-function-name-face t) | |
650 '("\\\\\\(begin\\|end\\){\\([a-zA-Z0-9\\*]+\\)}" | |
651 2 font-lock-function-name-face t) | |
652 '("[^\\\\]\\$\\([^$]*\\)\\$" 1 font-lock-string-face t) | |
653 ; '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t) | |
654 ) | |
655 "Additional expressions to highlight in TeX mode.") | |
656 | |
657 (defvar texi-font-lock-keywords | |
658 (list | |
659 "@\\(@\\|[^}\t \n{]+\\)" ;commands | |
660 '("^\\(@c\\|@comment\\)[ \t].*$" . font-lock-comment-face) ;comments | |
661 '("^\\(*.*\\)[\t ]*$" 1 font-lock-function-name-face t) ;menu items | |
662 '("@\\(emph\\|strong\\|b\\|i\\){\\([^}]+\\)" 2 font-lock-comment-face t) | |
663 '("@\\(file\\|kbd\\|key\\){\\([^}]+\\)" 2 font-lock-string-face t) | |
664 '("@\\(samp\\|code\\|var\\){\\([^}]+\\)" 2 font-lock-function-name-face t) | |
665 '("@\\(xref\\|pxref\\){\\([^}]+\\)" 2 font-lock-keyword-face t) | |
666 '("@end *\\([a-zA-Z0-9]+\\)[ \t]*$" 1 font-lock-function-name-face t) | |
667 '("@item \\(.*\\)$" 1 font-lock-function-name-face t) | |
668 '("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t) | |
669 ) | |
670 "Additional expressions to highlight in TeXinfo mode.") | |
671 | |
5726
781af712e68c
(font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents:
5717
diff
changeset
|
672 (defvar shell-font-lock-keywords |
781af712e68c
(font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents:
5717
diff
changeset
|
673 (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
|
674 '("[ \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
|
675 '("^[^ \t]+:.*$" . font-lock-string-face) |
781af712e68c
(font-lock-set-defaults): Handle shell mode.
Richard M. Stallman <rms@gnu.org>
parents:
5717
diff
changeset
|
676 '("^\\[[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
|
677 "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
|
678 |
5752
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
679 (defvar dired-font-lock-keywords |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
680 '(;; Put directory headers in italics. |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
681 ("^ \\(/.+\\)$" 1 font-lock-type-face) |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
682 ;; Put symlinks in bold italics. |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
683 ("\\([^ ]+\\) -> [^ ]+$" . font-lock-function-name-face) |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
684 ;; Put marks in bold. |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
685 ("^\\([^ ]\\).*$" 1 font-lock-keyword-face t) |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
686 ;; Put files that are subdirectories in bold. |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
687 ("^..d.* \\([^ ]+\\)$" 1 font-lock-keyword-face)) |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
688 "Additional expressions to highlight in Dired mode.") |
412ac1a01f46
(dired-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5744
diff
changeset
|
689 |
7018
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
690 (defvar rmail-font-lock-keywords |
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
691 '(;; Put From field in bold. |
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
692 ("^From: \\(.*\\)$" 1 font-lock-keyword-face) |
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
693 ;; Put subject in bold italics |
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
694 ("^Subject: \\(.*\\)$" 1 font-lock-function-name-face)) |
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
695 "Additional expressions to highlight in Rmail mode.") |
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
696 |
7751
422b83beb015
(shell-font-lock-keywords): Removed regexp for commands.
Richard M. Stallman <rms@gnu.org>
parents:
7546
diff
changeset
|
697 (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
|
698 '(("^\\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
|
699 ("^\\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
|
700 "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
|
701 |
7018
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
702 (defvar compilation-mode-font-lock-keywords |
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
703 '(("^\\([^\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
|
704 ;;; ("^\\([^\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
|
705 "Additional expressions to highlight in Compilation mode.") |
aa83a7152b11
(rmail-font-lock-keywords): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6578
diff
changeset
|
706 |
7491
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
707 (defun font-lock-set-defaults () |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
708 "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
|
709 (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
|
710 (setq font-lock-no-comments t)) |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
711 (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
|
712 (setq font-lock-keywords |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
713 (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
|
714 ((eq major-mode 'emacs-lisp-mode) lisp-font-lock-keywords) |
8457
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
715 ((eq major-mode 'c-mode) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
716 (make-local-variable 'font-lock-syntax-table) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
717 (setq font-lock-syntax-table |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
718 (copy-syntax-table (syntax-table))) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
719 (modify-syntax-entry ?_ "w" font-lock-syntax-table) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
720 c-font-lock-keywords) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
721 ((eq major-mode 'c++-c-mode) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
722 (make-local-variable 'font-lock-syntax-table) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
723 (setq font-lock-syntax-table |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
724 (copy-syntax-table (syntax-table))) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
725 (modify-syntax-entry ?_ "w" font-lock-syntax-table) |
c0492d7043b2
(font-lock-syntax-table): New syntax table.
Richard M. Stallman <rms@gnu.org>
parents:
7915
diff
changeset
|
726 c-font-lock-keywords) |
7491
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
727 ((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
|
728 ((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
|
729 ((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
|
730 ((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
|
731 ((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
|
732 ((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
|
733 ((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
|
734 ((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
|
735 ((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
|
736 ((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
|
737 rmail-summary-font-lock-keywords) |
7491
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
738 ((eq major-mode 'compilation-mode) |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
739 compilation-mode-font-lock-keywords) |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
740 (t nil))))) |
621c162a80db
(font-lock-no-comments): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
7298
diff
changeset
|
741 |
4053 | 742 (provide 'font-lock) |
743 | |
744 ;;; font-lock.el ends here |