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