]> code.delx.au - gnu-emacs/blob - lisp/progmodes/cc-fonts.el
9f28bfa97b512211e4c22dc032cfd55158dad002
[gnu-emacs] / lisp / progmodes / cc-fonts.el
1 ;;; cc-fonts.el --- font lock support for CC Mode
2
3 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
4
5 ;; Authors: 2003- Alan Mackenzie
6 ;; 2002- Martin Stjernholm
7 ;; Maintainer: bug-cc-mode@gnu.org
8 ;; Created: 07-Jan-2002
9 ;; Version: See cc-mode.el
10 ;; Keywords: c languages oop
11
12 ;; This file is part of GNU Emacs.
13
14 ;; GNU Emacs is free software: you can redistribute it and/or modify
15 ;; it under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation, either version 3 of the License, or
17 ;; (at your option) any later version.
18
19 ;; GNU Emacs is distributed in the hope that it will be useful,
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ;; GNU General Public License for more details.
23
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26
27 ;;; Commentary:
28
29 ;; Some comments on the use of faces:
30 ;;
31 ;; o `c-label-face-name' is either `font-lock-constant-face' (in
32 ;; Emacs), or `font-lock-reference-face'.
33 ;;
34 ;; o `c-constant-face-name', `c-reference-face-name' and
35 ;; `c-doc-markup-face-name' are essentially set up like
36 ;; `c-label-face-name'.
37 ;;
38 ;; o `c-preprocessor-face-name' is `font-lock-preprocessor-face' in
39 ;; XEmacs and - in lack of a closer equivalent -
40 ;; `font-lock-builtin-face' or `font-lock-reference-face' in Emacs.
41 ;;
42 ;; o `c-doc-face-name' is `font-lock-doc-string-face' in XEmacs,
43 ;; `font-lock-doc-face' in Emacs 21 and later, or
44 ;; `font-lock-comment-face' in older Emacs (that since source
45 ;; documentation are actually comments in these languages, as opposed
46 ;; to elisp).
47 ;;
48 ;; TBD: We should probably provide real faces for the above uses and
49 ;; instead initialize them from the standard faces.
50
51 ;;; Code:
52
53 ;; The faces that already have been put onto the text is tested in
54 ;; various places to direct further fontifications. For this to work,
55 ;; the following assumptions regarding the faces must hold (apart from
56 ;; the dependencies on the font locking order):
57 ;;
58 ;; o `font-lock-comment-face' and the face in `c-doc-face-name' is
59 ;; not used in anything but comments.
60 ;; o If any face (e.g. `c-doc-markup-face-name') but those above is
61 ;; used in comments, it doesn't replace them.
62 ;; o `font-lock-string-face' is not used in anything but string
63 ;; literals (single or double quoted).
64 ;; o `font-lock-keyword-face' and the face in `c-label-face-name' are
65 ;; never overlaid with other faces.
66
67 (eval-when-compile
68 (let ((load-path
69 (if (and (boundp 'byte-compile-dest-file)
70 (stringp byte-compile-dest-file))
71 (cons (file-name-directory byte-compile-dest-file) load-path)
72 load-path)))
73 (load "cc-bytecomp" nil t)))
74
75 (cc-require 'cc-defs)
76 (cc-require-when-compile 'cc-langs)
77 (cc-require 'cc-vars)
78 (cc-require 'cc-engine)
79 (cc-require-when-compile 'cc-awk) ; Change from cc-require, 2003/6/18 to
80 ;; prevent cc-awk being loaded when it's not needed. There is now a (require
81 ;; 'cc-awk) in (defun awk-mode ..).
82
83 ;; Avoid repeated loading through the eval-after-load directive in
84 ;; cc-mode.el.
85 (provide 'cc-fonts)
86
87 (cc-external-require 'font-lock)
88
89 (cc-bytecomp-defvar parse-sexp-lookup-properties) ; Emacs only.
90
91 ;; Need to declare these local symbols during compilation since
92 ;; they're referenced from lambdas in `byte-compile' calls that are
93 ;; executed at compile time. They don't need to have the proper
94 ;; definitions, though, since the generated functions aren't called
95 ;; during compilation.
96 (cc-bytecomp-defvar c-preprocessor-face-name)
97 (cc-bytecomp-defvar c-reference-face-name)
98 (cc-bytecomp-defun c-fontify-recorded-types-and-refs)
99 (cc-bytecomp-defun c-font-lock-declarators)
100 (cc-bytecomp-defun c-font-lock-objc-method)
101 (cc-bytecomp-defun c-font-lock-invalid-string)
102
103 \f
104 ;; Note that font-lock in XEmacs doesn't expand face names as
105 ;; variables, so we have to use the (eval . FORM) in the font lock
106 ;; matchers wherever we use these alias variables.
107
108 (defconst c-preprocessor-face-name
109 (cond ((c-face-name-p 'font-lock-preprocessor-face)
110 ;; XEmacs has a font-lock-preprocessor-face.
111 'font-lock-preprocessor-face)
112 ((c-face-name-p 'font-lock-builtin-face)
113 ;; In Emacs font-lock-builtin-face has traditionally been
114 ;; used for preprocessor directives.
115 'font-lock-builtin-face)
116 (t
117 'font-lock-reference-face)))
118
119 (cc-bytecomp-defvar font-lock-constant-face)
120
121 (defconst c-label-face-name
122 (cond ((c-face-name-p 'font-lock-label-face)
123 ;; If it happens to occur in the future. (Well, the more
124 ;; pragmatic reason is to get unique faces for the test
125 ;; suite.)
126 'font-lock-label-face)
127 ((and (c-face-name-p 'font-lock-constant-face)
128 (eq font-lock-constant-face 'font-lock-constant-face))
129 ;; Test both if font-lock-constant-face exists and that it's
130 ;; not an alias for something else. This is important since
131 ;; we compare already set faces in various places.
132 'font-lock-constant-face)
133 (t
134 'font-lock-reference-face)))
135
136 (defconst c-constant-face-name
137 (if (and (c-face-name-p 'font-lock-constant-face)
138 (eq font-lock-constant-face 'font-lock-constant-face))
139 ;; This doesn't exist in some earlier versions of XEmacs 21.
140 'font-lock-constant-face
141 c-label-face-name))
142
143 (defconst c-reference-face-name
144 (with-no-warnings
145 (if (and (c-face-name-p 'font-lock-reference-face)
146 (eq font-lock-reference-face 'font-lock-reference-face))
147 ;; This is considered obsolete in Emacs, but it still maps well
148 ;; to this use. (Another reason to do this is to get unique
149 ;; faces for the test suite.)
150 'font-lock-reference-face
151 c-label-face-name)))
152
153 ;; This should not mapped to a face that also is used to fontify things
154 ;; that aren't comments or string literals.
155 (defconst c-doc-face-name
156 (cond ((c-face-name-p 'font-lock-doc-string-face)
157 ;; XEmacs.
158 'font-lock-doc-string-face)
159 ((c-face-name-p 'font-lock-doc-face)
160 ;; Emacs 21 and later.
161 'font-lock-doc-face)
162 (t
163 'font-lock-comment-face)))
164
165 (defconst c-doc-markup-face-name
166 (if (c-face-name-p 'font-lock-doc-markup-face)
167 ;; If it happens to occur in the future. (Well, the more
168 ;; pragmatic reason is to get unique faces for the test
169 ;; suite.)
170 'font-lock-doc-markup-face
171 c-label-face-name))
172
173 (defconst c-negation-char-face-name
174 (if (c-face-name-p 'font-lock-negation-char-face)
175 ;; Emacs 22 has a special face for negation chars.
176 'font-lock-negation-char-face))
177
178 (cc-bytecomp-defun face-inverse-video-p) ; Only in Emacs.
179 (cc-bytecomp-defun face-property-instance) ; Only in XEmacs.
180
181 (defun c-make-inverse-face (oldface newface)
182 ;; Emacs and XEmacs have completely different face manipulation
183 ;; routines. :P
184 (copy-face oldface newface)
185 (cond ((fboundp 'face-inverse-video-p)
186 ;; Emacs. This only looks at the inverse flag in the current
187 ;; frame. Other display configurations might be different,
188 ;; but it can only show if the same Emacs has frames on
189 ;; e.g. a color and a monochrome display simultaneously.
190 (unless (face-inverse-video-p oldface)
191 (invert-face newface)))
192 ((fboundp 'face-property-instance)
193 ;; XEmacs. Same pitfall here.
194 (unless (face-property-instance oldface 'reverse)
195 (invert-face newface)))))
196
197 (eval-and-compile
198 ;; We need the following functions during compilation since they're
199 ;; called when the `c-lang-defconst' initializers are evaluated.
200 ;; Define them at runtime too for the sake of derived modes.
201
202 (defmacro c-put-font-lock-face (from to face)
203 ;; Put a face on a region (overriding any existing face) in the way
204 ;; font-lock would do it. In XEmacs that means putting an
205 ;; additional font-lock property, or else the font-lock package
206 ;; won't recognize it as fontified and might override it
207 ;; incorrectly.
208 ;;
209 ;; This function does a hidden buffer change.
210 (if (fboundp 'font-lock-set-face)
211 ;; Note: This function has no docstring in XEmacs so it might be
212 ;; considered internal.
213 `(font-lock-set-face ,from ,to ,face)
214 `(put-text-property ,from ,to 'face ,face)))
215
216 (defmacro c-remove-font-lock-face (from to)
217 ;; This is the inverse of `c-put-font-lock-face'.
218 ;;
219 ;; This function does a hidden buffer change.
220 (if (fboundp 'font-lock-remove-face)
221 `(font-lock-remove-face ,from ,to)
222 `(remove-text-properties ,from ,to '(face nil))))
223
224 (defmacro c-put-font-lock-string-face (from to)
225 ;; Put `font-lock-string-face' on a string. The surrounding
226 ;; quotes are included in Emacs but not in XEmacs. The passed
227 ;; region should include them.
228 ;;
229 ;; This function does a hidden buffer change.
230 (if (featurep 'xemacs)
231 `(c-put-font-lock-face (1+ ,from) (1- ,to) 'font-lock-string-face)
232 `(c-put-font-lock-face ,from ,to 'font-lock-string-face)))
233
234 (defmacro c-fontify-types-and-refs (varlist &rest body)
235 ;; Like `let', but additionally activates `c-record-type-identifiers'
236 ;; and `c-record-ref-identifiers', and fontifies the recorded ranges
237 ;; accordingly on exit.
238 ;;
239 ;; This function does hidden buffer changes.
240 `(let ((c-record-type-identifiers t)
241 c-record-ref-identifiers
242 ,@varlist)
243 (prog1 (progn ,@body)
244 (c-fontify-recorded-types-and-refs))))
245 (put 'c-fontify-types-and-refs 'lisp-indent-function 1)
246
247 (defun c-skip-comments-and-strings (limit)
248 ;; If the point is within a region fontified as a comment or
249 ;; string literal skip to the end of it or to LIMIT, whichever
250 ;; comes first, and return t. Otherwise return nil. The match
251 ;; data is not clobbered.
252 ;;
253 ;; This function might do hidden buffer changes.
254 (when (c-got-face-at (point) c-literal-faces)
255 (while (progn
256 (goto-char (next-single-property-change
257 (point) 'face nil limit))
258 (and (< (point) limit)
259 (c-got-face-at (point) c-literal-faces))))
260 t))
261
262 (defun c-make-syntactic-matcher (regexp)
263 ;; Returns a byte compiled function suitable for use in place of a
264 ;; regexp string in a `font-lock-keywords' matcher, except that
265 ;; only matches outside comments and string literals count.
266 ;;
267 ;; This function does not do any hidden buffer changes, but the
268 ;; generated functions will. (They are however used in places
269 ;; covered by the font-lock context.)
270 (byte-compile
271 `(lambda (limit)
272 (let (res)
273 (while (and (setq res (re-search-forward ,regexp limit t))
274 (progn
275 (goto-char (match-beginning 0))
276 (or (c-skip-comments-and-strings limit)
277 (progn
278 (goto-char (match-end 0))
279 nil)))))
280 res))))
281
282 (defun c-make-font-lock-search-function (regexp &rest highlights)
283 ;; This function makes a byte compiled function that works much like
284 ;; a matcher element in `font-lock-keywords'. It cuts out a little
285 ;; bit of the overhead compared to a real matcher. The main reason
286 ;; is however to pass the real search limit to the anchored
287 ;; matcher(s), since most (if not all) font-lock implementations
288 ;; arbitrarily limits anchored matchers to the same line, and also
289 ;; to insulate against various other irritating differences between
290 ;; the different (X)Emacs font-lock packages.
291 ;;
292 ;; REGEXP is the matcher, which must be a regexp. Only matches
293 ;; where the beginning is outside any comment or string literal are
294 ;; significant.
295 ;;
296 ;; HIGHLIGHTS is a list of highlight specs, just like in
297 ;; `font-lock-keywords', with these limitations: The face is always
298 ;; overridden (no big disadvantage, since hits in comments etc are
299 ;; filtered anyway), there is no "laxmatch", and an anchored matcher
300 ;; is always a form which must do all the fontification directly.
301 ;; `limit' is a variable bound to the real limit in the context of
302 ;; the anchored matcher forms.
303 ;;
304 ;; This function does not do any hidden buffer changes, but the
305 ;; generated functions will. (They are however used in places
306 ;; covered by the font-lock context.)
307
308 ;; Note: Replace `byte-compile' with `eval' to debug the generated
309 ;; lambda easier.
310 (byte-compile
311 `(lambda (limit)
312 (let (;; The font-lock package in Emacs is known to clobber
313 ;; `parse-sexp-lookup-properties' (when it exists).
314 (parse-sexp-lookup-properties
315 (cc-eval-when-compile
316 (boundp 'parse-sexp-lookup-properties))))
317 (while (re-search-forward ,regexp limit t)
318 (unless (progn
319 (goto-char (match-beginning 0))
320 (c-skip-comments-and-strings limit))
321 (goto-char (match-end 0))
322 ,@(mapcar
323 (lambda (highlight)
324 (if (integerp (car highlight))
325 (progn
326 (unless (eq (nth 2 highlight) t)
327 (error
328 "The override flag must currently be t in %s"
329 highlight))
330 (when (nth 3 highlight)
331 (error
332 "The laxmatch flag may currently not be set in %s"
333 highlight))
334 `(save-match-data
335 (c-put-font-lock-face
336 (match-beginning ,(car highlight))
337 (match-end ,(car highlight))
338 ,(elt highlight 1))))
339 (when (nth 3 highlight)
340 (error "Match highlights currently not supported in %s"
341 highlight))
342 `(progn
343 ,(nth 1 highlight)
344 (save-match-data ,(car highlight))
345 ,(nth 2 highlight))))
346 highlights))))
347 nil)))
348
349 ; (eval-after-load "edebug" ; 2006-07-09: def-edebug-spec is now in subr.el.
350 ; '(progn
351 (def-edebug-spec c-fontify-types-and-refs let*)
352 (def-edebug-spec c-make-syntactic-matcher t)
353 ;; If there are literal quoted or backquoted highlight specs in
354 ;; the call to `c-make-font-lock-search-function' then let's
355 ;; instrument the forms in them.
356 (def-edebug-spec c-make-font-lock-search-function
357 (form &rest &or ("quote" (&rest form)) ("`" (&rest form)) form)));))
358
359 (defun c-fontify-recorded-types-and-refs ()
360 ;; Convert the ranges recorded on `c-record-type-identifiers' and
361 ;; `c-record-ref-identifiers' to fontification.
362 ;;
363 ;; This function does hidden buffer changes.
364 (let (elem)
365 (while (consp c-record-type-identifiers)
366 (setq elem (car c-record-type-identifiers)
367 c-record-type-identifiers (cdr c-record-type-identifiers))
368 (c-put-font-lock-face (car elem) (cdr elem)
369 'font-lock-type-face))
370 (while c-record-ref-identifiers
371 (setq elem (car c-record-ref-identifiers)
372 c-record-ref-identifiers (cdr c-record-ref-identifiers))
373 ;; Note that the reference face is a variable that is
374 ;; dereferenced, since it's an alias in Emacs.
375 (c-put-font-lock-face (car elem) (cdr elem)
376 c-reference-face-name))))
377
378 (c-lang-defconst c-cpp-matchers
379 "Font lock matchers for preprocessor directives and purely lexical
380 stuff. Used on level 1 and higher."
381
382 ;; Note: `c-font-lock-declarations' assumes that no matcher here
383 ;; sets `font-lock-type-face' in languages where
384 ;; `c-recognize-<>-arglists' is set.
385
386 t `(,@(when (c-lang-const c-opt-cpp-prefix)
387 (let* ((noncontinued-line-end "\\(\\=\\|\\(\\=\\|[^\\]\\)[\n\r]\\)")
388 (ncle-depth (regexp-opt-depth noncontinued-line-end))
389 (sws-depth (c-lang-const c-syntactic-ws-depth))
390 (nsws-depth (c-lang-const c-nonempty-syntactic-ws-depth)))
391
392 `(;; The stuff after #error and #warning is a message, so
393 ;; fontify it as a string.
394 ,@(when (c-lang-const c-cpp-message-directives)
395 (let* ((re (c-make-keywords-re 'appendable ; nil
396 (c-lang-const c-cpp-message-directives)))
397 (re-depth (regexp-opt-depth re)))
398 `((,(concat noncontinued-line-end
399 (c-lang-const c-opt-cpp-prefix)
400 re
401 "\\s +\\(.*\\)$")
402 ,(+ ncle-depth re-depth 1) font-lock-string-face t))))
403
404 ;; Fontify filenames in #include <...> as strings.
405 ,@(when (c-lang-const c-cpp-include-directives)
406 (let* ((re (c-make-keywords-re nil
407 (c-lang-const c-cpp-include-directives)))
408 (re-depth (regexp-opt-depth re)))
409 `((,(concat noncontinued-line-end
410 (c-lang-const c-opt-cpp-prefix)
411 re
412 (c-lang-const c-syntactic-ws)
413 "\\(<[^>\n\r]*>?\\)")
414 (,(+ ncle-depth re-depth sws-depth 1)
415 font-lock-string-face)
416
417 ;; Use an anchored matcher to put paren syntax
418 ;; on the brackets.
419 (,(byte-compile
420 `(lambda (limit)
421 (let ((beg (match-beginning
422 ,(+ ncle-depth re-depth sws-depth 1)))
423 (end (1- (match-end ,(+ ncle-depth re-depth
424 sws-depth 1)))))
425 (if (eq (char-after end) ?>)
426 (progn
427 (c-mark-<-as-paren beg)
428 (c-mark->-as-paren end))
429 (c-clear-char-property beg 'syntax-table)))
430 nil)))))))
431
432 ;; #define.
433 ,@(when (c-lang-const c-opt-cpp-macro-define)
434 `((,(c-make-font-lock-search-function
435 (concat
436 noncontinued-line-end
437 (c-lang-const c-opt-cpp-prefix)
438 (c-lang-const c-opt-cpp-macro-define)
439 (c-lang-const c-nonempty-syntactic-ws)
440 "\\(" (c-lang-const ; 1 + ncle + nsws
441 c-symbol-key) "\\)"
442 (concat "\\(" ; 2 + ncle + nsws + c-sym-key
443 ;; Macro with arguments - a "function".
444 "\\(\(\\)" ; 3 + ncle + nsws + c-sym-key
445 "\\|"
446 ;; Macro without arguments - a "variable".
447 "\\([^\(]\\|$\\)"
448 "\\)"))
449 `((if (match-beginning
450 ,(+ 3 ncle-depth nsws-depth
451 (c-lang-const c-symbol-key-depth)))
452
453 ;; "Function". Fontify the name and the arguments.
454 (save-restriction
455 (c-put-font-lock-face
456 (match-beginning ,(+ 1 ncle-depth nsws-depth))
457 (match-end ,(+ 1 ncle-depth nsws-depth))
458 'font-lock-function-name-face)
459 (goto-char
460 (match-end
461 ,(+ 3 ncle-depth nsws-depth
462 (c-lang-const c-symbol-key-depth))))
463
464 (narrow-to-region (point-min) limit)
465 (while (and
466 (progn
467 (c-forward-syntactic-ws)
468 (looking-at c-symbol-key))
469 (progn
470 (c-put-font-lock-face
471 (match-beginning 0) (match-end 0)
472 'font-lock-variable-name-face)
473 (goto-char (match-end 0))
474 (c-forward-syntactic-ws)
475 (eq (char-after) ?,)))
476 (forward-char)))
477
478 ;; "Variable".
479 (c-put-font-lock-face
480 (match-beginning ,(+ 1 ncle-depth nsws-depth))
481 (match-end ,(+ 1 ncle-depth nsws-depth))
482 'font-lock-variable-name-face)))))))
483
484 ;; Fontify cpp function names in preprocessor
485 ;; expressions in #if and #elif.
486 ,@(when (and (c-lang-const c-cpp-expr-directives)
487 (c-lang-const c-cpp-expr-functions))
488 (let ((ced-re (c-make-keywords-re t
489 (c-lang-const c-cpp-expr-directives)))
490 (cef-re (c-make-keywords-re t
491 (c-lang-const c-cpp-expr-functions))))
492 `((,(c-make-font-lock-search-function
493 (concat noncontinued-line-end
494 (c-lang-const c-opt-cpp-prefix)
495 ced-re ; 1 + ncle-depth
496 ;; Match the whole logical line to look
497 ;; for the functions in.
498 "\\(\\\\\\(.\\|[\n\r]\\)\\|[^\n\r]\\)*")
499 `((let ((limit (match-end 0)))
500 (while (re-search-forward ,cef-re limit 'move)
501 (c-put-font-lock-face (match-beginning 1)
502 (match-end 1)
503 c-preprocessor-face-name)))
504 (goto-char (match-end ,(1+ ncle-depth)))))))))
505
506 ;; Fontify the directive names.
507 (,(c-make-font-lock-search-function
508 (concat noncontinued-line-end
509 "\\("
510 (c-lang-const c-opt-cpp-prefix)
511 "[" (c-lang-const c-symbol-chars) "]+"
512 "\\)")
513 `(,(1+ ncle-depth) c-preprocessor-face-name t)))
514
515 (eval . (list ,(c-make-syntactic-matcher
516 (concat noncontinued-line-end
517 (c-lang-const c-opt-cpp-prefix)
518 "if\\(n\\)def\\>"))
519 ,(+ ncle-depth 1)
520 c-negation-char-face-name
521 'append))
522 )))
523
524 ,@(when (c-major-mode-is 'pike-mode)
525 ;; Recognize hashbangs in Pike.
526 `((eval . (list "\\`#![^\n\r]*"
527 0 c-preprocessor-face-name))))
528
529 ;; Make hard spaces visible through an inverted `font-lock-warning-face'.
530 (eval . (list
531 "\240"
532 0 (progn
533 (unless (c-face-name-p 'c-nonbreakable-space-face)
534 (c-make-inverse-face 'font-lock-warning-face
535 'c-nonbreakable-space-face))
536 ''c-nonbreakable-space-face)))
537 ))
538
539 (defun c-font-lock-invalid-string ()
540 ;; Assuming the point is after the opening character of a string,
541 ;; fontify that char with `font-lock-warning-face' if the string
542 ;; decidedly isn't terminated properly.
543 ;;
544 ;; This function does hidden buffer changes.
545 (let ((start (1- (point))))
546 (save-excursion
547 (and (eq (elt (parse-partial-sexp start (c-point 'eol)) 8) start)
548 (if (integerp c-multiline-string-start-char)
549 ;; There's no multiline string start char before the
550 ;; string, so newlines aren't allowed.
551 (not (eq (char-before start) c-multiline-string-start-char))
552 ;; Multiline strings are allowed anywhere if
553 ;; c-multiline-string-start-char is t.
554 (not c-multiline-string-start-char))
555 (if c-string-escaped-newlines
556 ;; There's no \ before the newline.
557 (not (eq (char-before (point)) ?\\))
558 ;; Escaped newlines aren't supported.
559 t)
560 (c-put-font-lock-face start (1+ start) 'font-lock-warning-face)))))
561
562 (c-lang-defconst c-basic-matchers-before
563 "Font lock matchers for basic keywords, labels, references and various
564 other easily recognizable things that should be fontified before generic
565 casts and declarations are fontified. Used on level 2 and higher."
566
567 ;; Note: `c-font-lock-declarations' assumes that no matcher here
568 ;; sets `font-lock-type-face' in languages where
569 ;; `c-recognize-<>-arglists' is set.
570
571 t `(;; Put a warning face on the opener of unclosed strings that
572 ;; can't span lines. Later font
573 ;; lock packages have a `font-lock-syntactic-face-function' for
574 ;; this, but it doesn't give the control we want since any
575 ;; fontification done inside the function will be
576 ;; unconditionally overridden.
577 ,(c-make-font-lock-search-function
578 ;; Match a char before the string starter to make
579 ;; `c-skip-comments-and-strings' work correctly.
580 (concat ".\\(" c-string-limit-regexp "\\)")
581 '((c-font-lock-invalid-string)))
582
583 ;; Fontify keyword constants.
584 ,@(when (c-lang-const c-constant-kwds)
585 (let ((re (c-make-keywords-re nil (c-lang-const c-constant-kwds))))
586 (if (c-major-mode-is 'pike-mode)
587 ;; No symbol is a keyword after "->" in Pike.
588 `((eval . (list ,(concat "\\(\\=.?\\|[^>]\\|[^-]>\\)"
589 "\\<\\(" re "\\)\\>")
590 2 c-constant-face-name)))
591 `((eval . (list ,(concat "\\<\\(" re "\\)\\>")
592 1 c-constant-face-name))))))
593
594 ;; Fontify all keywords except the primitive types.
595 ,(if (c-major-mode-is 'pike-mode)
596 ;; No symbol is a keyword after "->" in Pike.
597 `(,(concat "\\(\\=.?\\|[^>]\\|[^-]>\\)"
598 "\\<" (c-lang-const c-regular-keywords-regexp))
599 2 font-lock-keyword-face)
600 `(,(concat "\\<" (c-lang-const c-regular-keywords-regexp))
601 1 font-lock-keyword-face))
602
603 ;; Fontify leading identifiers in fully qualified names like
604 ;; "foo::bar" in languages that supports such things.
605 ,@(when (c-lang-const c-opt-identifier-concat-key)
606 (if (c-major-mode-is 'java-mode)
607 ;; Java needs special treatment since "." is used both to
608 ;; qualify names and in normal indexing. Here we look for
609 ;; capital characters at the beginning of an identifier to
610 ;; recognize the class. "*" is also recognized to cover
611 ;; wildcard import declarations. All preceding dot separated
612 ;; identifiers are taken as package names and therefore
613 ;; fontified as references.
614 `(,(c-make-font-lock-search-function
615 ;; Search for class identifiers preceded by ".". The
616 ;; anchored matcher takes it from there.
617 (concat (c-lang-const c-opt-identifier-concat-key)
618 (c-lang-const c-simple-ws) "*"
619 (concat "\\("
620 "[" c-upper "]"
621 "[" (c-lang-const c-symbol-chars) "]*"
622 "\\|"
623 "\\*"
624 "\\)"))
625 `((let (id-end)
626 (goto-char (1+ (match-beginning 0)))
627 (while (and (eq (char-before) ?.)
628 (progn
629 (backward-char)
630 (c-backward-syntactic-ws)
631 (setq id-end (point))
632 (< (skip-chars-backward
633 ,(c-lang-const c-symbol-chars)) 0))
634 (not (get-text-property (point) 'face)))
635 (c-put-font-lock-face (point) id-end
636 c-reference-face-name)
637 (c-backward-syntactic-ws)))
638 nil
639 (goto-char (match-end 0)))))
640
641 `((,(byte-compile
642 ;; Must use a function here since we match longer than
643 ;; we want to move before doing a new search. This is
644 ;; not necessary for XEmacs since it restarts the
645 ;; search from the end of the first highlighted
646 ;; submatch (something that causes problems in other
647 ;; places).
648 `(lambda (limit)
649 (while (re-search-forward
650 ,(concat "\\(\\<" ; 1
651 "\\(" (c-lang-const c-symbol-key) "\\)" ; 2
652 (c-lang-const c-simple-ws) "*"
653 (c-lang-const c-opt-identifier-concat-key)
654 (c-lang-const c-simple-ws) "*"
655 "\\)"
656 "\\("
657 (c-lang-const c-opt-after-id-concat-key)
658 "\\)")
659 limit t)
660 (unless (progn
661 (goto-char (match-beginning 0))
662 (c-skip-comments-and-strings limit))
663 (or (get-text-property (match-beginning 2) 'face)
664 (c-put-font-lock-face (match-beginning 2)
665 (match-end 2)
666 c-reference-face-name))
667 (goto-char (match-end 1))))))))))
668
669 ;; Fontify the special declarations in Objective-C.
670 ,@(when (c-major-mode-is 'objc-mode)
671 `(;; Fontify class names in the beginning of message expressions.
672 ,(c-make-font-lock-search-function
673 "\\["
674 '((c-fontify-types-and-refs ()
675 (c-forward-syntactic-ws limit)
676 (let ((start (point)))
677 ;; In this case we accept both primitive and known types.
678 (when (eq (c-forward-type) 'known)
679 (goto-char start)
680 (let ((c-promote-possible-types t))
681 (c-forward-type))))
682 (if (> (point) limit) (goto-char limit)))))
683
684 ;; The @interface/@implementation/@protocol directives.
685 ,(c-make-font-lock-search-function
686 (concat "\\<"
687 (regexp-opt
688 '("@interface" "@implementation" "@protocol")
689 t)
690 "\\>")
691 '((c-fontify-types-and-refs
692 (;; The font-lock package in Emacs is known to clobber
693 ;; `parse-sexp-lookup-properties' (when it exists).
694 (parse-sexp-lookup-properties
695 (cc-eval-when-compile
696 (boundp 'parse-sexp-lookup-properties))))
697 (c-forward-objc-directive)
698 nil)
699 (goto-char (match-beginning 0))))))
700
701 (eval . (list "\\(!\\)[^=]" 1 c-negation-char-face-name))
702 ))
703
704 (defun c-font-lock-complex-decl-prepare (limit)
705 ;; This function will be called from font-lock for a region bounded by POINT
706 ;; and LIMIT, as though it were to identify a keyword for
707 ;; font-lock-keyword-face. It always returns NIL to inhibit this and
708 ;; prevent a repeat invocation. See elisp/lispref page "Search-based
709 ;; Fontification".
710 ;;
711 ;; Called before any of the matchers in `c-complex-decl-matchers'.
712 ;;
713 ;; This function does hidden buffer changes.
714
715 ;;(message "c-font-lock-complex-decl-prepare %s %s" (point) limit)
716
717 ;; Clear the list of found types if we start from the start of the
718 ;; buffer, to make it easier to get rid of misspelled types and
719 ;; variables that has gotten recognized as types in malformed code.
720 (when (bobp)
721 (c-clear-found-types))
722
723 ;; Clear the c-type char properties in the region to recalculate
724 ;; them properly. This is necessary e.g. to handle constructs that
725 ;; might been required as declarations temporarily during editing.
726 ;; The interesting properties are anyway those put on the closest
727 ;; token before the region.
728 (c-clear-char-properties (point) limit 'c-type)
729
730 ;; Update `c-state-cache' to the beginning of the region. This will
731 ;; make `c-beginning-of-syntax' go faster when it's used later on,
732 ;; and it's near the point most of the time.
733 (c-parse-state)
734
735 ;; Check if the fontified region starts inside a declarator list so
736 ;; that `c-font-lock-declarators' should be called at the start.
737 (let ((prop (save-excursion
738 (c-backward-syntactic-ws)
739 (unless (bobp)
740 (c-get-char-property (1- (point)) 'c-type)))))
741 (when (memq prop '(c-decl-id-start c-decl-type-start))
742 (c-forward-syntactic-ws limit)
743 (c-font-lock-declarators limit t (eq prop 'c-decl-type-start))))
744
745 nil)
746
747 (defun c-font-lock-<>-arglists (limit)
748 ;; This function will be called from font-lock for a region bounded by POINT
749 ;; and LIMIT, as though it were to identify a keyword for
750 ;; font-lock-keyword-face. It always returns NIL to inhibit this and
751 ;; prevent a repeat invocation. See elisp/lispref page "Search-based
752 ;; Fontification".
753 ;;
754 ;; Fontify types and references in names containing angle bracket
755 ;; arglists from the point to LIMIT. Note that
756 ;; `c-font-lock-declarations' already has handled many of them.
757 ;;
758 ;; This function might do hidden buffer changes.
759
760 (let (;; The font-lock package in Emacs is known to clobber
761 ;; `parse-sexp-lookup-properties' (when it exists).
762 (parse-sexp-lookup-properties
763 (cc-eval-when-compile
764 (boundp 'parse-sexp-lookup-properties)))
765 (c-parse-and-markup-<>-arglists t)
766 c-restricted-<>-arglists
767 id-start id-end id-face pos kwd-sym)
768
769 (while (and (< (point) limit)
770 (re-search-forward c-opt-<>-arglist-start limit t))
771
772 (setq id-start (match-beginning 1)
773 id-end (match-end 1)
774 pos (point))
775
776 (goto-char id-start)
777 (unless (c-skip-comments-and-strings limit)
778 (setq kwd-sym nil
779 c-restricted-<>-arglists nil
780 id-face (get-text-property id-start 'face))
781
782 (if (cond
783 ((eq id-face 'font-lock-type-face)
784 ;; The identifier got the type face so it has already been
785 ;; handled in `c-font-lock-declarations'.
786 nil)
787
788 ((eq id-face 'font-lock-keyword-face)
789 (when (looking-at c-opt-<>-sexp-key)
790 ;; There's a special keyword before the "<" that tells
791 ;; that it's an angle bracket arglist.
792 (setq kwd-sym (c-keyword-sym (match-string 1)))))
793
794 (t
795 ;; There's a normal identifier before the "<". If we're not in
796 ;; a declaration context then we set `c-restricted-<>-arglists'
797 ;; to avoid recognizing templates in function calls like "foo (a
798 ;; < b, c > d)".
799 (c-backward-syntactic-ws)
800 (when (and (memq (char-before) '(?\( ?,))
801 (not (eq (get-text-property (1- (point)) 'c-type)
802 'c-decl-arg-start)))
803 (setq c-restricted-<>-arglists t))
804 t))
805
806 (progn
807 (goto-char (1- pos))
808 ;; Check for comment/string both at the identifier and
809 ;; at the "<".
810 (unless (c-skip-comments-and-strings limit)
811
812 (c-fontify-types-and-refs ()
813 (when (c-forward-<>-arglist (c-keyword-member
814 kwd-sym 'c-<>-type-kwds))
815 (when (and c-opt-identifier-concat-key
816 (not (get-text-property id-start 'face)))
817 (c-forward-syntactic-ws)
818 (if (looking-at c-opt-identifier-concat-key)
819 (c-put-font-lock-face id-start id-end
820 c-reference-face-name)
821 (c-put-font-lock-face id-start id-end
822 'font-lock-type-face)))))
823
824 (goto-char pos)))
825 (goto-char pos)))))
826 nil)
827
828 (defun c-font-lock-declarators (limit list types)
829 ;; Assuming the point is at the start of a declarator in a
830 ;; declaration, fontify it. If LIST is non-nil, fontify also all
831 ;; following declarators in a comma separated list (e.g. "foo" and
832 ;; "bar" in "int foo = 17, bar;"). Stop at LIMIT. If TYPES is
833 ;; non-nil, fontify all identifiers as types. Nil is always
834 ;; returned.
835 ;;
836 ;; This function might do hidden buffer changes.
837
838 ;;(message "c-font-lock-declarators from %s to %s" (point) limit)
839 (c-fontify-types-and-refs
840 ((pos (point)) next-pos id-start id-end
841 paren-depth
842 id-face got-init
843 c-last-identifier-range
844 (separator-prop (if types 'c-decl-type-start 'c-decl-id-start)))
845
846 (while (and
847 pos
848 (< (point) limit)
849
850 (let (got-identifier)
851 (setq paren-depth 0)
852 ;; Skip over type decl prefix operators. (Note similar
853 ;; code in `c-forward-decl-or-cast-1'.)
854 (while (and (looking-at c-type-decl-prefix-key)
855 (if (and (c-major-mode-is 'c++-mode)
856 (match-beginning 2))
857 ;; If the second submatch matches in C++ then
858 ;; we're looking at an identifier that's a
859 ;; prefix only if it specifies a member pointer.
860 (progn
861 (setq id-start (point))
862 (c-forward-name)
863 (if (looking-at "\\(::\\)")
864 ;; We only check for a trailing "::" and
865 ;; let the "*" that should follow be
866 ;; matched in the next round.
867 t
868 ;; It turned out to be the real identifier,
869 ;; so flag that and stop.
870 (setq got-identifier t)
871 nil))
872 t))
873 (if (eq (char-after) ?\()
874 (progn
875 (setq paren-depth (1+ paren-depth))
876 (forward-char))
877 (goto-char (match-end 1)))
878 (c-forward-syntactic-ws))
879
880 ;; If we didn't pass the identifier above already, do it now.
881 (unless got-identifier
882 (setq id-start (point))
883 (c-forward-name))
884 (setq id-end (point))
885
886 (/= id-end pos))
887
888 ;; Skip out of the parens surrounding the identifier.
889 (or (= paren-depth 0)
890 (c-safe (goto-char (scan-lists (point) 1 paren-depth))))
891
892 (<= (point) limit)
893
894 (progn
895 (when (looking-at c-decl-hangon-key)
896 (c-forward-keyword-clause 1))
897 (<= (point) limit))
898
899 ;; Search syntactically to the end of the declarator (";",
900 ;; ",", a closen paren, eob etc) or to the beginning of an
901 ;; initializer or function prototype ("=" or "\\s\(").
902 ;; Note that the open paren will match array specs in
903 ;; square brackets, and we treat them as initializers too.
904 (c-syntactic-re-search-forward
905 "[;,]\\|\\s)\\|\\'\\|\\(=\\|\\s(\\)" limit t t))
906
907 (setq next-pos (match-beginning 0)
908 id-face (if (and (eq (char-after next-pos) ?\()
909 (let (c-last-identifier-range)
910 (save-excursion
911 (goto-char next-pos)
912 (c-at-toplevel-p))))
913 'font-lock-function-name-face
914 'font-lock-variable-name-face)
915 got-init (and (match-beginning 1)
916 (char-after (match-beginning 1))))
917
918 (if types
919 ;; Register and fontify the identifer as a type.
920 (let ((c-promote-possible-types t))
921 (goto-char id-start)
922 (c-forward-type))
923 ;; Fontify the last symbol in the identifier if it isn't fontified
924 ;; already. The check is necessary only in certain cases where this
925 ;; function is used "sloppily", e.g. in `c-simple-decl-matchers'.
926 (when (and c-last-identifier-range
927 (not (get-text-property (car c-last-identifier-range)
928 'face)))
929 (c-put-font-lock-face (car c-last-identifier-range)
930 (cdr c-last-identifier-range)
931 id-face)))
932
933 (goto-char next-pos)
934 (setq pos nil)
935 (when list
936 ;; Jump past any initializer or function prototype to see if
937 ;; there's a ',' to continue at.
938
939 (cond ((eq id-face 'font-lock-function-name-face)
940 ;; Skip a parenthesized initializer (C++) or a function
941 ;; prototype.
942 (if (c-safe (c-forward-sexp 1) t)
943 (c-forward-syntactic-ws limit)
944 (goto-char limit)))
945
946 (got-init
947 ;; Skip an initializer expression. If we're at a '='
948 ;; then accept a brace list directly after it to cope
949 ;; with array initializers. Otherwise stop at braces
950 ;; to avoid going past full function and class blocks.
951 (and (if (and (eq got-init ?=)
952 (= (c-forward-token-2 1 nil limit) 0)
953 (looking-at "{"))
954 (c-safe (c-forward-sexp) t)
955 t)
956 ;; FIXME: Should look for c-decl-end markers here;
957 ;; we might go far into the following declarations
958 ;; in e.g. ObjC mode (see e.g. methods-4.m).
959 (c-syntactic-re-search-forward "[;,{]" limit 'move t)
960 (backward-char)))
961
962 (t (c-forward-syntactic-ws limit)))
963
964 ;; If a ',' is found we set pos to the next declarator and iterate.
965 (when (and (< (point) limit) (looking-at ","))
966 (c-put-char-property (point) 'c-type separator-prop)
967 (forward-char)
968 (c-forward-syntactic-ws limit)
969 (setq pos (point))))))
970 nil)
971
972 (defconst c-font-lock-maybe-decl-faces
973 ;; List of faces that might be put at the start of a type when
974 ;; `c-font-lock-declarations' runs. This needs to be evaluated to
975 ;; ensure that face name aliases in Emacs are resolved.
976 (list nil
977 font-lock-type-face
978 c-reference-face-name
979 font-lock-keyword-face))
980
981 (defun c-font-lock-declarations (limit)
982 ;; This function will be called from font-lock for a region bounded by POINT
983 ;; and LIMIT, as though it were to identify a keyword for
984 ;; font-lock-keyword-face. It always returns NIL to inhibit this and
985 ;; prevent a repeat invocation. See elisp/lispref page "Search-based
986 ;; Fontification".
987 ;;
988 ;; Fontify all the declarations, casts and labels from the point to LIMIT.
989 ;; Assumes that strings and comments have been fontified already.
990 ;;
991 ;; This function might do hidden buffer changes.
992
993 ;;(message "c-font-lock-declarations search from %s to %s" (point) limit)
994
995 (save-restriction
996 (let (;; The position where `c-find-decl-spots' stopped.
997 start-pos
998 ;; 'decl if we're in an arglist containing declarations (but
999 ;; if `c-recognize-paren-inits' is set it might also be an
1000 ;; initializer arglist), '<> if the arglist is of angle
1001 ;; bracket type, 'arglist if it's some other arglist, or nil
1002 ;; if not in an arglist at all.
1003 context
1004 ;; The position of the next token after the closing paren of
1005 ;; the last detected cast.
1006 last-cast-end
1007 ;; The result from `c-forward-decl-or-cast-1'.
1008 decl-or-cast
1009 ;; The maximum of the end positions of all the checked type
1010 ;; decl expressions in the successfully identified
1011 ;; declarations. The position might be either before or
1012 ;; after the syntactic whitespace following the last token
1013 ;; in the type decl expression.
1014 (max-type-decl-end 0)
1015 ;; Same as `max-type-decl-*', but used when we're before
1016 ;; `token-pos'.
1017 (max-type-decl-end-before-token 0)
1018 ;; Set according to the context to direct the heuristics for
1019 ;; recognizing C++ templates.
1020 c-restricted-<>-arglists
1021 ;; Turn on recording of identifier ranges in
1022 ;; `c-forward-decl-or-cast-1' and `c-forward-label' for
1023 ;; later fontification.
1024 (c-record-type-identifiers t)
1025 label-type
1026 c-record-ref-identifiers
1027 ;; Make `c-forward-type' calls mark up template arglists if
1028 ;; it finds any. That's necessary so that we later will
1029 ;; stop inside them to fontify types there.
1030 (c-parse-and-markup-<>-arglists t)
1031 ;; The font-lock package in Emacs is known to clobber
1032 ;; `parse-sexp-lookup-properties' (when it exists).
1033 (parse-sexp-lookup-properties
1034 (cc-eval-when-compile
1035 (boundp 'parse-sexp-lookup-properties))))
1036
1037 ;; Below we fontify a whole declaration even when it crosses the limit,
1038 ;; to avoid gaps when lazy-lock fontifies the file a screenful at a
1039 ;; time. That is however annoying during editing, e.g. the following is
1040 ;; a common situation while the first line is being written:
1041 ;;
1042 ;; my_variable
1043 ;; some_other_variable = 0;
1044 ;;
1045 ;; font-lock will put the limit at the beginning of the second line
1046 ;; here, and if we go past it we'll fontify "my_variable" as a type and
1047 ;; "some_other_variable" as an identifier, and the latter will not
1048 ;; correct itself until the second line is changed. To avoid that we
1049 ;; narrow to the limit if the region to fontify is a single line.
1050 (narrow-to-region
1051 (point-min)
1052 (if (<= limit (c-point 'bonl))
1053 (save-excursion
1054 ;; Narrow after any operator chars following the limit though,
1055 ;; since those characters can be useful in recognizing a
1056 ;; declaration (in particular the '{' that opens a function body
1057 ;; after the header).
1058 (goto-char limit)
1059 (skip-chars-forward c-nonsymbol-chars)
1060 (point))
1061 limit))
1062
1063 (c-find-decl-spots
1064 limit
1065 c-decl-start-re
1066 c-font-lock-maybe-decl-faces
1067
1068 (lambda (match-pos inside-macro)
1069 (setq start-pos (point))
1070 (when
1071 ;; The result of the form below is true when we don't recognize a
1072 ;; declaration or cast.
1073 (if (and (eq (get-text-property (point) 'face)
1074 'font-lock-keyword-face)
1075 (looking-at c-not-decl-init-keywords))
1076 ;; Don't do anything more if we're looking at a keyword that
1077 ;; can't start a declaration.
1078 t
1079
1080 ;; Set `context'. Look for "<" for the sake of C++-style template
1081 ;; arglists.
1082 (if (memq (char-before match-pos) '(?\( ?, ?\[ ?<))
1083
1084 ;; Find out the type of the arglist.
1085 (if (<= match-pos (point-min))
1086 (setq context 'arglist)
1087 (let ((type (c-get-char-property (1- match-pos) 'c-type)))
1088 (cond ((eq type 'c-decl-arg-start)
1089 ;; Got a cached hit in a declaration arglist.
1090 (setq context 'decl))
1091 ((or (eq type 'c-<>-arg-sep)
1092 (eq (char-before match-pos) ?<))
1093 ;; Inside an angle bracket arglist.
1094 (setq context '<>))
1095 (type
1096 ;; Got a cached hit in some other type of arglist.
1097 (setq context 'arglist))
1098 ((if inside-macro
1099 (< match-pos max-type-decl-end-before-token)
1100 (< match-pos max-type-decl-end))
1101 ;; The point is within the range of a previously
1102 ;; encountered type decl expression, so the arglist
1103 ;; is probably one that contains declarations.
1104 ;; However, if `c-recognize-paren-inits' is set it
1105 ;; might also be an initializer arglist.
1106 (setq context 'decl)
1107 ;; The result of this check is cached with a char
1108 ;; property on the match token, so that we can look
1109 ;; it up again when refontifying single lines in a
1110 ;; multiline declaration.
1111 (c-put-char-property (1- match-pos)
1112 'c-type 'c-decl-arg-start))
1113 (t
1114 (setq context 'arglist)))))
1115
1116 (setq context nil))
1117
1118 ;; If we're in a normal arglist context we don't want to
1119 ;; recognize commas in nested angle bracket arglists since
1120 ;; those commas could be part of our own arglist.
1121 (setq c-restricted-<>-arglists (and c-recognize-<>-arglists
1122 (eq context 'arglist))
1123
1124 ;; Now analyze the construct.
1125 decl-or-cast (c-forward-decl-or-cast-1
1126 match-pos context last-cast-end))
1127
1128 (if (not decl-or-cast)
1129 ;; False alarm. Return t to go on to the next check.
1130 t
1131
1132 (if (eq decl-or-cast 'cast)
1133 ;; Save the position after the previous cast so we can feed
1134 ;; it to `c-forward-decl-or-cast-1' in the next round. That
1135 ;; helps it discover cast chains like "(a) (b) c".
1136 (setq last-cast-end (point))
1137
1138 ;; Set `max-type-decl-end' or `max-type-decl-end-before-token'
1139 ;; under the assumption that we're after the first type decl
1140 ;; expression in the declaration now. That's not really true;
1141 ;; we could also be after a parenthesized initializer
1142 ;; expression in C++, but this is only used as a last resort
1143 ;; to slant ambiguous expression/declarations, and overall
1144 ;; it's worth the risk to occasionally fontify an expression
1145 ;; as a declaration in an initializer expression compared to
1146 ;; getting ambiguous things in normal function prototypes
1147 ;; fontified as expressions.
1148 (if inside-macro
1149 (when (> (point) max-type-decl-end-before-token)
1150 (setq max-type-decl-end-before-token (point)))
1151 (when (> (point) max-type-decl-end)
1152 (setq max-type-decl-end (point))))
1153
1154 ;; Back up to the type to fontify the declarator(s).
1155 (goto-char (car decl-or-cast))
1156
1157 (let ((decl-list
1158 (if context
1159 ;; Should normally not fontify a list of
1160 ;; declarators inside an arglist, but the first
1161 ;; argument in the ';' separated list of a "for"
1162 ;; statement is an exception.
1163 (when (eq (char-before match-pos) ?\()
1164 (save-excursion
1165 (goto-char (1- match-pos))
1166 (c-backward-syntactic-ws)
1167 (and (c-simple-skip-symbol-backward)
1168 (looking-at c-paren-stmt-key))))
1169 t)))
1170
1171 ;; Fix the `c-decl-id-start' or `c-decl-type-start' property
1172 ;; before the first declarator if it's a list.
1173 ;; `c-font-lock-declarators' handles the rest.
1174 (when decl-list
1175 (save-excursion
1176 (c-backward-syntactic-ws)
1177 (unless (bobp)
1178 (c-put-char-property (1- (point)) 'c-type
1179 (if (cdr decl-or-cast)
1180 'c-decl-type-start
1181 'c-decl-id-start)))))
1182
1183 (c-font-lock-declarators
1184 (point-max) decl-list (cdr decl-or-cast))))
1185
1186 ;; A cast or declaration has been successfully identified, so do
1187 ;; all the fontification of types and refs that's been recorded.
1188 (c-fontify-recorded-types-and-refs)
1189 nil))
1190
1191 ;; It was a false alarm. Check if we're in a label (or other
1192 ;; construct with `:' except bitfield) instead.
1193 (goto-char start-pos)
1194 (when (setq label-type (c-forward-label t match-pos nil))
1195 ;; Can't use `c-fontify-types-and-refs' here since we
1196 ;; use the label face at times.
1197 (cond ((eq label-type 'goto-target)
1198 (c-put-font-lock-face (caar c-record-ref-identifiers)
1199 (cdar c-record-ref-identifiers)
1200 c-label-face-name))
1201 ((eq label-type 'qt-1kwd-colon)
1202 (c-put-font-lock-face (caar c-record-ref-identifiers)
1203 (cdar c-record-ref-identifiers)
1204 'font-lock-keyword-face))
1205 ((eq label-type 'qt-2kwds-colon)
1206 (mapc
1207 (lambda (kwd)
1208 (c-put-font-lock-face (car kwd) (cdr kwd)
1209 'font-lock-keyword-face))
1210 c-record-ref-identifiers)))
1211 (setq c-record-ref-identifiers nil)
1212 ;; `c-forward-label' has probably added a `c-decl-end'
1213 ;; marker, so return t to `c-find-decl-spots' to signal
1214 ;; that.
1215 t))))
1216
1217 nil)))
1218
1219 (c-lang-defconst c-simple-decl-matchers
1220 "Simple font lock matchers for types and declarations. These are used
1221 on level 2 only and so aren't combined with `c-complex-decl-matchers'."
1222
1223 t `(;; Objective-C methods.
1224 ,@(when (c-major-mode-is 'objc-mode)
1225 `((,(c-lang-const c-opt-method-key)
1226 (,(byte-compile
1227 (lambda (limit)
1228 (let (;; The font-lock package in Emacs is known to clobber
1229 ;; `parse-sexp-lookup-properties' (when it exists).
1230 (parse-sexp-lookup-properties
1231 (cc-eval-when-compile
1232 (boundp 'parse-sexp-lookup-properties))))
1233 (save-restriction
1234 (narrow-to-region (point-min) limit)
1235 (c-font-lock-objc-method)))
1236 nil))
1237 (goto-char (match-end 1))))))
1238
1239 ;; Fontify all type names and the identifiers in the
1240 ;; declarations they might start. Use eval here since
1241 ;; `c-known-type-key' gets its value from
1242 ;; `*-font-lock-extra-types' on mode init.
1243 (eval . (list ,(c-make-font-lock-search-function
1244 'c-known-type-key
1245 '(1 'font-lock-type-face t)
1246 '((c-font-lock-declarators limit t nil)
1247 (save-match-data
1248 (goto-char (match-end 1))
1249 (c-forward-syntactic-ws))
1250 (goto-char (match-end 1))))))
1251
1252 ;; Fontify types preceded by `c-type-prefix-kwds' and the
1253 ;; identifiers in the declarations they might start.
1254 ,@(when (c-lang-const c-type-prefix-kwds)
1255 (let* ((prefix-re (c-make-keywords-re nil
1256 (c-lang-const c-type-prefix-kwds)))
1257 (type-match (+ 2
1258 (regexp-opt-depth prefix-re)
1259 (c-lang-const c-simple-ws-depth))))
1260 `((,(c-make-font-lock-search-function
1261 (concat "\\<\\(" prefix-re "\\)" ; 1
1262 (c-lang-const c-simple-ws) "+"
1263 (concat "\\(" ; 2 + prefix-re + c-simple-ws
1264 (c-lang-const c-symbol-key)
1265 "\\)"))
1266 `(,type-match
1267 'font-lock-type-face t)
1268 `((c-font-lock-declarators limit t nil)
1269 (save-match-data
1270 (goto-char (match-end ,type-match))
1271 (c-forward-syntactic-ws))
1272 (goto-char (match-end ,type-match))))))))
1273
1274 ;; Fontify special declarations that lacks a type.
1275 ,@(when (c-lang-const c-typeless-decl-kwds)
1276 `((,(c-make-font-lock-search-function
1277 (concat "\\<\\("
1278 (regexp-opt (c-lang-const c-typeless-decl-kwds))
1279 "\\)\\>")
1280 '((c-font-lock-declarators limit t nil)
1281 (save-match-data
1282 (goto-char (match-end 1))
1283 (c-forward-syntactic-ws))
1284 (goto-char (match-end 1)))))))
1285
1286 ;; Fontify generic colon labels in languages that support them.
1287 ,@(when (c-lang-const c-recognize-colon-labels)
1288 `(c-font-lock-labels))))
1289
1290 (c-lang-defconst c-complex-decl-matchers
1291 "Complex font lock matchers for types and declarations. Used on level
1292 3 and higher."
1293
1294 ;; Note: This code in this form dumps a number of funtions into the
1295 ;; resulting constant, `c-matchers-3'. At run time, font lock will call
1296 ;; each of them as a "FUNCTION" (see Elisp page "Search-based
1297 ;; Fontification"). The font lock region is delimited by POINT and the
1298 ;; single parameter, LIMIT. Each of these functions returns NIL (thus
1299 ;; inhibiting spurious font-lock-keyword-face highlighting and another
1300 ;; call).
1301
1302 t `(;; Initialize some things before the search functions below.
1303 c-font-lock-complex-decl-prepare
1304
1305 ,@(if (c-major-mode-is 'objc-mode)
1306 ;; Fontify method declarations in Objective-C, but first
1307 ;; we have to put the `c-decl-end' `c-type' property on
1308 ;; all the @-style directives that haven't been handled in
1309 ;; `c-basic-matchers-before'.
1310 `(,(c-make-font-lock-search-function
1311 (c-make-keywords-re t
1312 ;; Exclude "@class" since that directive ends with a
1313 ;; semicolon anyway.
1314 (delete "@class"
1315 (append (c-lang-const c-protection-kwds)
1316 (c-lang-const c-other-decl-kwds)
1317 nil)))
1318 '((c-put-char-property (1- (match-end 1))
1319 'c-type 'c-decl-end)))
1320 c-font-lock-objc-methods))
1321
1322 ;; Fontify all declarations, casts and normal labels.
1323 c-font-lock-declarations
1324
1325 ;; Fontify angle bracket arglists like templates in C++.
1326 ,@(when (c-lang-const c-recognize-<>-arglists)
1327 `(c-font-lock-<>-arglists))
1328
1329 ;; The first two rules here mostly find occurrences that
1330 ;; `c-font-lock-declarations' has found already, but not
1331 ;; declarations containing blocks in the type (see note below).
1332 ;; It's also useful to fontify these everywhere to show e.g. when
1333 ;; a type keyword is accidentally used as an identifier.
1334
1335 ;; Fontify basic types.
1336 ,(let ((re (c-make-keywords-re nil
1337 (c-lang-const c-primitive-type-kwds))))
1338 (if (c-major-mode-is 'pike-mode)
1339 ;; No symbol is a keyword after "->" in Pike.
1340 `(,(concat "\\(\\=.?\\|[^>]\\|[^-]>\\)"
1341 "\\<\\(" re "\\)\\>")
1342 2 font-lock-type-face)
1343 `(,(concat "\\<\\(" re "\\)\\>")
1344 1 'font-lock-type-face)))
1345
1346 ;; Fontify types preceded by `c-type-prefix-kwds'.
1347 ,@(when (c-lang-const c-type-prefix-kwds)
1348 `((,(byte-compile
1349 `(lambda (limit)
1350 (c-fontify-types-and-refs
1351 ((c-promote-possible-types t)
1352 ;; The font-lock package in Emacs is known to clobber
1353 ;; `parse-sexp-lookup-properties' (when it exists).
1354 (parse-sexp-lookup-properties
1355 (cc-eval-when-compile
1356 (boundp 'parse-sexp-lookup-properties))))
1357 (save-restriction
1358 ;; Narrow to avoid going past the limit in
1359 ;; `c-forward-type'.
1360 (narrow-to-region (point) limit)
1361 (while (re-search-forward
1362 ,(concat "\\<\\("
1363 (c-make-keywords-re nil
1364 (c-lang-const c-type-prefix-kwds))
1365 "\\)\\>")
1366 limit t)
1367 (unless (c-skip-comments-and-strings limit)
1368 (c-forward-syntactic-ws)
1369 ;; Handle prefix declaration specifiers.
1370 (when (looking-at c-prefix-spec-kwds-re)
1371 (c-forward-keyword-clause 1))
1372 ,(if (c-major-mode-is 'c++-mode)
1373 `(when (and (c-forward-type)
1374 (eq (char-after) ?=))
1375 ;; In C++ we additionally check for a "class
1376 ;; X = Y" construct which is used in
1377 ;; templates, to fontify Y as a type.
1378 (forward-char)
1379 (c-forward-syntactic-ws)
1380 (c-forward-type))
1381 `(c-forward-type))
1382 )))))))))
1383
1384 ;; Fontify symbols after closing braces as declaration
1385 ;; identifiers under the assumption that they are part of
1386 ;; declarations like "class Foo { ... } foo;". It's too
1387 ;; expensive to check this accurately by skipping past the
1388 ;; brace block, so we use the heuristic that it's such a
1389 ;; declaration if the first identifier is on the same line as
1390 ;; the closing brace. `c-font-lock-declarations' will later
1391 ;; override it if it turns out to be an new declaration, but
1392 ;; it will be wrong if it's an expression (see the test
1393 ;; decls-8.cc).
1394 ,@(when (c-lang-const c-opt-block-decls-with-vars-key)
1395 `((,(c-make-font-lock-search-function
1396 (concat "}"
1397 (c-lang-const c-single-line-syntactic-ws)
1398 "\\(" ; 1 + c-single-line-syntactic-ws-depth
1399 (c-lang-const c-type-decl-prefix-key)
1400 "\\|"
1401 (c-lang-const c-symbol-key)
1402 "\\)")
1403 `((c-font-lock-declarators limit t nil)
1404 (progn
1405 (c-put-char-property (match-beginning 0) 'c-type
1406 'c-decl-id-start)
1407 (goto-char (match-beginning
1408 ,(1+ (c-lang-const
1409 c-single-line-syntactic-ws-depth)))))
1410 (goto-char (match-end 0)))))))
1411
1412 ;; Fontify the type in C++ "new" expressions.
1413 ,@(when (c-major-mode-is 'c++-mode)
1414 ;; This pattern is a probably a "(MATCHER . ANCHORED-HIGHLIGHTER)"
1415 ;; (see Elisp page "Search-based Fontification").
1416 `(("\\<new\\>"
1417 (c-font-lock-c++-new))))
1418 ))
1419
1420 (defun c-font-lock-labels (limit)
1421 ;; Fontify all statement labels from the point to LIMIT. Assumes
1422 ;; that strings and comments have been fontified already. Nil is
1423 ;; always returned.
1424 ;;
1425 ;; Note: This function is only used on decoration level 2; this is
1426 ;; taken care of directly by the gargantuan
1427 ;; `c-font-lock-declarations' on higher levels.
1428 ;;
1429 ;; This function might do hidden buffer changes.
1430
1431 (let (continue-pos id-start
1432 ;; The font-lock package in Emacs is known to clobber
1433 ;; `parse-sexp-lookup-properties' (when it exists).
1434 (parse-sexp-lookup-properties
1435 (cc-eval-when-compile
1436 (boundp 'parse-sexp-lookup-properties))))
1437
1438 (while (re-search-forward ":[^:]" limit t)
1439 (setq continue-pos (point))
1440 (goto-char (match-beginning 0))
1441 (unless (c-skip-comments-and-strings limit)
1442
1443 (c-backward-syntactic-ws)
1444 (and (setq id-start (c-on-identifier))
1445
1446 (not (get-text-property id-start 'face))
1447
1448 (progn
1449 (goto-char id-start)
1450 (c-backward-syntactic-ws)
1451 (or
1452 ;; Check for a char that precedes a statement.
1453 (memq (char-before) '(?\} ?\{ ?\;))
1454 ;; Check for a preceding label. We exploit the font
1455 ;; locking made earlier by this function.
1456 (and (eq (char-before) ?:)
1457 (progn
1458 (backward-char)
1459 (c-backward-syntactic-ws)
1460 (not (bobp)))
1461 (eq (get-text-property (1- (point)) 'face)
1462 c-label-face-name))
1463 ;; Check for a keyword that precedes a statement.
1464 (c-after-conditional)))
1465
1466 (progn
1467 ;; Got a label.
1468 (goto-char id-start)
1469 (looking-at c-symbol-key)
1470 (c-put-font-lock-face (match-beginning 0) (match-end 0)
1471 c-label-face-name)))
1472
1473 (goto-char continue-pos))))
1474 nil)
1475
1476 (c-lang-defconst c-basic-matchers-after
1477 "Font lock matchers for various things that should be fontified after
1478 generic casts and declarations are fontified. Used on level 2 and
1479 higher."
1480
1481 t `(;; Fontify the identifiers inside enum lists. (The enum type
1482 ;; name is handled by `c-simple-decl-matchers' or
1483 ;; `c-complex-decl-matchers' below.
1484 ,@(when (c-lang-const c-brace-id-list-kwds)
1485 `((,(c-make-font-lock-search-function
1486 (concat
1487 "\\<\\("
1488 (c-make-keywords-re nil (c-lang-const c-brace-id-list-kwds))
1489 "\\)\\>"
1490 ;; Disallow various common punctuation chars that can't come
1491 ;; before the '{' of the enum list, to avoid searching too far.
1492 "[^\]\[{}();,/#=]*"
1493 "{")
1494 '((c-font-lock-declarators limit t nil)
1495 (save-match-data
1496 (goto-char (match-end 0))
1497 (c-put-char-property (1- (point)) 'c-type
1498 'c-decl-id-start)
1499 (c-forward-syntactic-ws))
1500 (goto-char (match-end 0)))))))
1501
1502 ;; Fontify labels after goto etc.
1503 ,@(when (c-lang-const c-before-label-kwds)
1504 `(;; (Got three different interpretation levels here,
1505 ;; which makes it a bit complicated: 1) The backquote
1506 ;; stuff is expanded when compiled or loaded, 2) the
1507 ;; eval form is evaluated at font-lock setup (to
1508 ;; substitute c-label-face-name correctly), and 3) the
1509 ;; resulting structure is interpreted during
1510 ;; fontification.)
1511 (eval
1512 . ,(let* ((c-before-label-re
1513 (c-make-keywords-re nil
1514 (c-lang-const c-before-label-kwds))))
1515 `(list
1516 ,(concat "\\<\\(" c-before-label-re "\\)\\>"
1517 "\\s *"
1518 "\\(" ; identifier-offset
1519 (c-lang-const c-symbol-key)
1520 "\\)")
1521 (list ,(+ (regexp-opt-depth c-before-label-re) 2)
1522 c-label-face-name nil t))))))
1523
1524 ;; Fontify the clauses after various keywords.
1525 ,@(when (or (c-lang-const c-type-list-kwds)
1526 (c-lang-const c-ref-list-kwds)
1527 (c-lang-const c-colon-type-list-kwds)
1528 (c-lang-const c-paren-type-kwds))
1529 `((,(c-make-font-lock-search-function
1530 (concat "\\<\\("
1531 (c-make-keywords-re nil
1532 (append (c-lang-const c-type-list-kwds)
1533 (c-lang-const c-ref-list-kwds)
1534 (c-lang-const c-colon-type-list-kwds)
1535 (c-lang-const c-paren-type-kwds)))
1536 "\\)\\>")
1537 '((c-fontify-types-and-refs ((c-promote-possible-types t))
1538 (c-forward-keyword-clause 1)
1539 (if (> (point) limit) (goto-char limit))))))))
1540 ))
1541
1542 (c-lang-defconst c-matchers-1
1543 t (c-lang-const c-cpp-matchers))
1544
1545 (c-lang-defconst c-matchers-2
1546 t (append (c-lang-const c-matchers-1)
1547 (c-lang-const c-basic-matchers-before)
1548 (c-lang-const c-simple-decl-matchers)
1549 (c-lang-const c-basic-matchers-after)))
1550
1551 (c-lang-defconst c-matchers-3
1552 t (append (c-lang-const c-matchers-1)
1553 (c-lang-const c-basic-matchers-before)
1554 (c-lang-const c-complex-decl-matchers)
1555 (c-lang-const c-basic-matchers-after)))
1556
1557 (defun c-compose-keywords-list (base-list)
1558 ;; Incorporate the font lock keyword lists according to
1559 ;; `c-doc-comment-style' on the given keyword list and return it.
1560 ;; This is used in the function bindings of the
1561 ;; `*-font-lock-keywords-*' symbols since we have to build the list
1562 ;; when font-lock is initialized.
1563
1564 (unless (memq c-doc-face-name c-literal-faces)
1565 (setq c-literal-faces (cons c-doc-face-name c-literal-faces)))
1566
1567 (let* ((doc-keywords
1568 (if (consp (car-safe c-doc-comment-style))
1569 (cdr-safe (or (assq c-buffer-is-cc-mode c-doc-comment-style)
1570 (assq 'other c-doc-comment-style)))
1571 c-doc-comment-style))
1572 (list (nconc (apply 'nconc
1573 (mapcar
1574 (lambda (doc-style)
1575 (let ((sym (intern
1576 (concat (symbol-name doc-style)
1577 "-font-lock-keywords"))))
1578 (cond ((fboundp sym)
1579 (funcall sym))
1580 ((boundp sym)
1581 (append (eval sym) nil)))))
1582 (if (listp doc-keywords)
1583 doc-keywords
1584 (list doc-keywords))))
1585 base-list)))
1586
1587 ;; Kludge: If `c-font-lock-complex-decl-prepare' is on the list we
1588 ;; move it first since the doc comment font lockers might add
1589 ;; `c-type' text properties, so they have to be cleared before that.
1590 (when (memq 'c-font-lock-complex-decl-prepare list)
1591 (setq list (cons 'c-font-lock-complex-decl-prepare
1592 (delq 'c-font-lock-complex-decl-prepare
1593 (append list nil)))))
1594
1595 list))
1596
1597 (defun c-override-default-keywords (def-var)
1598 ;; This is used to override the value on a `*-font-lock-keywords'
1599 ;; variable only if it's nil or has the same value as one of the
1600 ;; `*-font-lock-keywords-*' variables. Older font-lock packages
1601 ;; define a default value for `*-font-lock-keywords' which we want
1602 ;; to override, but we should otoh avoid clobbering a user setting.
1603 ;; This heuristic for that isn't perfect, but I can't think of any
1604 ;; better. /mast
1605 (when (and (boundp def-var)
1606 (memq (symbol-value def-var)
1607 (cons nil
1608 (mapcar
1609 (lambda (suffix)
1610 (let ((sym (intern (concat (symbol-name def-var)
1611 suffix))))
1612 (and (boundp sym) (symbol-value sym))))
1613 '("-1" "-2" "-3")))))
1614 ;; The overriding is done by unbinding the variable so that the normal
1615 ;; defvar will install its default value later on.
1616 (makunbound def-var)))
1617
1618 \f
1619 ;;; C.
1620
1621 (c-override-default-keywords 'c-font-lock-keywords)
1622
1623 (defconst c-font-lock-keywords-1 (c-lang-const c-matchers-1 c)
1624 "Minimal font locking for C mode.
1625 Fontifies only preprocessor directives (in addition to the syntactic
1626 fontification of strings and comments).")
1627
1628 (defconst c-font-lock-keywords-2 (c-lang-const c-matchers-2 c)
1629 "Fast normal font locking for C mode.
1630 In addition to `c-font-lock-keywords-1', this adds fontification of
1631 keywords, simple types, declarations that are easy to recognize, the
1632 user defined types on `c-font-lock-extra-types', and the doc comment
1633 styles specified by `c-doc-comment-style'.")
1634
1635 (defconst c-font-lock-keywords-3 (c-lang-const c-matchers-3 c)
1636 "Accurate normal font locking for C mode.
1637 Like `c-font-lock-keywords-2' but detects declarations in a more
1638 accurate way that works in most cases for arbitrary types without the
1639 need for `c-font-lock-extra-types'.")
1640
1641 (defvar c-font-lock-keywords c-font-lock-keywords-3
1642 "Default expressions to highlight in C mode.")
1643
1644 (defun c-font-lock-keywords-2 ()
1645 (c-compose-keywords-list c-font-lock-keywords-2))
1646 (defun c-font-lock-keywords-3 ()
1647 (c-compose-keywords-list c-font-lock-keywords-3))
1648 (defun c-font-lock-keywords ()
1649 (c-compose-keywords-list c-font-lock-keywords))
1650
1651 \f
1652 ;;; C++.
1653
1654 (defun c-font-lock-c++-new (limit)
1655 ;; Assuming point is after a "new" word, check that it isn't inside
1656 ;; a string or comment, and if so try to fontify the type in the
1657 ;; allocation expression. Nil is always returned.
1658 ;;
1659 ;; As usual, C++ takes the prize in coming up with a hard to parse
1660 ;; syntax. :P
1661 ;;
1662 ;; This function might do hidden buffer changes.
1663
1664 (unless (c-skip-comments-and-strings limit)
1665 (save-excursion
1666 (catch 'false-alarm
1667 ;; A "new" keyword is followed by one to three expressions, where
1668 ;; the type is the middle one, and the only required part.
1669 (let (expr1-pos expr2-pos
1670 ;; Enable recording of identifier ranges in `c-forward-type'
1671 ;; etc for later fontification. Not using
1672 ;; `c-fontify-types-and-refs' here since the ranges should
1673 ;; be fontified selectively only when an allocation
1674 ;; expression is successfully recognized.
1675 (c-record-type-identifiers t)
1676 c-record-ref-identifiers
1677 ;; The font-lock package in Emacs is known to clobber
1678 ;; `parse-sexp-lookup-properties' (when it exists).
1679 (parse-sexp-lookup-properties
1680 (cc-eval-when-compile
1681 (boundp 'parse-sexp-lookup-properties))))
1682 (c-forward-syntactic-ws)
1683
1684 ;; The first placement arglist is always parenthesized, if it
1685 ;; exists.
1686 (when (eq (char-after) ?\()
1687 (setq expr1-pos (1+ (point)))
1688 (condition-case nil
1689 (c-forward-sexp)
1690 (scan-error (throw 'false-alarm t)))
1691 (c-forward-syntactic-ws))
1692
1693 ;; The second expression is either a type followed by some "*" or
1694 ;; "[...]" or similar, or a parenthesized type followed by a full
1695 ;; identifierless declarator.
1696 (setq expr2-pos (1+ (point)))
1697 (cond ((eq (char-after) ?\())
1698 ((let ((c-promote-possible-types t))
1699 (c-forward-type)))
1700 (t (setq expr2-pos nil)))
1701
1702 (when expr1-pos
1703 (cond
1704 ((not expr2-pos)
1705 ;; No second expression, so the first has to be a
1706 ;; parenthesized type.
1707 (goto-char expr1-pos)
1708 (let ((c-promote-possible-types t))
1709 (c-forward-type)))
1710
1711 ((eq (char-before expr2-pos) ?\()
1712 ;; Got two parenthesized expressions, so we have to look
1713 ;; closer at them to decide which is the type. No need to
1714 ;; handle `c-record-ref-identifiers' since all references
1715 ;; has already been handled by other fontification rules.
1716 (let (expr1-res expr2-res)
1717
1718 (goto-char expr1-pos)
1719 (when (setq expr1-res (c-forward-type))
1720 (unless (looking-at
1721 (cc-eval-when-compile
1722 (concat (c-lang-const c-symbol-start c++)
1723 "\\|[*:\)\[]")))
1724 ;; There's something after the would-be type that
1725 ;; can't be there, so this is a placement arglist.
1726 (setq expr1-res nil)))
1727
1728 (goto-char expr2-pos)
1729 (when (setq expr2-res (c-forward-type))
1730 (unless (looking-at
1731 (cc-eval-when-compile
1732 (concat (c-lang-const c-symbol-start c++)
1733 "\\|[*:\)\[]")))
1734 ;; There's something after the would-be type that can't
1735 ;; be there, so this is an initialization expression.
1736 (setq expr2-res nil))
1737 (when (and (c-go-up-list-forward)
1738 (progn (c-forward-syntactic-ws)
1739 (eq (char-after) ?\()))
1740 ;; If there's a third initialization expression
1741 ;; then the second one is the type, so demote the
1742 ;; first match.
1743 (setq expr1-res nil)))
1744
1745 ;; We fontify the most likely type, with a preference for
1746 ;; the first argument since a placement arglist is more
1747 ;; unusual than an initializer.
1748 (cond ((memq expr1-res '(t known prefix)))
1749 ((memq expr2-res '(t known prefix)))
1750 ((eq expr1-res 'found)
1751 (let ((c-promote-possible-types t))
1752 (goto-char expr1-pos)
1753 (c-forward-type)))
1754 ((eq expr2-res 'found)
1755 (let ((c-promote-possible-types t))
1756 (goto-char expr2-pos)
1757 (c-forward-type)))
1758 ((and (eq expr1-res 'maybe) (not expr2-res))
1759 (let ((c-promote-possible-types t))
1760 (goto-char expr1-pos)
1761 (c-forward-type)))
1762 ((and (not expr1-res) (eq expr2-res 'maybe))
1763 (let ((c-promote-possible-types t))
1764 (goto-char expr2-pos)
1765 (c-forward-type)))
1766 ;; If both type matches are 'maybe then we're
1767 ;; too uncertain to promote either of them.
1768 )))))
1769
1770 ;; Fontify the type that now is recorded in
1771 ;; `c-record-type-identifiers', if any.
1772 (c-fontify-recorded-types-and-refs)))))
1773 nil)
1774
1775 (c-override-default-keywords 'c++-font-lock-keywords)
1776
1777 (defconst c++-font-lock-keywords-1 (c-lang-const c-matchers-1 c++)
1778 "Minimal font locking for C++ mode.
1779 Fontifies only preprocessor directives (in addition to the syntactic
1780 fontification of strings and comments).")
1781
1782 (defconst c++-font-lock-keywords-2 (c-lang-const c-matchers-2 c++)
1783 "Fast normal font locking for C++ mode.
1784 In addition to `c++-font-lock-keywords-1', this adds fontification of
1785 keywords, simple types, declarations that are easy to recognize, the
1786 user defined types on `c++-font-lock-extra-types', and the doc comment
1787 styles specified by `c-doc-comment-style'.")
1788
1789 (defconst c++-font-lock-keywords-3 (c-lang-const c-matchers-3 c++)
1790 "Accurate normal font locking for C++ mode.
1791 Like `c++-font-lock-keywords-2' but detects declarations in a more
1792 accurate way that works in most cases for arbitrary types without the
1793 need for `c++-font-lock-extra-types'.")
1794
1795 (defvar c++-font-lock-keywords c++-font-lock-keywords-3
1796 "Default expressions to highlight in C++ mode.")
1797
1798 (defun c++-font-lock-keywords-2 ()
1799 (c-compose-keywords-list c++-font-lock-keywords-2))
1800 (defun c++-font-lock-keywords-3 ()
1801 (c-compose-keywords-list c++-font-lock-keywords-3))
1802 (defun c++-font-lock-keywords ()
1803 (c-compose-keywords-list c++-font-lock-keywords))
1804
1805 \f
1806 ;;; Objective-C.
1807
1808 (defun c-font-lock-objc-method ()
1809 ;; Assuming the point is after the + or - that starts an Objective-C
1810 ;; method declaration, fontify it. This must be done before normal
1811 ;; casts, declarations and labels are fontified since they will get
1812 ;; false matches in these things.
1813 ;;
1814 ;; This function might do hidden buffer changes.
1815
1816 (c-fontify-types-and-refs
1817 ((first t)
1818 (c-promote-possible-types t))
1819
1820 (while (and
1821 (progn
1822 (c-forward-syntactic-ws)
1823
1824 ;; An optional method type.
1825 (if (eq (char-after) ?\()
1826 (progn
1827 (forward-char)
1828 (c-forward-syntactic-ws)
1829 (c-forward-type)
1830 (prog1 (c-go-up-list-forward)
1831 (c-forward-syntactic-ws)))
1832 t))
1833
1834 ;; The name. The first time it's the first part of
1835 ;; the function name, the rest of the time it's an
1836 ;; argument name.
1837 (looking-at c-symbol-key)
1838 (progn
1839 (goto-char (match-end 0))
1840 (c-put-font-lock-face (match-beginning 0)
1841 (point)
1842 (if first
1843 'font-lock-function-name-face
1844 'font-lock-variable-name-face))
1845 (c-forward-syntactic-ws)
1846
1847 ;; Another optional part of the function name.
1848 (when (looking-at c-symbol-key)
1849 (goto-char (match-end 0))
1850 (c-put-font-lock-face (match-beginning 0)
1851 (point)
1852 'font-lock-function-name-face)
1853 (c-forward-syntactic-ws))
1854
1855 ;; There's another argument if a colon follows.
1856 (eq (char-after) ?:)))
1857 (forward-char)
1858 (setq first nil))))
1859
1860 (defun c-font-lock-objc-methods (limit)
1861 ;; Fontify method declarations in Objective-C. Nil is always
1862 ;; returned.
1863 ;;
1864 ;; This function might do hidden buffer changes.
1865
1866 (let (;; The font-lock package in Emacs is known to clobber
1867 ;; `parse-sexp-lookup-properties' (when it exists).
1868 (parse-sexp-lookup-properties
1869 (cc-eval-when-compile
1870 (boundp 'parse-sexp-lookup-properties))))
1871
1872 (c-find-decl-spots
1873 limit
1874 "[-+]"
1875 nil
1876 (lambda (match-pos inside-macro)
1877 (forward-char)
1878 (c-font-lock-objc-method))))
1879 nil)
1880
1881 (c-override-default-keywords 'objc-font-lock-keywords)
1882
1883 (defconst objc-font-lock-keywords-1 (c-lang-const c-matchers-1 objc)
1884 "Minimal font locking for Objective-C mode.
1885 Fontifies only compiler directives (in addition to the syntactic
1886 fontification of strings and comments).")
1887
1888 (defconst objc-font-lock-keywords-2 (c-lang-const c-matchers-2 objc)
1889 "Fast normal font locking for Objective-C mode.
1890 In addition to `objc-font-lock-keywords-1', this adds fontification of
1891 keywords, simple types, declarations that are easy to recognize, the
1892 user defined types on `objc-font-lock-extra-types', and the doc
1893 comment styles specified by `c-doc-comment-style'.")
1894
1895 (defconst objc-font-lock-keywords-3 (c-lang-const c-matchers-3 objc)
1896 "Accurate normal font locking for Objective-C mode.
1897 Like `objc-font-lock-keywords-2' but detects declarations in a more
1898 accurate way that works in most cases for arbitrary types without the
1899 need for `objc-font-lock-extra-types'.")
1900
1901 (defvar objc-font-lock-keywords objc-font-lock-keywords-3
1902 "Default expressions to highlight in Objective-C mode.")
1903
1904 (defun objc-font-lock-keywords-2 ()
1905 (c-compose-keywords-list objc-font-lock-keywords-2))
1906 (defun objc-font-lock-keywords-3 ()
1907 (c-compose-keywords-list objc-font-lock-keywords-3))
1908 (defun objc-font-lock-keywords ()
1909 (c-compose-keywords-list objc-font-lock-keywords))
1910
1911 ;; Kludge to override the default value that
1912 ;; `objc-font-lock-extra-types' might have gotten from the font-lock
1913 ;; package. The value replaced here isn't relevant now anyway since
1914 ;; those types are builtin and therefore listed directly in
1915 ;; `c-primitive-type-kwds'.
1916 (when (equal (sort (append objc-font-lock-extra-types nil) 'string-lessp)
1917 '("BOOL" "Class" "IMP" "SEL"))
1918 (setq objc-font-lock-extra-types
1919 (cc-eval-when-compile (list (concat "[" c-upper "]\\sw*")))))
1920
1921 \f
1922 ;;; Java.
1923
1924 (c-override-default-keywords 'java-font-lock-keywords)
1925
1926 (defconst java-font-lock-keywords-1 (c-lang-const c-matchers-1 java)
1927 "Minimal font locking for Java mode.
1928 Fontifies nothing except the syntactic fontification of strings and
1929 comments.")
1930
1931 (defconst java-font-lock-keywords-2 (c-lang-const c-matchers-2 java)
1932 "Fast normal font locking for Java mode.
1933 In addition to `java-font-lock-keywords-1', this adds fontification of
1934 keywords, simple types, declarations that are easy to recognize, the
1935 user defined types on `java-font-lock-extra-types', and the doc
1936 comment styles specified by `c-doc-comment-style'.")
1937
1938 (defconst java-font-lock-keywords-3 (c-lang-const c-matchers-3 java)
1939 "Accurate normal font locking for Java mode.
1940 Like `java-font-lock-keywords-2' but detects declarations in a more
1941 accurate way that works in most cases for arbitrary types without the
1942 need for `java-font-lock-extra-types'.")
1943
1944 (defvar java-font-lock-keywords java-font-lock-keywords-3
1945 "Default expressions to highlight in Java mode.")
1946
1947 (defun java-font-lock-keywords-2 ()
1948 (c-compose-keywords-list java-font-lock-keywords-2))
1949 (defun java-font-lock-keywords-3 ()
1950 (c-compose-keywords-list java-font-lock-keywords-3))
1951 (defun java-font-lock-keywords ()
1952 (c-compose-keywords-list java-font-lock-keywords))
1953
1954 \f
1955 ;;; CORBA IDL.
1956
1957 (c-override-default-keywords 'idl-font-lock-keywords)
1958
1959 (defconst idl-font-lock-keywords-1 (c-lang-const c-matchers-1 idl)
1960 "Minimal font locking for CORBA IDL mode.
1961 Fontifies nothing except the syntactic fontification of strings and
1962 comments.")
1963
1964 (defconst idl-font-lock-keywords-2 (c-lang-const c-matchers-2 idl)
1965 "Fast normal font locking for CORBA IDL mode.
1966 In addition to `idl-font-lock-keywords-1', this adds fontification of
1967 keywords, simple types, declarations that are easy to recognize, the
1968 user defined types on `idl-font-lock-extra-types', and the doc comment
1969 styles specified by `c-doc-comment-style'.")
1970
1971 (defconst idl-font-lock-keywords-3 (c-lang-const c-matchers-3 idl)
1972 "Accurate normal font locking for CORBA IDL mode.
1973 Like `idl-font-lock-keywords-2' but detects declarations in a more
1974 accurate way that works in most cases for arbitrary types without the
1975 need for `idl-font-lock-extra-types'.")
1976
1977 (defvar idl-font-lock-keywords idl-font-lock-keywords-3
1978 "Default expressions to highlight in CORBA IDL mode.")
1979
1980 (defun idl-font-lock-keywords-2 ()
1981 (c-compose-keywords-list idl-font-lock-keywords-2))
1982 (defun idl-font-lock-keywords-3 ()
1983 (c-compose-keywords-list idl-font-lock-keywords-3))
1984 (defun idl-font-lock-keywords ()
1985 (c-compose-keywords-list idl-font-lock-keywords))
1986
1987 \f
1988 ;;; Pike.
1989
1990 (c-override-default-keywords 'pike-font-lock-keywords)
1991
1992 (defconst pike-font-lock-keywords-1 (c-lang-const c-matchers-1 pike)
1993 "Minimal font locking for Pike mode.
1994 Fontifies only preprocessor directives (in addition to the syntactic
1995 fontification of strings and comments).")
1996
1997 (defconst pike-font-lock-keywords-2 (c-lang-const c-matchers-2 pike)
1998 "Fast normal font locking for Pike mode.
1999 In addition to `pike-font-lock-keywords-1', this adds fontification of
2000 keywords, simple types, declarations that are easy to recognize, the
2001 user defined types on `pike-font-lock-extra-types', and the doc
2002 comment styles specified by `c-doc-comment-style'.")
2003
2004 (defconst pike-font-lock-keywords-3 (c-lang-const c-matchers-3 pike)
2005 "Accurate normal font locking for Pike mode.
2006 Like `pike-font-lock-keywords-2' but detects declarations in a more
2007 accurate way that works in most cases for arbitrary types without the
2008 need for `pike-font-lock-extra-types'.")
2009
2010 (defvar pike-font-lock-keywords pike-font-lock-keywords-3
2011 "Default expressions to highlight in Pike mode.")
2012
2013 (defun pike-font-lock-keywords-2 ()
2014 (c-compose-keywords-list pike-font-lock-keywords-2))
2015 (defun pike-font-lock-keywords-3 ()
2016 (c-compose-keywords-list pike-font-lock-keywords-3))
2017 (defun pike-font-lock-keywords ()
2018 (c-compose-keywords-list pike-font-lock-keywords))
2019
2020 \f
2021 ;;; Doc comments.
2022
2023 (defun c-font-lock-doc-comments (prefix limit keywords)
2024 ;; Fontify the comments between the point and LIMIT whose start
2025 ;; matches PREFIX with `c-doc-face-name'. Assumes comments have been
2026 ;; fontified with `font-lock-comment-face' already. nil is always
2027 ;; returned.
2028 ;;
2029 ;; After the fontification of a matching comment, fontification
2030 ;; according to KEYWORDS is applied inside it. It's a list like
2031 ;; `font-lock-keywords' except that anchored matches and eval
2032 ;; clauses aren't supported and that some abbreviated forms can't be
2033 ;; used. The buffer is narrowed to the comment while KEYWORDS is
2034 ;; applied; leading comment starters are included but trailing
2035 ;; comment enders for block comment are not.
2036 ;;
2037 ;; Note that faces added through KEYWORDS should never replace the
2038 ;; existing `c-doc-face-name' face since the existence of that face
2039 ;; is used as a flag in other code to skip comments.
2040 ;;
2041 ;; This function might do hidden buffer changes.
2042
2043 (let (comment-beg region-beg)
2044 (if (eq (get-text-property (point) 'face)
2045 'font-lock-comment-face)
2046 ;; Handle the case when the fontified region starts inside a
2047 ;; comment.
2048 (let ((range (c-literal-limits)))
2049 (setq region-beg (point))
2050 (when range
2051 (goto-char (car range)))
2052 (when (looking-at prefix)
2053 (setq comment-beg (point)))))
2054
2055 (while (or
2056 comment-beg
2057
2058 ;; Search for the prefix until a match is found at the start
2059 ;; of a comment.
2060 (while (when (re-search-forward prefix limit t)
2061 (setq comment-beg (match-beginning 0))
2062 (or (not (c-got-face-at comment-beg
2063 c-literal-faces))
2064 (and (/= comment-beg (point-min))
2065 (c-got-face-at (1- comment-beg)
2066 c-literal-faces))))
2067 (setq comment-beg nil))
2068 (setq region-beg comment-beg))
2069
2070 (if (eq (elt (parse-partial-sexp comment-beg (+ comment-beg 2)) 7) t)
2071 ;; Collect a sequence of doc style line comments.
2072 (progn
2073 (goto-char comment-beg)
2074 (while (and (progn
2075 (c-forward-single-comment)
2076 (skip-syntax-forward " ")
2077 (< (point) limit))
2078 (looking-at prefix))))
2079 (goto-char comment-beg)
2080 (c-forward-single-comment))
2081 (if (> (point) limit) (goto-char limit))
2082 (setq comment-beg nil)
2083
2084 (let ((region-end (point))
2085 (keylist keywords) keyword matcher highlights)
2086 (c-put-font-lock-face region-beg region-end c-doc-face-name)
2087 (save-restriction
2088 ;; Narrow to the doc comment. Among other things, this
2089 ;; helps by making "^" match at the start of the comment.
2090 ;; Do not include a trailing block comment ender, though.
2091 (and (> region-end (1+ region-beg))
2092 (progn (goto-char region-end)
2093 (backward-char 2)
2094 (looking-at "\\*/"))
2095 (setq region-end (point)))
2096 (narrow-to-region region-beg region-end)
2097
2098 (while keylist
2099 (setq keyword (car keylist)
2100 keylist (cdr keylist)
2101 matcher (car keyword))
2102 (goto-char region-beg)
2103 (while (if (stringp matcher)
2104 (re-search-forward matcher region-end t)
2105 (funcall matcher region-end))
2106 (setq highlights (cdr keyword))
2107 (if (consp (car highlights))
2108 (while highlights
2109 (font-lock-apply-highlight (car highlights))
2110 (setq highlights (cdr highlights)))
2111 (font-lock-apply-highlight highlights))))
2112
2113 (goto-char region-end)))))
2114 nil)
2115 (put 'c-font-lock-doc-comments 'lisp-indent-function 2)
2116
2117 (defun c-find-invalid-doc-markup (regexp limit)
2118 ;; Used to fontify invalid markup in doc comments after the correct
2119 ;; ones have been fontified: Find the first occurrence of REGEXP
2120 ;; between the point and LIMIT that only is fontified with
2121 ;; `c-doc-face-name'. If a match is found then submatch 0 surrounds
2122 ;; the first char and t is returned, otherwise nil is returned.
2123 ;;
2124 ;; This function might do hidden buffer changes.
2125 (let (start)
2126 (while (if (re-search-forward regexp limit t)
2127 (not (eq (get-text-property
2128 (setq start (match-beginning 0)) 'face)
2129 c-doc-face-name))
2130 (setq start nil)))
2131 (when start
2132 (store-match-data (list (copy-marker start)
2133 (copy-marker (1+ start))))
2134 t)))
2135
2136 ;; GtkDoc patterns contributed by Masatake YAMATO <jet@gyve.org>.
2137
2138 (defconst gtkdoc-font-lock-doc-comments
2139 (let ((symbol "[a-zA-Z0-9_]+")
2140 (header "^ \\* "))
2141 `((,(concat header "\\(" symbol "\\):[ \t]*$")
2142 1 ,c-doc-markup-face-name prepend nil)
2143 (,(concat symbol "()")
2144 0 ,c-doc-markup-face-name prepend nil)
2145 (,(concat header "\\(" "@" symbol "\\):")
2146 1 ,c-doc-markup-face-name prepend nil)
2147 (,(concat "[#%@]" symbol)
2148 0 ,c-doc-markup-face-name prepend nil))
2149 ))
2150
2151 (defconst gtkdoc-font-lock-doc-protection
2152 `(("< \\(public\\|private\\|protected\\) >"
2153 1 ,c-doc-markup-face-name prepend nil)))
2154
2155 (defconst gtkdoc-font-lock-keywords
2156 `((,(lambda (limit)
2157 (c-font-lock-doc-comments "/\\*\\*$" limit
2158 gtkdoc-font-lock-doc-comments)
2159 (c-font-lock-doc-comments "/\\*< " limit
2160 gtkdoc-font-lock-doc-protection)
2161 ))))
2162
2163 ;; Javadoc.
2164
2165 (defconst javadoc-font-lock-doc-comments
2166 `(("{@[a-z]+[^}\n\r]*}" ; "{@foo ...}" markup.
2167 0 ,c-doc-markup-face-name prepend nil)
2168 ("^\\(/\\*\\)?\\(\\s \\|\\*\\)*\\(@[a-z]+\\)" ; "@foo ..." markup.
2169 3 ,c-doc-markup-face-name prepend nil)
2170 (,(concat "</?\\sw" ; HTML tags.
2171 "\\("
2172 (concat "\\sw\\|\\s \\|[=\n\r*.:]\\|"
2173 "\"[^\"]*\"\\|'[^']*'")
2174 "\\)*>")
2175 0 ,c-doc-markup-face-name prepend nil)
2176 ("&\\(\\sw\\|[.:]\\)+;" ; HTML entities.
2177 0 ,c-doc-markup-face-name prepend nil)
2178 ;; Fontify remaining markup characters as invalid. Note
2179 ;; that the Javadoc spec is hazy about when "@" is
2180 ;; allowed in non-markup use.
2181 (,(lambda (limit)
2182 (c-find-invalid-doc-markup "[<>&]\\|{@" limit))
2183 0 'font-lock-warning-face prepend nil)))
2184
2185 (defconst javadoc-font-lock-keywords
2186 `((,(lambda (limit)
2187 (c-font-lock-doc-comments "/\\*\\*" limit
2188 javadoc-font-lock-doc-comments)))))
2189
2190 ;; Pike autodoc.
2191
2192 (defconst autodoc-decl-keywords
2193 ;; Adorned regexp matching the keywords that introduce declarations
2194 ;; in Pike Autodoc.
2195 (cc-eval-when-compile
2196 (c-make-keywords-re t '("@decl" "@elem" "@index" "@member") 'pike-mode)))
2197
2198 (defconst autodoc-decl-type-keywords
2199 ;; Adorned regexp matching the keywords that are followed by a type.
2200 (cc-eval-when-compile
2201 (c-make-keywords-re t '("@elem" "@member") 'pike-mode)))
2202
2203 (defun autodoc-font-lock-line-markup (limit)
2204 ;; Fontify all line oriented keywords between the point and LIMIT.
2205 ;; Nil is always returned.
2206 ;;
2207 ;; This function might do hidden buffer changes.
2208
2209 (let ((line-re (concat "^\\(\\(/\\*!\\|\\s *\\("
2210 c-current-comment-prefix
2211 "\\)\\)\\s *\\)@[A-Za-z_-]+\\(\\s \\|$\\)"))
2212 (markup-faces (list c-doc-markup-face-name c-doc-face-name)))
2213
2214 (while (re-search-forward line-re limit t)
2215 (goto-char (match-end 1))
2216
2217 (if (looking-at autodoc-decl-keywords)
2218 (let* ((kwd-pos (point))
2219 (start (match-end 1))
2220 (pos start)
2221 end)
2222
2223 (c-put-font-lock-face (point) pos markup-faces)
2224
2225 ;; Put a declaration end mark at the markup keyword and
2226 ;; remove the faces from the rest of the line so that it
2227 ;; gets refontified as a declaration later on by
2228 ;; `c-font-lock-declarations'.
2229 (c-put-char-property (1- pos) 'c-type 'c-decl-end)
2230 (goto-char pos)
2231 (while (progn
2232 (end-of-line)
2233 (setq end (point))
2234 (and (eq (char-before) ?@)
2235 (not (eobp))
2236 (progn (forward-char)
2237 (skip-syntax-forward " ")
2238 (looking-at c-current-comment-prefix))))
2239 (goto-char (match-end 0))
2240 (c-remove-font-lock-face pos (1- end))
2241 (c-put-font-lock-face (1- end) end markup-faces)
2242 (setq pos (point)))
2243
2244 ;; Include the final newline in the removed area. This
2245 ;; has no visual effect but it avoids some tricky special
2246 ;; cases in the testsuite wrt the differences in string
2247 ;; fontification in Emacs vs XEmacs.
2248 (c-remove-font-lock-face pos (min (1+ (point)) (point-max)))
2249
2250 ;; Must handle string literals explicitly inside the declaration.
2251 (goto-char start)
2252 (while (re-search-forward
2253 "\"\\([^\\\"]\\|\\\\.\\)*\"\\|'\\([^\\']\\|\\\\.\\)*'"
2254 end 'move)
2255 (c-put-font-lock-string-face (match-beginning 0)
2256 (point)))
2257
2258 ;; Fontify types after keywords that always are followed
2259 ;; by them.
2260 (goto-char kwd-pos)
2261 (when (looking-at autodoc-decl-type-keywords)
2262 (c-fontify-types-and-refs ((c-promote-possible-types t))
2263 (goto-char start)
2264 (c-forward-syntactic-ws)
2265 (c-forward-type))))
2266
2267 ;; Mark each whole line as markup, as long as the logical line
2268 ;; continues.
2269 (while (progn
2270 (c-put-font-lock-face (point)
2271 (progn (end-of-line) (point))
2272 markup-faces)
2273 (and (eq (char-before) ?@)
2274 (not (eobp))
2275 (progn (forward-char)
2276 (skip-syntax-forward " ")
2277 (looking-at c-current-comment-prefix))))
2278 (goto-char (match-end 0))))))
2279
2280 nil)
2281
2282 (defconst autodoc-font-lock-doc-comments
2283 `(("@\\(\\w+{\\|\\[\\([^\]@\n\r]\\|@@\\)*\\]\\|[@}]\\|$\\)"
2284 ;; In-text markup.
2285 0 ,c-doc-markup-face-name prepend nil)
2286 (autodoc-font-lock-line-markup)
2287 ;; Fontify remaining markup characters as invalid.
2288 (,(lambda (limit)
2289 (c-find-invalid-doc-markup "@" limit))
2290 0 'font-lock-warning-face prepend nil)
2291 ))
2292
2293 (defun autodoc-font-lock-keywords ()
2294 ;; Note that we depend on that `c-current-comment-prefix' has got
2295 ;; its proper value here.
2296 ;;
2297 ;; This function might do hidden buffer changes.
2298
2299 ;; The `c-type' text property with `c-decl-end' is used to mark the
2300 ;; end of the `autodoc-decl-keywords' occurrences to fontify the
2301 ;; following declarations.
2302 (setq c-type-decl-end-used t)
2303
2304 `((,(lambda (limit)
2305 (c-font-lock-doc-comments "/[*/]!" limit
2306 autodoc-font-lock-doc-comments)))))
2307
2308 \f
2309 ;; 2006-07-10: awk-font-lock-keywords has been moved back to cc-awk.el.
2310 (cc-provide 'cc-fonts)
2311
2312 ;; arch-tag: 2f65f405-735f-4da5-8d4b-b957844c5203
2313 ;;; cc-fonts.el ends here