Fix Bug#27315
[emacs.git] / lisp / progmodes / cc-fonts.el
blobadb1f1a4937843c19f87b6c2c2591dd8f461d3e6
1 ;;; cc-fonts.el --- font lock support for CC Mode
3 ;; Copyright (C) 2002-2017 Free Software Foundation, Inc.
5 ;; Authors: 2003- Alan Mackenzie
6 ;; 2002- Martin Stjernholm
7 ;; Maintainer: bug-cc-mode@gnu.org
8 ;; Created: 07-Jan-2002
9 ;; Keywords: c languages
10 ;; Package: cc-mode
12 ;; This file is part of GNU Emacs.
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.
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.
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/>.
27 ;;; Commentary:
29 ;; Some comments on the use of faces:
31 ;; o `c-label-face-name' is either `font-lock-constant-face' (in
32 ;; Emacs), or `font-lock-reference-face'.
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'.
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.
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).
48 ;; TBD: We should probably provide real faces for the above uses and
49 ;; instead initialize them from the standard faces.
51 ;;; Code:
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):
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.
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)))
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 ..).
83 ;; Avoid repeated loading through the eval-after-load directive in
84 ;; cc-mode.el.
85 (provide 'cc-fonts)
87 (cc-external-require 'font-lock)
89 (cc-bytecomp-defvar parse-sexp-lookup-properties) ; Emacs only.
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)
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.
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)
117 'font-lock-reference-face)))
119 (cc-bytecomp-defvar font-lock-constant-face)
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)
134 'font-lock-reference-face)))
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))
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)))
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)
163 'font-lock-comment-face)))
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))
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))
178 (cc-bytecomp-defun face-inverse-video-p) ; Only in Emacs.
180 (defun c-make-inverse-face (oldface newface)
181 ;; Emacs and XEmacs have completely different face manipulation
182 ;; routines. :P
183 (copy-face oldface newface)
184 (cond ((fboundp 'face-inverse-video-p)
185 ;; Emacs. This only looks at the inverse flag in the current
186 ;; frame. Other display configurations might be different,
187 ;; but it can only show if the same Emacs has frames on
188 ;; e.g. a color and a monochrome display simultaneously.
189 (unless (face-inverse-video-p oldface)
190 (invert-face newface)))
191 ((fboundp 'face-property-instance)
192 ;; XEmacs. Same pitfall here.
193 (unless (face-property-instance oldface 'reverse)
194 (invert-face newface)))))
196 (defvar c-annotation-face 'c-annotation-face)
198 (defface c-annotation-face
199 '((default :inherit font-lock-constant-face))
200 "Face for highlighting annotations in Java mode and similar modes."
201 :version "24.1"
202 :group 'c)
204 (eval-and-compile
205 ;; We need the following definitions during compilation since they're
206 ;; used when the `c-lang-defconst' initializers are evaluated. Define
207 ;; them at runtime too for the sake of derived modes.
209 ;; This indicates the "font locking context", and is set just before
210 ;; fontification is done. If non-nil, it says, e.g., point starts
211 ;; from within a #if preprocessor construct.
212 (defvar c-font-lock-context nil)
213 (make-variable-buffer-local 'c-font-lock-context)
215 (defmacro c-put-font-lock-face (from to face)
216 ;; Put a face on a region (overriding any existing face) in the way
217 ;; font-lock would do it. In XEmacs that means putting an
218 ;; additional font-lock property, or else the font-lock package
219 ;; won't recognize it as fontified and might override it
220 ;; incorrectly.
222 ;; This function does a hidden buffer change.
223 (if (fboundp 'font-lock-set-face)
224 ;; Note: This function has no docstring in XEmacs so it might be
225 ;; considered internal.
226 `(font-lock-set-face ,from ,to ,face)
227 `(put-text-property ,from ,to 'face ,face)))
229 (defmacro c-remove-font-lock-face (from to)
230 ;; This is the inverse of `c-put-font-lock-face'.
232 ;; This function does a hidden buffer change.
233 (if (fboundp 'font-lock-remove-face)
234 `(font-lock-remove-face ,from ,to)
235 `(remove-text-properties ,from ,to '(face nil))))
237 (defmacro c-put-font-lock-string-face (from to)
238 ;; Put `font-lock-string-face' on a string. The surrounding
239 ;; quotes are included in Emacs but not in XEmacs. The passed
240 ;; region should include them.
242 ;; This function does a hidden buffer change.
243 (if (featurep 'xemacs)
244 `(c-put-font-lock-face (1+ ,from) (1- ,to) 'font-lock-string-face)
245 `(c-put-font-lock-face ,from ,to 'font-lock-string-face)))
247 (defmacro c-fontify-types-and-refs (varlist &rest body)
248 ;; Like `let', but additionally activates `c-record-type-identifiers'
249 ;; and `c-record-ref-identifiers', and fontifies the recorded ranges
250 ;; accordingly on exit.
252 ;; This function does hidden buffer changes.
253 `(let ((c-record-type-identifiers t)
254 c-record-ref-identifiers
255 ,@varlist)
256 (prog1 (progn ,@body)
257 (c-fontify-recorded-types-and-refs))))
258 (put 'c-fontify-types-and-refs 'lisp-indent-function 1)
260 (defun c-skip-comments-and-strings (limit)
261 ;; If the point is within a region fontified as a comment or
262 ;; string literal skip to the end of it or to LIMIT, whichever
263 ;; comes first, and return t. Otherwise return nil. The match
264 ;; data is not clobbered.
266 ;; This function might do hidden buffer changes.
267 (when (c-got-face-at (point) c-literal-faces)
268 (while (progn
269 (goto-char (c-next-single-property-change
270 (point) 'face nil limit))
271 (and (< (point) limit)
272 (c-got-face-at (point) c-literal-faces))))
275 (defun c-make-syntactic-matcher (regexp)
276 ;; Returns a byte compiled function suitable for use in place of a
277 ;; regexp string in a `font-lock-keywords' matcher, except that
278 ;; only matches outside comments and string literals count.
280 ;; This function does not do any hidden buffer changes, but the
281 ;; generated functions will. (They are however used in places
282 ;; covered by the font-lock context.)
283 (byte-compile
284 `(lambda (limit)
285 (let (res)
286 (while (and (setq res (re-search-forward ,regexp limit t))
287 (progn
288 (goto-char (match-beginning 0))
289 (or (c-skip-comments-and-strings limit)
290 (progn
291 (goto-char (match-end 0))
292 nil)))))
293 res))))
295 (defun c-make-font-lock-search-form (regexp highlights)
296 ;; Return a lisp form which will fontify every occurrence of REGEXP
297 ;; (a regular expression, NOT a function) between POINT and `limit'
298 ;; with HIGHLIGHTS, a list of highlighters as specified on page
299 ;; "Search-based Fontification" in the elisp manual.
300 `(while (re-search-forward ,regexp limit t)
301 (unless (progn
302 (goto-char (match-beginning 0))
303 (c-skip-comments-and-strings limit))
304 (goto-char (match-end 0))
305 ,@(mapcar
306 (lambda (highlight)
307 (if (integerp (car highlight))
308 ;; e.g. highlight is (1 font-lock-type-face t)
309 (progn
310 (unless (eq (nth 2 highlight) t)
311 (error
312 "The override flag must currently be t in %s"
313 highlight))
314 (when (nth 3 highlight)
315 (error
316 "The laxmatch flag may currently not be set in %s"
317 highlight))
318 `(save-match-data
319 (c-put-font-lock-face
320 (match-beginning ,(car highlight))
321 (match-end ,(car highlight))
322 ,(elt highlight 1))))
323 ;; highlight is an "ANCHORED HIGHLIGHTER" of the form
324 ;; (ANCHORED-MATCHER PRE-FORM POST-FORM SUBEXP-HIGHLIGHTERS...)
325 (when (nth 3 highlight)
326 (error "Match highlights currently not supported in %s"
327 highlight))
328 `(progn
329 ,(nth 1 highlight)
330 (save-match-data ,(car highlight))
331 ,(nth 2 highlight))))
332 highlights))))
334 (defun c-make-font-lock-search-function (regexp &rest highlights)
335 ;; This function makes a byte compiled function that works much like
336 ;; a matcher element in `font-lock-keywords'. It cuts out a little
337 ;; bit of the overhead compared to a real matcher. The main reason
338 ;; is however to pass the real search limit to the anchored
339 ;; matcher(s), since most (if not all) font-lock implementations
340 ;; arbitrarily limit anchored matchers to the same line, and also
341 ;; to insulate against various other irritating differences between
342 ;; the different (X)Emacs font-lock packages.
344 ;; REGEXP is the matcher, which must be a regexp. Only matches
345 ;; where the beginning is outside any comment or string literal are
346 ;; significant.
348 ;; HIGHLIGHTS is a list of highlight specs, just like in
349 ;; `font-lock-keywords', with these limitations: The face is always
350 ;; overridden (no big disadvantage, since hits in comments etc are
351 ;; filtered anyway), there is no "laxmatch", and an anchored matcher
352 ;; is always a form which must do all the fontification directly.
353 ;; `limit' is a variable bound to the real limit in the context of
354 ;; the anchored matcher forms.
356 ;; This function does not do any hidden buffer changes, but the
357 ;; generated functions will. (They are however used in places
358 ;; covered by the font-lock context.)
360 ;; Note: Replace `byte-compile' with `eval' to debug the generated
361 ;; lambda more easily.
362 (byte-compile
363 `(lambda (limit)
364 (let ( ;; The font-lock package in Emacs is known to clobber
365 ;; `parse-sexp-lookup-properties' (when it exists).
366 (parse-sexp-lookup-properties
367 (cc-eval-when-compile
368 (boundp 'parse-sexp-lookup-properties))))
369 ,(c-make-font-lock-search-form regexp highlights))
370 nil)))
372 (defun c-make-font-lock-BO-decl-search-function (regexp &rest highlights)
373 ;; This function makes a byte compiled function that first moves back
374 ;; to the beginning of the current declaration (if any), then searches
375 ;; forward for matcher elements (as in `font-lock-keywords') and
376 ;; fontifies them.
378 ;; The motivation for moving back to the declaration start is to
379 ;; establish a context for the current text when, e.g., a character
380 ;; is typed on a C++ inheritance continuation line, or a jit-lock
381 ;; chunk starts there.
383 ;; The new function works much like a matcher element in
384 ;; `font-lock-keywords'. It cuts out a little bit of the overhead
385 ;; compared to a real matcher. The main reason is however to pass the
386 ;; real search limit to the anchored matcher(s), since most (if not
387 ;; all) font-lock implementations arbitrarily limit anchored matchers
388 ;; to the same line, and also to insulate against various other
389 ;; irritating differences between the different (X)Emacs font-lock
390 ;; packages.
392 ;; REGEXP is the matcher, which must be a regexp. Only matches
393 ;; where the beginning is outside any comment or string literal are
394 ;; significant.
396 ;; HIGHLIGHTS is a list of highlight specs, just like in
397 ;; `font-lock-keywords', with these limitations: The face is always
398 ;; overridden (no big disadvantage, since hits in comments etc are
399 ;; filtered anyway), there is no "laxmatch", and an anchored matcher
400 ;; is always a form which must do all the fontification directly.
401 ;; `limit' is a variable bound to the real limit in the context of
402 ;; the anchored matcher forms.
404 ;; This function does not do any hidden buffer changes, but the
405 ;; generated functions will. (They are however used in places
406 ;; covered by the font-lock context.)
408 ;; Note: Replace `byte-compile' with `eval' to debug the generated
409 ;; lambda more easily.
410 (byte-compile
411 `(lambda (limit)
412 (let ( ;; The font-lock package in Emacs is known to clobber
413 ;; `parse-sexp-lookup-properties' (when it exists).
414 (parse-sexp-lookup-properties
415 (cc-eval-when-compile
416 (boundp 'parse-sexp-lookup-properties)))
417 (BOD-limit
418 (c-determine-limit 1000)))
419 (goto-char
420 (let ((here (point)))
421 (if (eq (car (c-beginning-of-decl-1 BOD-limit)) 'same)
422 (point)
423 here)))
424 ,(c-make-font-lock-search-form regexp highlights))
425 nil)))
427 (defun c-make-font-lock-context-search-function (normal &rest state-stanzas)
428 ;; This function makes a byte compiled function that works much like
429 ;; a matcher element in `font-lock-keywords', with the following
430 ;; enhancement: the generated function will test for particular "font
431 ;; lock contexts" at the start of the region, i.e. is this point in
432 ;; the middle of some particular construct? if so the generated
433 ;; function will first fontify the tail of the construct, before
434 ;; going into the main loop and fontify full constructs up to limit.
436 ;; The generated function takes one parameter called `limit', and
437 ;; will fontify the region between POINT and LIMIT.
439 ;; NORMAL is a list of the form (REGEXP HIGHLIGHTS .....), and is
440 ;; used to fontify the "regular" bit of the region.
441 ;; STATE-STANZAS is list of elements of the form (STATE LIM REGEXP
442 ;; HIGHLIGHTS), each element coding one possible font lock context.
444 ;; o - REGEXP is a font-lock regular expression (NOT a function),
445 ;; o - HIGHLIGHTS is a list of zero or more highlighters as defined
446 ;; on page "Search-based Fontification" in the elisp manual. As
447 ;; yet (2009-06), they must have OVERRIDE set, and may not have
448 ;; LAXMATCH set.
450 ;; o - STATE is the "font lock context" (e.g. in-cpp-expr) and is
451 ;; not quoted.
452 ;; o - LIM is a lisp form whose evaluation will yield the limit
453 ;; position in the buffer for fontification by this stanza.
455 ;; This function does not do any hidden buffer changes, but the
456 ;; generated functions will. (They are however used in places
457 ;; covered by the font-lock context.)
459 ;; Note: Replace `byte-compile' with `eval' to debug the generated
460 ;; lambda more easily.
461 (byte-compile
462 `(lambda (limit)
463 (let ( ;; The font-lock package in Emacs is known to clobber
464 ;; `parse-sexp-lookup-properties' (when it exists).
465 (parse-sexp-lookup-properties
466 (cc-eval-when-compile
467 (boundp 'parse-sexp-lookup-properties))))
468 ,@(mapcar
469 (lambda (stanza)
470 (let ((state (car stanza))
471 (lim (nth 1 stanza))
472 (regexp (nth 2 stanza))
473 (highlights (cdr (cddr stanza))))
474 `(if (eq c-font-lock-context ',state)
475 (let ((limit ,lim))
476 ,(c-make-font-lock-search-form
477 regexp highlights)))))
478 state-stanzas)
479 ,(c-make-font-lock-search-form (car normal) (cdr normal))
480 nil))))
482 ; (eval-after-load "edebug" ; 2006-07-09: def-edebug-spec is now in subr.el.
483 ; '(progn
484 (def-edebug-spec c-fontify-types-and-refs let*)
485 (def-edebug-spec c-make-syntactic-matcher t)
486 ;; If there are literal quoted or backquoted highlight specs in
487 ;; the call to `c-make-font-lock-search-function' then let's
488 ;; instrument the forms in them.
489 (def-edebug-spec c-make-font-lock-search-function
490 (form &rest &or ("quote" (&rest form)) ("`" (&rest form)) form)));))
492 (defun c-fontify-recorded-types-and-refs ()
493 ;; Convert the ranges recorded on `c-record-type-identifiers' and
494 ;; `c-record-ref-identifiers' to fontification.
496 ;; This function does hidden buffer changes.
497 (let (elem)
498 (while (consp c-record-type-identifiers)
499 (setq elem (car c-record-type-identifiers)
500 c-record-type-identifiers (cdr c-record-type-identifiers))
501 (c-put-font-lock-face (car elem) (cdr elem)
502 'font-lock-type-face))
503 (while c-record-ref-identifiers
504 (setq elem (car c-record-ref-identifiers)
505 c-record-ref-identifiers (cdr c-record-ref-identifiers))
506 ;; Note that the reference face is a variable that is
507 ;; dereferenced, since it's an alias in Emacs.
508 (c-put-font-lock-face (car elem) (cdr elem)
509 c-reference-face-name))))
511 (c-lang-defconst c-cpp-matchers
512 "Font lock matchers for preprocessor directives and purely lexical
513 stuff. Used on level 1 and higher."
515 ;; Note: `c-font-lock-declarations' assumes that no matcher here
516 ;; sets `font-lock-type-face' in languages where
517 ;; `c-recognize-<>-arglists' is set.
519 t `(,@(when (c-lang-const c-opt-cpp-prefix)
520 (let* ((noncontinued-line-end "\\(\\=\\|\\(\\=\\|[^\\]\\)[\n\r]\\)")
521 (ncle-depth (regexp-opt-depth noncontinued-line-end))
522 (sws-depth (c-lang-const c-syntactic-ws-depth))
523 (nsws-depth (c-lang-const c-nonempty-syntactic-ws-depth)))
525 `(;; The stuff after #error and #warning is a message, so
526 ;; fontify it as a string.
527 ,@(when (c-lang-const c-cpp-message-directives)
528 (let* ((re (c-make-keywords-re 'appendable ; nil
529 (c-lang-const c-cpp-message-directives)))
530 (re-depth (regexp-opt-depth re)))
531 `((,(concat noncontinued-line-end
532 (c-lang-const c-opt-cpp-prefix)
534 "\\s +\\(.*\\)$")
535 ,(+ ncle-depth re-depth 1) font-lock-string-face t))))
537 ;; Fontify filenames in #include <...> as strings.
538 ,@(when (c-lang-const c-cpp-include-directives)
539 (let* ((re (c-make-keywords-re nil
540 (c-lang-const c-cpp-include-directives)))
541 (re-depth (regexp-opt-depth re)))
542 ;; We used to use a font-lock "anchored matcher" here for
543 ;; the paren syntax. This failed when the ">" was at EOL,
544 ;; since `font-lock-fontify-anchored-keywords' terminated
545 ;; its loop at EOL without executing our lambda form at
546 ;; all.
547 `((,(c-make-font-lock-search-function
548 (concat noncontinued-line-end
549 (c-lang-const c-opt-cpp-prefix)
551 (c-lang-const c-syntactic-ws)
552 "\\(<[^>\n\r]*>?\\)")
553 `(,(+ ncle-depth re-depth sws-depth 1)
554 font-lock-string-face t)
555 `((let ((beg (match-beginning
556 ,(+ ncle-depth re-depth sws-depth 1)))
557 (end (1- (match-end ,(+ ncle-depth re-depth
558 sws-depth 1)))))
559 (if (eq (char-after end) ?>)
560 (progn
561 (c-mark-<-as-paren beg)
562 (c-mark->-as-paren end))
563 (c-unmark-<->-as-paren beg)))
564 nil))))))
566 ;; #define.
567 ,@(when (c-lang-const c-opt-cpp-macro-define)
568 `((,(c-make-font-lock-search-function
569 (concat
570 noncontinued-line-end
571 (c-lang-const c-opt-cpp-prefix)
572 (c-lang-const c-opt-cpp-macro-define)
573 (c-lang-const c-nonempty-syntactic-ws)
574 "\\(" (c-lang-const ; 1 + ncle + nsws
575 c-symbol-key) "\\)"
576 (concat "\\(" ; 2 + ncle + nsws + c-sym-key
577 ;; Macro with arguments - a "function".
578 "\\((\\)" ; 3 + ncle + nsws + c-sym-key
579 "\\|"
580 ;; Macro without arguments - a "variable".
581 "\\([^(]\\|$\\)"
582 "\\)"))
583 `((if (match-beginning
584 ,(+ 3 ncle-depth nsws-depth
585 (c-lang-const c-symbol-key-depth)))
587 ;; "Function". Fontify the name and the arguments.
588 (save-restriction
589 (c-put-font-lock-face
590 (match-beginning ,(+ 1 ncle-depth nsws-depth))
591 (match-end ,(+ 1 ncle-depth nsws-depth))
592 'font-lock-function-name-face)
593 (goto-char
594 (match-end
595 ,(+ 3 ncle-depth nsws-depth
596 (c-lang-const c-symbol-key-depth))))
598 (narrow-to-region (point-min) limit)
599 (while (and
600 (progn
601 (c-forward-syntactic-ws)
602 (looking-at c-symbol-key))
603 (progn
604 (c-put-font-lock-face
605 (match-beginning 0) (match-end 0)
606 'font-lock-variable-name-face)
607 (goto-char (match-end 0))
608 (c-forward-syntactic-ws)
609 (eq (char-after) ?,)))
610 (forward-char)))
612 ;; "Variable".
613 (c-put-font-lock-face
614 (match-beginning ,(+ 1 ncle-depth nsws-depth))
615 (match-end ,(+ 1 ncle-depth nsws-depth))
616 'font-lock-variable-name-face)))))))
618 ;; Fontify cpp function names in preprocessor
619 ;; expressions in #if and #elif.
620 ,@(when (and (c-lang-const c-cpp-expr-directives)
621 (c-lang-const c-cpp-expr-functions))
622 (let ((ced-re (c-make-keywords-re t
623 (c-lang-const c-cpp-expr-directives)))
624 (cef-re (c-make-keywords-re t
625 (c-lang-const c-cpp-expr-functions))))
627 `((,(c-make-font-lock-context-search-function
628 `(,(concat noncontinued-line-end
629 (c-lang-const c-opt-cpp-prefix)
630 ced-re ; 1 + ncle-depth
631 ;; Match the whole logical line to look
632 ;; for the functions in.
633 "\\(\\\\\\(.\\|[\n\r]\\)\\|[^\n\r]\\)*")
634 ((let ((limit (match-end 0)))
635 (while (re-search-forward ,cef-re limit 'move)
636 (c-put-font-lock-face (match-beginning 1)
637 (match-end 1)
638 c-preprocessor-face-name)))
639 (goto-char (match-end ,(1+ ncle-depth)))))
640 `(in-cpp-expr
641 (save-excursion (c-end-of-macro) (point))
642 ,cef-re
643 (1 c-preprocessor-face-name t)))))))
645 ;; Fontify the directive names.
646 (,(c-make-font-lock-search-function
647 (concat noncontinued-line-end
648 "\\("
649 (c-lang-const c-opt-cpp-prefix)
650 "[" (c-lang-const c-symbol-chars) "]+"
651 "\\)")
652 `(,(1+ ncle-depth) c-preprocessor-face-name t)))
654 (eval . (list ,(c-make-syntactic-matcher
655 (concat noncontinued-line-end
656 (c-lang-const c-opt-cpp-prefix)
657 "if\\(n\\)def\\>"))
658 ,(+ ncle-depth 1)
659 c-negation-char-face-name
660 'append))
663 ,@(when (c-major-mode-is 'pike-mode)
664 ;; Recognize hashbangs in Pike.
665 `((eval . (list "\\`#![^\n\r]*"
666 0 c-preprocessor-face-name))))
668 ;; Make hard spaces visible through an inverted `font-lock-warning-face'.
669 (eval . (list
670 "\240"
671 0 (progn
672 (unless (c-face-name-p 'c-nonbreakable-space-face)
673 (c-make-inverse-face 'font-lock-warning-face
674 'c-nonbreakable-space-face))
675 ''c-nonbreakable-space-face)))
678 (defun c-font-lock-invalid-string ()
679 ;; Assuming the point is after the opening character of a string,
680 ;; fontify that char with `font-lock-warning-face' if the string
681 ;; decidedly isn't terminated properly.
683 ;; This function does hidden buffer changes.
684 (let ((start (1- (point))))
685 (save-excursion
686 (and (eq (elt (parse-partial-sexp start (c-point 'eol)) 8) start)
687 (if (if (eval-when-compile (integerp ?c))
688 ;; Emacs
689 (integerp c-multiline-string-start-char)
690 ;; XEmacs
691 (characterp c-multiline-string-start-char))
692 ;; There's no multiline string start char before the
693 ;; string, so newlines aren't allowed.
694 (not (eq (char-before start) c-multiline-string-start-char))
695 ;; Multiline strings are allowed anywhere if
696 ;; c-multiline-string-start-char is t.
697 (not c-multiline-string-start-char))
698 (if c-string-escaped-newlines
699 ;; There's no \ before the newline.
700 (not (eq (char-before (point)) ?\\))
701 ;; Escaped newlines aren't supported.
703 (c-put-font-lock-face start (1+ start) 'font-lock-warning-face)))))
705 (c-lang-defconst c-basic-matchers-before
706 "Font lock matchers for basic keywords, labels, references and various
707 other easily recognizable things that should be fontified before generic
708 casts and declarations are fontified. Used on level 2 and higher."
710 ;; Note: `c-font-lock-declarations' assumes that no matcher here
711 ;; sets `font-lock-type-face' in languages where
712 ;; `c-recognize-<>-arglists' is set.
714 t `(;; Put a warning face on the opener of unclosed strings that
715 ;; can't span lines. Later font
716 ;; lock packages have a `font-lock-syntactic-face-function' for
717 ;; this, but it doesn't give the control we want since any
718 ;; fontification done inside the function will be
719 ;; unconditionally overridden.
720 ,(c-make-font-lock-search-function
721 ;; Match a char before the string starter to make
722 ;; `c-skip-comments-and-strings' work correctly.
723 (concat ".\\(" c-string-limit-regexp "\\)")
724 '((c-font-lock-invalid-string)))
726 ;; Fontify C++ raw strings.
727 ,@(when (c-major-mode-is 'c++-mode)
728 '(c-font-lock-raw-strings))
730 ;; Fontify keyword constants.
731 ,@(when (c-lang-const c-constant-kwds)
732 (let ((re (c-make-keywords-re nil (c-lang-const c-constant-kwds))))
733 (if (c-major-mode-is 'pike-mode)
734 ;; No symbol is a keyword after "->" in Pike.
735 `((eval . (list ,(concat "\\(\\=.?\\|[^>]\\|[^-]>\\)"
736 "\\<\\(" re "\\)\\>")
737 2 c-constant-face-name)))
738 `((eval . (list ,(concat "\\<\\(" re "\\)\\>")
739 1 c-constant-face-name))))))
741 ;; Fontify all keywords except the primitive types.
742 ,(if (c-major-mode-is 'pike-mode)
743 ;; No symbol is a keyword after "->" in Pike.
744 `(,(concat "\\(\\=.?\\|[^>]\\|[^-]>\\)"
745 "\\<" (c-lang-const c-regular-keywords-regexp))
746 2 font-lock-keyword-face)
747 `(,(concat "\\<" (c-lang-const c-regular-keywords-regexp))
748 1 font-lock-keyword-face))
750 ;; Fontify leading identifiers in fully qualified names like
751 ;; "foo::bar" in languages that supports such things.
752 ,@(when (c-lang-const c-opt-identifier-concat-key)
753 (if (c-major-mode-is 'java-mode)
754 ;; Java needs special treatment since "." is used both to
755 ;; qualify names and in normal indexing. Here we look for
756 ;; capital characters at the beginning of an identifier to
757 ;; recognize the class. "*" is also recognized to cover
758 ;; wildcard import declarations. All preceding dot separated
759 ;; identifiers are taken as package names and therefore
760 ;; fontified as references.
761 `(,(c-make-font-lock-search-function
762 ;; Search for class identifiers preceded by ".". The
763 ;; anchored matcher takes it from there.
764 (concat (c-lang-const c-opt-identifier-concat-key)
765 (c-lang-const c-simple-ws) "*"
766 (concat "\\("
767 "[" c-upper "]"
768 "[" (c-lang-const c-symbol-chars) "]*"
769 "\\|"
770 "\\*"
771 "\\)"))
772 `((let (id-end)
773 (goto-char (1+ (match-beginning 0)))
774 (while (and (eq (char-before) ?.)
775 (progn
776 (backward-char)
777 (c-backward-syntactic-ws)
778 (setq id-end (point))
779 (< (skip-chars-backward
780 ,(c-lang-const c-symbol-chars)) 0))
781 (not (get-text-property (point) 'face)))
782 (c-put-font-lock-face (point) id-end
783 c-reference-face-name)
784 (c-backward-syntactic-ws)))
786 (goto-char (match-end 0)))))
788 `((,(byte-compile
789 ;; Must use a function here since we match longer than
790 ;; we want to move before doing a new search. This is
791 ;; not necessary for XEmacs since it restarts the
792 ;; search from the end of the first highlighted
793 ;; submatch (something that causes problems in other
794 ;; places).
795 `(lambda (limit)
796 (while (re-search-forward
797 ,(concat "\\(\\<" ; 1
798 "\\(" (c-lang-const c-symbol-key) "\\)" ; 2
799 (c-lang-const c-simple-ws) "*"
800 (c-lang-const c-opt-identifier-concat-key)
801 (c-lang-const c-simple-ws) "*"
802 "\\)"
803 "\\("
804 (c-lang-const c-opt-after-id-concat-key)
805 "\\)")
806 limit t)
807 (unless (progn
808 (goto-char (match-beginning 0))
809 (c-skip-comments-and-strings limit))
810 (or (get-text-property (match-beginning 2) 'face)
811 (c-put-font-lock-face (match-beginning 2)
812 (match-end 2)
813 c-reference-face-name))
814 (goto-char (match-end 1))))))))))
816 ;; Fontify the special declarations in Objective-C.
817 ,@(when (c-major-mode-is 'objc-mode)
818 `(;; Fontify class names in the beginning of message expressions.
819 ,(c-make-font-lock-search-function
820 "\\["
821 '((c-fontify-types-and-refs ()
822 (c-forward-syntactic-ws limit)
823 (let ((start (point)))
824 ;; In this case we accept both primitive and known types.
825 (when (eq (c-forward-type) 'known)
826 (goto-char start)
827 (let ((c-promote-possible-types t))
828 (c-forward-type))))
829 (if (> (point) limit) (goto-char limit)))))
831 ;; The @interface/@implementation/@protocol directives.
832 ,(c-make-font-lock-search-function
833 (concat "\\<"
834 (regexp-opt
835 '("@interface" "@implementation" "@protocol")
837 "\\>")
838 '((c-fontify-types-and-refs
839 (;; The font-lock package in Emacs is known to clobber
840 ;; `parse-sexp-lookup-properties' (when it exists).
841 (parse-sexp-lookup-properties
842 (cc-eval-when-compile
843 (boundp 'parse-sexp-lookup-properties))))
844 (c-forward-objc-directive)
845 nil)
846 (goto-char (match-beginning 0))))))
848 (eval . (list "\\(!\\)[^=]" 1 c-negation-char-face-name))
851 (defun c-font-lock-complex-decl-prepare (limit)
852 ;; This function will be called from font-lock for a region bounded by POINT
853 ;; and LIMIT, as though it were to identify a keyword for
854 ;; font-lock-keyword-face. It always returns NIL to inhibit this and
855 ;; prevent a repeat invocation. See elisp/lispref page "Search-based
856 ;; Fontification".
858 ;; Called before any of the matchers in `c-complex-decl-matchers'.
860 ;; This function does hidden buffer changes.
862 ;;(message "c-font-lock-complex-decl-prepare %s %s" (point) limit)
864 ;; Clear the list of found types if we start from the start of the
865 ;; buffer, to make it easier to get rid of misspelled types and
866 ;; variables that have gotten recognized as types in malformed code.
867 (when (bobp)
868 (c-clear-found-types))
870 ;; Clear the c-type char properties which mark the region, to recalculate
871 ;; them properly. The most interesting properties are those put on the
872 ;; closest token before the region.
873 (save-excursion
874 (let ((pos (point)))
875 (c-backward-syntactic-ws)
876 (c-clear-char-properties
877 (if (and (not (bobp))
878 (memq (c-get-char-property (1- (point)) 'c-type)
879 '(c-decl-arg-start
880 c-decl-end
881 c-decl-id-start
882 c-decl-type-start)))
883 (1- (point))
884 pos)
885 limit 'c-type)))
887 ;; Update `c-state-cache' to the beginning of the region. This will
888 ;; make `c-beginning-of-syntax' go faster when it's used later on,
889 ;; and it's near the point most of the time.
890 (c-parse-state)
892 ;; Check if the fontified region starts inside a declarator list so
893 ;; that `c-font-lock-declarators' should be called at the start.
894 ;; The declared identifiers are font-locked correctly as types, if
895 ;; that is what they are.
896 (let ((prop (save-excursion
897 (c-backward-syntactic-ws)
898 (unless (bobp)
899 (c-get-char-property (1- (point)) 'c-type)))))
900 (when (memq prop '(c-decl-id-start c-decl-type-start))
901 (c-forward-syntactic-ws limit)
902 (c-font-lock-declarators limit t (eq prop 'c-decl-type-start)
903 (not (c-bs-at-toplevel-p (point))))))
905 (setq c-font-lock-context ;; (c-guess-font-lock-context)
906 (save-excursion
907 (if (and c-cpp-expr-intro-re
908 (c-beginning-of-macro)
909 (looking-at c-cpp-expr-intro-re))
910 'in-cpp-expr)))
911 nil)
913 (defun c-font-lock-<>-arglists (limit)
914 ;; This function will be called from font-lock for a region bounded by POINT
915 ;; and LIMIT, as though it were to identify a keyword for
916 ;; font-lock-keyword-face. It always returns NIL to inhibit this and
917 ;; prevent a repeat invocation. See elisp/lispref page "Search-based
918 ;; Fontification".
920 ;; Fontify types and references in names containing angle bracket
921 ;; arglists from the point to LIMIT. Note that
922 ;; `c-font-lock-declarations' has already handled many of them.
924 ;; This function might do hidden buffer changes.
926 (let (;; The font-lock package in Emacs is known to clobber
927 ;; `parse-sexp-lookup-properties' (when it exists).
928 (parse-sexp-lookup-properties
929 (cc-eval-when-compile
930 (boundp 'parse-sexp-lookup-properties)))
931 (c-parse-and-markup-<>-arglists t)
932 c-restricted-<>-arglists
933 id-start id-end id-face pos kwd-sym)
935 (while (and (< (point) limit)
936 (re-search-forward c-opt-<>-arglist-start limit t))
938 (setq id-start (match-beginning 1)
939 id-end (match-end 1)
940 pos (point))
942 (goto-char id-start)
943 (unless (c-skip-comments-and-strings limit)
944 (setq kwd-sym nil
945 c-restricted-<>-arglists nil
946 id-face (get-text-property id-start 'face))
948 (if (cond
949 ((eq id-face 'font-lock-type-face)
950 ;; The identifier got the type face so it has already been
951 ;; handled in `c-font-lock-declarations'.
952 nil)
954 ((eq id-face 'font-lock-keyword-face)
955 (when (looking-at c-opt-<>-sexp-key)
956 ;; There's a special keyword before the "<" that tells
957 ;; that it's an angle bracket arglist.
958 (setq kwd-sym (c-keyword-sym (match-string 1)))))
961 ;; There's a normal identifier before the "<". If we're not in
962 ;; a declaration context then we set `c-restricted-<>-arglists'
963 ;; to avoid recognizing templates in function calls like "foo (a
964 ;; < b, c > d)".
965 (c-backward-syntactic-ws)
966 (when (and (memq (char-before) '(?\( ?,))
967 (not (eq (get-text-property (1- (point)) 'c-type)
968 'c-decl-arg-start)))
969 (setq c-restricted-<>-arglists t))
972 (progn
973 (goto-char (1- pos))
974 ;; Check for comment/string both at the identifier and
975 ;; at the "<".
976 (unless (c-skip-comments-and-strings limit)
978 (c-fontify-types-and-refs ()
979 (when (c-forward-<>-arglist (c-keyword-member
980 kwd-sym 'c-<>-type-kwds))
981 (when (and c-opt-identifier-concat-key
982 (not (get-text-property id-start 'face)))
983 (c-forward-syntactic-ws)
984 (cond ((looking-at c-opt-identifier-concat-key)
985 (c-put-font-lock-face id-start id-end
986 c-reference-face-name))
987 ((eq (char-after) ?\())
988 (t (c-put-font-lock-face id-start id-end
989 'font-lock-type-face))))))
991 (goto-char pos)))
992 (goto-char pos)))))
993 nil)
995 (defun c-font-lock-declarators (limit list types not-top)
996 ;; Assuming the point is at the start of a declarator in a declaration,
997 ;; fontify the identifier it declares. (If TYPES is set, it does this via
998 ;; the macro `c-fontify-types-and-refs'.)
1000 ;; If LIST is non-nil, also fontify the ids in any following declarators in
1001 ;; a comma separated list (e.g. "foo" and "*bar" in "int foo = 17, *bar;");
1002 ;; additionally, mark the commas with c-type property 'c-decl-id-start or
1003 ;; 'c-decl-type-start (according to TYPES). Stop at LIMIT.
1005 ;; If TYPES is non-nil, fontify all identifiers as types. If NOT-TOP is
1006 ;; non-nil, we are not at the top-level ("top-level" includes being directly
1007 ;; inside a class or namespace, etc.).
1009 ;; Nil is always returned. The function leaves point at the delimiter after
1010 ;; the last declarator it processes.
1012 ;; This function might do hidden buffer changes.
1014 ;;(message "c-font-lock-declarators from %s to %s" (point) limit)
1015 (c-fontify-types-and-refs
1016 ((pos (point)) next-pos id-start id-end
1017 decl-res
1018 paren-depth
1019 id-face got-type got-init
1020 c-last-identifier-range
1021 (separator-prop (if types 'c-decl-type-start 'c-decl-id-start))
1022 brackets-after-id)
1024 ;; The following `while' fontifies a single declarator id each time round.
1025 ;; It loops only when LIST is non-nil.
1026 (while
1027 (and pos (setq decl-res (c-forward-declarator limit)))
1028 (setq next-pos (point)
1029 id-start (car decl-res)
1030 id-face (if (and (eq (char-after) ?\()
1031 (or (not (c-major-mode-is 'c++-mode))
1032 (not not-top)
1033 (car (cddr (cddr decl-res))) ; Id is in
1034 ; parens, etc.
1035 (save-excursion
1036 (forward-char)
1037 (c-forward-syntactic-ws)
1038 (looking-at "[*&]")))
1039 (not (car (cddr decl-res))) ; brackets-after-id
1040 (or (not (c-major-mode-is 'c++-mode))
1041 (save-excursion
1042 (let (c-last-identifier-range)
1043 (forward-char)
1044 (c-forward-syntactic-ws)
1045 (catch 'is-function
1046 (while
1047 (progn
1048 (if (eq (char-after) ?\))
1049 (throw 'is-function t))
1050 (setq got-type (c-forward-type))
1051 (cond
1052 ((null got-type)
1053 (throw 'is-function nil))
1054 ((not (eq got-type 'maybe))
1055 (throw 'is-function t)))
1056 (c-forward-declarator limit t)
1057 (eq (char-after) ?,))
1058 (forward-char)
1059 (c-forward-syntactic-ws))
1060 t)))))
1061 'font-lock-function-name-face
1062 'font-lock-variable-name-face)
1063 got-init (and (cadr (cddr decl-res)) ; got-init
1064 (char-after)))
1066 (if types
1067 ;; Register and fontify the identifier as a type.
1068 (let ((c-promote-possible-types t))
1069 (goto-char id-start)
1070 (c-forward-type))
1071 ;; Fontify the last symbol in the identifier if it isn't fontified
1072 ;; already. The check is necessary only in certain cases where this
1073 ;; function is used "sloppily", e.g. in `c-simple-decl-matchers'.
1074 (when (and c-last-identifier-range
1075 (not (get-text-property (car c-last-identifier-range)
1076 'face)))
1077 (c-put-font-lock-face (car c-last-identifier-range)
1078 (cdr c-last-identifier-range)
1079 id-face)))
1081 (goto-char next-pos)
1082 (setq pos nil) ; So as to terminate the enclosing `while' form.
1083 (when list
1084 ;; Jump past any initializer or function prototype to see if
1085 ;; there's a ',' to continue at.
1086 (cond ((eq id-face 'font-lock-function-name-face)
1087 ;; Skip a parenthesized initializer (C++) or a function
1088 ;; prototype.
1089 (if (c-safe (c-forward-sexp 1) t) ; over the parameter list.
1090 (c-forward-syntactic-ws limit)
1091 (goto-char limit))) ; unbalanced parens
1093 (got-init ; "=" sign OR opening "(", "[", or "{"
1094 ;; Skip an initializer expression. If we're at a '='
1095 ;; then accept a brace list directly after it to cope
1096 ;; with array initializers. Otherwise stop at braces
1097 ;; to avoid going past full function and class blocks.
1098 (and (if (and (eq got-init ?=)
1099 (= (c-forward-token-2 1 nil limit) 0)
1100 (looking-at "{"))
1101 (c-safe (c-forward-sexp) t) ; over { .... }
1103 (< (point) limit)
1104 ;; FIXME: Should look for c-decl-end markers here;
1105 ;; we might go far into the following declarations
1106 ;; in e.g. ObjC mode (see e.g. methods-4.m).
1107 (c-syntactic-re-search-forward "[;,{]" limit 'move t)
1108 (backward-char)))
1110 (t (c-forward-syntactic-ws limit)))
1112 ;; If a ',' is found we set pos to the next declarator and iterate.
1113 (when (and (< (point) limit) (looking-at ","))
1114 (c-put-char-property (point) 'c-type separator-prop)
1115 (forward-char)
1116 (c-forward-syntactic-ws limit)
1117 (setq pos (point)))))) ; acts to make the `while' form continue.
1118 nil)
1120 (defun c-get-fontification-context (match-pos not-front-decl &optional toplev)
1121 ;; Return a cons (CONTEXT . RESTRICTED-<>-ARGLISTS) for MATCH-POS.
1122 ;; NOT-FRONT-DECL is non-nil when a declaration later in the buffer than
1123 ;; MATCH-POS has already been parsed. TOPLEV is non-nil when MATCH-POS is
1124 ;; known to be at "top level", i.e. outside any braces, or directly inside a
1125 ;; namespace, class, etc.
1127 ;; CONTEXT is the fontification context of MATCH-POS, and is one of the
1128 ;; following:
1129 ;; 'decl In a comma-separated declaration context (typically
1130 ;; inside a function declaration arglist).
1131 ;; '<> In an angle bracket arglist.
1132 ;; 'arglist Some other type of arglist.
1133 ;; 'top Some other context and point is at the top-level (either
1134 ;; outside any braces or directly inside a class or namespace,
1135 ;; etc.)
1136 ;; nil Some other context or unknown context. Includes
1137 ;; within the parens of an if, for, ... construct.
1138 ;; 'not-decl Definitely not in a declaration.
1140 ;; RESTRICTED-<>-ARGLISTS is non-nil when a scan of template/generic
1141 ;; arguments lists (i.e. lists enclosed by <...>) is more strict about what
1142 ;; characters it allows within the list.
1143 (let ((type (and (> match-pos (point-min))
1144 (c-get-char-property (1- match-pos) 'c-type))))
1145 (cond ((not (memq (char-before match-pos) '(?\( ?, ?\[ ?< ?{)))
1146 (cons (and toplev 'top) nil))
1147 ;; A control flow expression or a decltype
1148 ((and (eq (char-before match-pos) ?\()
1149 (save-excursion
1150 (goto-char match-pos)
1151 (backward-char)
1152 (c-backward-token-2)
1153 (or (looking-at c-block-stmt-2-key)
1154 (looking-at c-block-stmt-1-2-key)
1155 (looking-at c-typeof-key))))
1156 (cons nil t))
1157 ;; Near BOB.
1158 ((<= match-pos (point-min))
1159 (cons 'arglist t))
1160 ;; Got a cached hit in a declaration arglist.
1161 ((eq type 'c-decl-arg-start)
1162 (cons 'decl nil))
1163 ;; We're inside (probably) a brace list.
1164 ((eq type 'c-not-decl)
1165 (cons 'not-decl nil))
1166 ;; Inside a C++11 lambda function arglist.
1167 ((and (c-major-mode-is 'c++-mode)
1168 (eq (char-before match-pos) ?\()
1169 (save-excursion
1170 (goto-char match-pos)
1171 (c-backward-token-2)
1172 (and
1173 (c-safe (goto-char (scan-sexps (point) -1)))
1174 (c-looking-at-c++-lambda-capture-list))))
1175 (c-put-char-property (1- match-pos) 'c-type
1176 'c-decl-arg-start)
1177 (cons 'decl nil))
1178 ;; We're inside a brace list.
1179 ((and (eq (char-before match-pos) ?{)
1180 (save-excursion
1181 (goto-char (1- match-pos))
1182 (consp
1183 (c-looking-at-or-maybe-in-bracelist))))
1184 (c-put-char-property (1- match-pos) 'c-type
1185 'c-not-decl)
1186 (cons 'not-decl nil))
1187 ;; We're inside an "ordinary" open brace.
1188 ((eq (char-before match-pos) ?{)
1189 (cons (and toplev 'top) nil))
1190 ;; Inside an angle bracket arglist.
1191 ((or (eq type 'c-<>-arg-sep)
1192 (eq (char-before match-pos) ?<))
1193 (cons '<> nil))
1194 ;; Got a cached hit in some other type of arglist.
1195 (type
1196 (cons 'arglist t))
1197 (not-front-decl
1198 ;; The point is within the range of a previously
1199 ;; encountered type decl expression, so the arglist
1200 ;; is probably one that contains declarations.
1201 ;; However, if `c-recognize-paren-inits' is set it
1202 ;; might also be an initializer arglist.
1204 ;; The result of this check is cached with a char
1205 ;; property on the match token, so that we can look
1206 ;; it up again when refontifying single lines in a
1207 ;; multiline declaration.
1208 (c-put-char-property (1- match-pos)
1209 'c-type 'c-decl-arg-start)
1210 (cons 'decl nil))
1211 ;; Got an open paren preceded by an arith operator.
1212 ((and (eq (char-before match-pos) ?\()
1213 (save-excursion
1214 (and (zerop (c-backward-token-2 2))
1215 (looking-at c-arithmetic-op-regexp))))
1216 (cons nil nil))
1217 ;; At start of a declaration inside a declaration paren.
1218 ((save-excursion
1219 (and (memq (char-before match-pos) '(?\( ?\,))
1220 (c-go-up-list-backward match-pos)
1221 (eq (char-after) ?\()
1222 (let ((type (c-get-char-property (point) 'c-type)))
1223 (or (memq type '(c-decl-arg-start c-decl-type-start))
1224 (and
1225 (progn (c-backward-syntactic-ws) t)
1226 (c-back-over-compound-identifier)
1227 (progn
1228 (c-backward-syntactic-ws)
1229 (or (bobp)
1230 (progn
1231 (setq type (c-get-char-property (1- (point))
1232 'c-type))
1233 (memq type '(c-decl-arg-start
1234 c-decl-type-start))))))))))
1235 (cons 'decl nil))
1236 (t (cons 'arglist t)))))
1238 (defun c-font-lock-declarations (limit)
1239 ;; Fontify all the declarations, casts and labels from the point to LIMIT.
1240 ;; Assumes that strings and comments have been fontified already.
1242 ;; This function will be called from font-lock for a region bounded by POINT
1243 ;; and LIMIT, as though it were to identify a keyword for
1244 ;; font-lock-keyword-face. It always returns NIL to inhibit this and
1245 ;; prevent a repeat invocation. See elisp/lispref page "Search-based
1246 ;; Fontification".
1248 ;; This function might do hidden buffer changes.
1250 ;;(message "c-font-lock-declarations search from %s to %s" (point) limit)
1252 (save-restriction
1253 (let (;; The position where `c-find-decl-spots' last stopped.
1254 start-pos
1255 ;; o - 'decl if we're in an arglist containing declarations
1256 ;; (but if `c-recognize-paren-inits' is set it might also be
1257 ;; an initializer arglist);
1258 ;; o - '<> if the arglist is of angle bracket type;
1259 ;; o - 'arglist if it's some other arglist;
1260 ;; o - nil, if not in an arglist at all. This includes the
1261 ;; parenthesized condition which follows "if", "while", etc.
1262 context
1263 ;; A list of starting positions of possible type declarations, or of
1264 ;; the typedef preceding one, if any.
1265 last-cast-end
1266 ;; The result from `c-forward-decl-or-cast-1'.
1267 decl-or-cast
1268 ;; The maximum of the end positions of all the checked type
1269 ;; decl expressions in the successfully identified
1270 ;; declarations. The position might be either before or
1271 ;; after the syntactic whitespace following the last token
1272 ;; in the type decl expression.
1273 (max-type-decl-end 0)
1274 ;; Same as `max-type-decl-*', but used when we're before
1275 ;; `token-pos'.
1276 (max-type-decl-end-before-token 0)
1277 ;; End of <..> construct which has had c-<>-arg-sep c-type
1278 ;; properties set within it.
1279 (max-<>-end 0)
1280 ;; Set according to the context to direct the heuristics for
1281 ;; recognizing C++ templates.
1282 c-restricted-<>-arglists
1283 ;; Turn on recording of identifier ranges in
1284 ;; `c-forward-decl-or-cast-1' and `c-forward-label' for
1285 ;; later fontification.
1286 (c-record-type-identifiers t)
1287 label-type
1288 c-record-ref-identifiers
1289 ;; Make `c-forward-type' calls mark up template arglists if
1290 ;; it finds any. That's necessary so that we later will
1291 ;; stop inside them to fontify types there.
1292 (c-parse-and-markup-<>-arglists t)
1293 lbrace ; position of some {.
1294 ;; The font-lock package in Emacs is known to clobber
1295 ;; `parse-sexp-lookup-properties' (when it exists).
1296 (parse-sexp-lookup-properties
1297 (cc-eval-when-compile
1298 (boundp 'parse-sexp-lookup-properties))
1301 ;; Below we fontify a whole declaration even when it crosses the limit,
1302 ;; to avoid gaps when jit/lazy-lock fontifies the file a block at a
1303 ;; time. That is however annoying during editing, e.g. the following is
1304 ;; a common situation while the first line is being written:
1306 ;; my_variable
1307 ;; some_other_variable = 0;
1309 ;; font-lock will put the limit at the beginning of the second line
1310 ;; here, and if we go past it we'll fontify "my_variable" as a type and
1311 ;; "some_other_variable" as an identifier, and the latter will not
1312 ;; correct itself until the second line is changed. To avoid that we
1313 ;; narrow to the limit if the region to fontify is a single line.
1314 (if (<= limit (c-point 'bonl))
1315 (narrow-to-region
1316 (point-min)
1317 (save-excursion
1318 ;; Narrow after any operator chars following the limit though,
1319 ;; since those characters can be useful in recognizing a
1320 ;; declaration (in particular the '{' that opens a function body
1321 ;; after the header).
1322 (goto-char limit)
1323 (skip-chars-forward c-nonsymbol-chars)
1324 (point))))
1326 (c-find-decl-spots
1327 limit
1328 c-decl-start-re
1329 (eval c-maybe-decl-faces)
1331 (lambda (match-pos inside-macro &optional toplev)
1332 ;; Note to maintainers: don't use `limit' inside this lambda form;
1333 ;; c-find-decl-spots sometimes narrows to less than `limit'.
1334 (setq start-pos (point))
1335 (when
1336 ;; The result of the form below is true when we don't recognize a
1337 ;; declaration or cast, and we don't recognize a "non-decl",
1338 ;; typically a brace list.
1339 (if (or (and (eq (get-text-property (point) 'face)
1340 'font-lock-keyword-face)
1341 (looking-at c-not-decl-init-keywords))
1342 (and c-macro-with-semi-re
1343 (looking-at c-macro-with-semi-re))) ; 2008-11-04
1344 ;; Don't do anything more if we're looking at a keyword that
1345 ;; can't start a declaration.
1348 ;; Set `context' and `c-restricted-<>-arglists'. Look for
1349 ;; "<" for the sake of C++-style template arglists.
1350 ;; Ignore "(" when it's part of a control flow construct
1351 ;; (e.g. "for (").
1352 (let ((got-context
1353 (c-get-fontification-context
1354 match-pos
1355 (< match-pos (if inside-macro
1356 max-type-decl-end-before-token
1357 max-type-decl-end))
1358 toplev)))
1359 (setq context (car got-context)
1360 c-restricted-<>-arglists (cdr got-context)))
1362 ;; Check we haven't missed a preceding "typedef".
1363 (when (not (looking-at c-typedef-key))
1364 (c-backward-syntactic-ws)
1365 (c-backward-token-2)
1366 (or (looking-at c-typedef-key)
1367 (goto-char start-pos)))
1369 ;; In QT, "more" is an irritating keyword that expands to nothing.
1370 ;; We skip over it to prevent recognition of "more slots: <symbol>"
1371 ;; as a bitfield declaration.
1372 (when (and (c-major-mode-is 'c++-mode)
1373 (looking-at
1374 (concat "\\(more\\)\\([^" c-symbol-chars "]\\|$\\)")))
1375 (goto-char (match-end 1))
1376 (c-forward-syntactic-ws))
1378 ;; Now analyze the construct.
1379 (if (eq context 'not-decl)
1380 (progn
1381 (setq decl-or-cast nil)
1382 (if (c-syntactic-re-search-forward
1383 "," (min limit (point-max)) 'at-limit t)
1384 (c-put-char-property (1- (point)) 'c-type 'c-not-decl))
1385 nil)
1386 (setq decl-or-cast
1387 (c-forward-decl-or-cast-1
1388 match-pos context last-cast-end))
1390 ;; Ensure that c-<>-arg-sep c-type properties are in place on the
1391 ;; commas separating the arguments inside template/generic <..>s.
1392 (when (and (eq (char-before match-pos) ?<)
1393 (> match-pos max-<>-end))
1394 (save-excursion
1395 (goto-char match-pos)
1396 (c-backward-token-2)
1397 (if (and
1398 (eq (char-after) ?<)
1399 (let ((c-restricted-<>-arglists
1400 (save-excursion
1401 (c-backward-token-2)
1402 (and
1403 (not (looking-at c-opt-<>-sexp-key))
1404 (progn (c-backward-syntactic-ws)
1405 (memq (char-before) '(?\( ?,)))
1406 (not (eq (c-get-char-property (1- (point))
1407 'c-type)
1408 'c-decl-arg-start))))))
1409 (c-forward-<>-arglist nil)))
1410 (setq max-<>-end (point)))))
1412 (cond
1413 ((eq decl-or-cast 'cast)
1414 ;; Save the position after the previous cast so we can feed
1415 ;; it to `c-forward-decl-or-cast-1' in the next round. That
1416 ;; helps it discover cast chains like "(a) (b) c".
1417 (setq last-cast-end (point))
1418 (c-fontify-recorded-types-and-refs)
1419 nil)
1421 (decl-or-cast
1422 ;; We've found a declaration.
1424 ;; Set `max-type-decl-end' or `max-type-decl-end-before-token'
1425 ;; under the assumption that we're after the first type decl
1426 ;; expression in the declaration now. That's not really true;
1427 ;; we could also be after a parenthesized initializer
1428 ;; expression in C++, but this is only used as a last resort
1429 ;; to slant ambiguous expression/declarations, and overall
1430 ;; it's worth the risk to occasionally fontify an expression
1431 ;; as a declaration in an initializer expression compared to
1432 ;; getting ambiguous things in normal function prototypes
1433 ;; fontified as expressions.
1434 (if inside-macro
1435 (when (> (point) max-type-decl-end-before-token)
1436 (setq max-type-decl-end-before-token (point)))
1437 (when (> (point) max-type-decl-end)
1438 (setq max-type-decl-end (point))))
1440 ;; Do we have an expression as the second or third clause of
1441 ;; a "for" paren expression?
1442 (if (save-excursion
1443 (and
1444 (car (cddr decl-or-cast)) ; maybe-expression flag.
1445 (goto-char start-pos)
1446 (c-go-up-list-backward)
1447 (eq (char-after) ?\()
1448 (progn (c-backward-syntactic-ws)
1449 (c-simple-skip-symbol-backward))
1450 (looking-at c-paren-stmt-key)
1451 (progn (goto-char match-pos)
1452 (while (and (eq (char-before) ?\))
1453 (c-go-list-backward))
1454 (c-backward-syntactic-ws))
1455 (eq (char-before) ?\;))))
1456 ;; We've got an expression in "for" parens. Remove the
1457 ;; "type" that would spuriously get fontified.
1458 (let ((elt (and (consp c-record-type-identifiers)
1459 (assq (cadr (cddr decl-or-cast))
1460 c-record-type-identifiers))))
1461 (when elt
1462 (setq c-record-type-identifiers
1463 (c-delq-from-dotted-list
1464 elt c-record-type-identifiers)))
1466 ;; Back up to the type to fontify the declarator(s).
1467 (goto-char (car decl-or-cast))
1469 (let ((decl-list
1470 (if (not (memq context '(nil top)))
1471 ;; Should normally not fontify a list of
1472 ;; declarators inside an arglist, but the first
1473 ;; argument in the ';' separated list of a "for"
1474 ;; statement is an exception.
1475 (when (eq (char-before match-pos) ?\()
1476 (save-excursion
1477 (goto-char (1- match-pos))
1478 (c-backward-syntactic-ws)
1479 (and (c-simple-skip-symbol-backward)
1480 (looking-at c-paren-stmt-key))))
1481 t)))
1483 ;; Fix the `c-decl-id-start' or `c-decl-type-start' property
1484 ;; before the first declarator if it's a list.
1485 ;; `c-font-lock-declarators' handles the rest.
1486 (when decl-list
1487 (save-excursion
1488 (c-backward-syntactic-ws)
1489 (unless (bobp)
1490 (c-put-char-property (1- (point)) 'c-type
1491 (if (cadr decl-or-cast)
1492 'c-decl-type-start
1493 'c-decl-id-start)))))
1495 (c-font-lock-declarators
1496 (min limit (point-max)) decl-list
1497 (cadr decl-or-cast) (not toplev)))
1499 ;; A declaration has been successfully identified, so do all the
1500 ;; fontification of types and refs that've been recorded.
1501 (c-fontify-recorded-types-and-refs)
1502 nil))
1504 (t t))))
1506 ;; It was a false alarm. Check if we're in a label (or other
1507 ;; construct with `:' except bitfield) instead.
1508 (goto-char start-pos)
1509 (when (setq label-type (c-forward-label t match-pos nil))
1510 ;; Can't use `c-fontify-types-and-refs' here since we
1511 ;; use the label face at times.
1512 (cond ((eq label-type 'goto-target)
1513 (c-put-font-lock-face (caar c-record-ref-identifiers)
1514 (cdar c-record-ref-identifiers)
1515 c-label-face-name))
1516 ((eq label-type 'qt-1kwd-colon)
1517 (c-put-font-lock-face (caar c-record-ref-identifiers)
1518 (cdar c-record-ref-identifiers)
1519 'font-lock-keyword-face))
1520 ((eq label-type 'qt-2kwds-colon)
1521 (mapc
1522 (lambda (kwd)
1523 (c-put-font-lock-face (car kwd) (cdr kwd)
1524 'font-lock-keyword-face))
1525 c-record-ref-identifiers)))
1526 (setq c-record-ref-identifiers nil)
1527 ;; `c-forward-label' has probably added a `c-decl-end'
1528 ;; marker, so return t to `c-find-decl-spots' to signal
1529 ;; that.
1530 t))))
1532 nil)))
1534 (defun c-font-lock-enum-body (limit)
1535 ;; Fontify the identifiers of each enum we find by searching forward.
1537 ;; This function will be called from font-lock for a region bounded by POINT
1538 ;; and LIMIT, as though it were to identify a keyword for
1539 ;; font-lock-keyword-face. It always returns NIL to inhibit this and
1540 ;; prevent a repeat invocation. See elisp/lispref page "Search-based
1541 ;; Fontification".
1542 (while (search-forward-regexp c-enum-clause-introduction-re limit t)
1543 (when (save-excursion
1544 (backward-char)
1545 (c-backward-over-enum-header))
1546 (c-forward-syntactic-ws)
1547 (c-font-lock-declarators limit t nil t)))
1548 nil)
1550 (defun c-font-lock-enum-tail (limit)
1551 ;; Fontify an enum's identifiers when POINT is within the enum's brace
1552 ;; block.
1554 ;; This function will be called from font-lock for a region bounded by POINT
1555 ;; and LIMIT, as though it were to identify a keyword for
1556 ;; font-lock-keyword-face. It always returns NIL to inhibit this and
1557 ;; prevent a repeat invocation. See elisp/lispref page "Search-based
1558 ;; Fontification".
1560 ;; Note that this function won't attempt to fontify beyond the end of the
1561 ;; current enum block, if any.
1562 (let* ((paren-state (c-parse-state))
1563 (encl-pos (c-most-enclosing-brace paren-state)))
1564 (when (and
1565 encl-pos
1566 (eq (char-after encl-pos) ?\{)
1567 (save-excursion
1568 (goto-char encl-pos)
1569 (c-backward-over-enum-header)))
1570 (c-syntactic-skip-backward "^{," nil t)
1571 (c-put-char-property (1- (point)) 'c-type 'c-decl-id-start)
1573 (c-forward-syntactic-ws)
1574 (c-font-lock-declarators limit t nil t)))
1575 nil)
1577 (defun c-font-lock-cut-off-declarators (limit)
1578 ;; Fontify any declarators "cut off" from their declaring type at the start
1579 ;; of the region being fontified.
1581 ;; This function will be called from font-lock- for a region bounded by
1582 ;; POINT and LIMIT, as though it were to identify a keyword for
1583 ;; font-lock-keyword-face. It always returns NIL to inhibit this and
1584 ;; prevent a repeat invocation. See elisp/lispref page "Search-based
1585 ;; fontification".
1586 (let ((decl-search-lim (c-determine-limit 1000))
1587 paren-state bod-res is-typedef encl-pos
1588 (here (point))
1589 c-recognize-knr-p) ; Strictly speaking, bogus, but it
1590 ; speeds up lisp.h tremendously.
1591 (save-excursion
1592 (when (not (c-back-over-member-initializers))
1593 (unless (or (eobp)
1594 (looking-at "\\s(\\|\\s)"))
1595 (forward-char))
1596 (c-syntactic-skip-backward "^;{}" decl-search-lim t)
1597 (when (eq (char-before) ?})
1598 (c-go-list-backward) ; brace block of struct, etc.?
1599 (c-syntactic-skip-backward "^;{}" decl-search-lim t))
1600 (when (or (bobp)
1601 (memq (char-before) '(?\; ?{ ?})))
1602 (c-forward-syntactic-ws)
1603 ;; We're now putatively at the declaration.
1604 (setq paren-state (c-parse-state))
1605 ;; At top level or inside a "{"?
1606 (if (or (not (setq encl-pos
1607 (c-most-enclosing-brace paren-state)))
1608 (eq (char-after encl-pos) ?\{))
1609 (progn
1610 (when (looking-at c-typedef-key) ; "typedef"
1611 (setq is-typedef t)
1612 (goto-char (match-end 0))
1613 (c-forward-syntactic-ws))
1614 ;; At a real declaration?
1615 (if (memq (c-forward-type t) '(t known found decltype))
1616 (c-font-lock-declarators
1617 limit t is-typedef (not (c-bs-at-toplevel-p here)))))))))
1618 nil))
1620 (defun c-font-lock-enclosing-decls (limit)
1621 ;; Fontify the declarators of (nested) declarations we're in the middle of.
1622 ;; This is mainly for when a jit-lock etc. chunk starts inside the brace
1623 ;; block of a struct/union/class, etc.
1625 ;; This function will be called from font-lock for a region bounded by POINT
1626 ;; and LIMIT, as though it were to identify a keyword for
1627 ;; font-lock-keyword-face. It always returns NIL to inhibit this and
1628 ;; prevent a repeat invocation. See elisp/lispref page "Search-based
1629 ;; Fontification".
1630 (let* ((paren-state (c-parse-state))
1631 (decl-search-lim (c-determine-limit 1000))
1632 in-typedef ps-elt)
1633 ;; Are we in any nested struct/union/class/etc. braces?
1634 (while paren-state
1635 (setq ps-elt (car paren-state)
1636 paren-state (cdr paren-state))
1637 (when (and (atom ps-elt)
1638 (eq (char-after ps-elt) ?\{))
1639 (goto-char ps-elt)
1640 (c-syntactic-skip-backward "^;{}" decl-search-lim)
1641 (when (or (bobp)
1642 (memq (char-before) '(?\; ?})))
1643 (c-forward-syntactic-ws)
1644 (setq in-typedef (looking-at c-typedef-key))
1645 (if in-typedef (c-forward-token-2))
1646 (when (and c-opt-block-decls-with-vars-key
1647 (looking-at c-opt-block-decls-with-vars-key))
1648 (goto-char ps-elt)
1649 (when (c-safe (c-forward-sexp))
1650 (c-forward-syntactic-ws)
1651 (c-font-lock-declarators limit t in-typedef
1652 (not (c-bs-at-toplevel-p (point)))))))))))
1654 (defun c-font-lock-raw-strings (limit)
1655 ;; Fontify C++ raw strings.
1657 ;; This function will be called from font-lock for a region bounded by POINT
1658 ;; and LIMIT, as though it were to identify a keyword for
1659 ;; font-lock-keyword-face. It always returns NIL to inhibit this and
1660 ;; prevent a repeat invocation. See elisp/lispref page "Search-based
1661 ;; Fontification".
1662 (let* ((state (c-state-semi-pp-to-literal (point)))
1663 (string-start (and (eq (cadr state) 'string)
1664 (car (cddr state))))
1665 (raw-id (and string-start
1666 (save-excursion
1667 (goto-char string-start)
1668 (and (eq (char-before) ?R)
1669 (looking-at "\"\\([^ ()\\\n\r\t]\\{0,16\\}\\)(")
1670 (match-string-no-properties 1))))))
1671 (while (< (point) limit)
1672 (if raw-id
1673 (progn
1674 (if (search-forward-regexp (concat ")\\(" (regexp-quote raw-id) "\\)\"")
1675 limit 'limit)
1676 (c-put-font-lock-face (match-beginning 1) (point) 'default))
1677 (setq raw-id nil))
1679 (when (search-forward-regexp
1680 "R\\(\"\\)\\([^ ()\\\n\r\t]\\{0,16\\}\\)(" limit 'limit)
1681 (when
1682 (or (and (eobp)
1683 (eq (c-get-char-property (1- (point)) 'face)
1684 'font-lock-warning-face))
1685 (eq (c-get-char-property (point) 'face) 'font-lock-string-face)
1686 (and (equal (c-get-char-property (match-end 2) 'syntax-table) '(1))
1687 (equal (c-get-char-property (match-beginning 1) 'syntax-table)
1688 '(1))))
1689 (let ((paren-prop (c-get-char-property (1- (point)) 'syntax-table)))
1690 (if paren-prop
1691 (progn
1692 (c-put-font-lock-face (match-beginning 0) (match-end 0)
1693 'font-lock-warning-face)
1694 (when
1695 (and
1696 (equal paren-prop '(15))
1697 (not (c-search-forward-char-property 'syntax-table '(15) limit)))
1698 (goto-char limit)))
1699 (c-put-font-lock-face (match-beginning 1) (match-end 2) 'default)
1700 (setq raw-id (match-string-no-properties 2)))))))))
1701 nil)
1703 (defun c-font-lock-c++-lambda-captures (limit)
1704 ;; Fontify the lambda capture component of C++ lambda declarations.
1706 ;; This function will be called from font-lock for a region bounded by POINT
1707 ;; and LIMIT, as though it were to identify a keyword for
1708 ;; font-lock-keyword-face. It always returns NIL to inhibit this and
1709 ;; prevent a repeat invocation. See elisp/lispref page "Search-based
1710 ;; Fontification".
1711 (let (mode capture-default id-start id-end declaration sub-begin sub-end)
1712 (while (and (< (point) limit)
1713 (search-forward "[" limit t))
1714 (when (progn (backward-char)
1715 (prog1
1716 (c-looking-at-c++-lambda-capture-list)
1717 (forward-char)))
1718 (c-forward-syntactic-ws)
1719 (setq mode (and (memq (char-after) '(?= ?&))
1720 (char-after)))
1721 ;; Is the first element of the list a bare "=" or "&"?
1722 (when mode
1723 (forward-char)
1724 (c-forward-syntactic-ws)
1725 (if (memq (char-after) '(?, ?\]))
1726 (progn
1727 (setq capture-default mode)
1728 (when (eq (char-after) ?,)
1729 (forward-char)
1730 (c-forward-syntactic-ws)))
1731 (c-backward-token-2)))
1733 ;; Go round the following loop once per captured item. We use "\\s)"
1734 ;; rather than "\\]" here to avoid infinite looping in this situation:
1735 ;; "unsigned items [] { [ }". The second "[" triggers this function,
1736 ;; but if we don't match the "}" with an "\\s)", the
1737 ;; `c-syntactic-re-search-forward' at the end of the loop fails to
1738 ;; move forward over it, leaving point stuck at the "}".
1739 (while (and (not (looking-at "\\s)"))
1740 (< (point) limit))
1741 (if (eq (char-after) ?&)
1742 (progn (setq mode ?&)
1743 (forward-char)
1744 (c-forward-syntactic-ws))
1745 (setq mode ?=))
1746 (if (c-on-identifier)
1747 (progn
1748 (setq id-start (point))
1749 (forward-char)
1750 (c-end-of-current-token)
1751 (setq id-end (point))
1752 (c-forward-syntactic-ws)
1754 (setq declaration (eq (char-after) ?=))
1755 (when declaration
1756 (forward-char) ; over "="
1757 (c-forward-syntactic-ws)
1758 (setq sub-begin (point)))
1759 (if (or (and (< (point) limit)
1760 (c-syntactic-re-search-forward "," limit t t))
1761 (and (c-go-up-list-forward nil limit)
1762 (eq (char-before) ?\])))
1763 (backward-char)
1764 (goto-char limit))
1765 (when declaration
1766 (save-excursion
1767 (setq sub-end (point))
1768 (goto-char sub-begin)
1769 (c-font-lock-c++-lambda-captures sub-end)))
1771 (c-put-font-lock-face id-start id-end
1772 (cond
1773 (declaration
1774 'font-lock-variable-name-face)
1775 ((and capture-default
1776 (eq mode capture-default))
1777 'font-lock-warning-face)
1778 ((eq mode ?=) font-lock-constant-face)
1779 (t 'font-lock-variable-name-face))))
1780 (c-syntactic-re-search-forward "," limit 'bound t))
1782 (c-forward-syntactic-ws)
1783 (when (eq (char-after) ?,)
1784 (forward-char)
1785 (c-forward-syntactic-ws)))
1787 (setq capture-default nil)
1788 (if (< (point) limit)
1789 (forward-char))))) ; over the terminating "]" or other close paren.
1790 nil)
1793 (c-lang-defconst c-simple-decl-matchers
1794 "Simple font lock matchers for types and declarations. These are used
1795 on level 2 only and so aren't combined with `c-complex-decl-matchers'."
1797 t `(;; Objective-C methods.
1798 ,@(when (c-major-mode-is 'objc-mode)
1799 `((,(c-lang-const c-opt-method-key)
1800 (,(byte-compile
1801 (lambda (limit)
1802 (let (;; The font-lock package in Emacs is known to clobber
1803 ;; `parse-sexp-lookup-properties' (when it exists).
1804 (parse-sexp-lookup-properties
1805 (cc-eval-when-compile
1806 (boundp 'parse-sexp-lookup-properties))))
1807 (save-restriction
1808 (narrow-to-region (point-min) limit)
1809 (c-font-lock-objc-method)))
1810 nil))
1811 (goto-char (match-end 1))))))
1813 ;; Fontify all type names and the identifiers in the
1814 ;; declarations they might start. Use eval here since
1815 ;; `c-known-type-key' gets its value from
1816 ;; `*-font-lock-extra-types' on mode init.
1817 (eval . (list ,(c-make-font-lock-search-function
1818 'c-known-type-key
1819 '(1 'font-lock-type-face t)
1820 '((c-font-lock-declarators limit t nil nil)
1821 (save-match-data
1822 (goto-char (match-end 1))
1823 (c-forward-syntactic-ws))
1824 (goto-char (match-end 1))))))
1826 ;; Fontify types preceded by `c-type-prefix-kwds' and the
1827 ;; identifiers in the declarations they might start.
1828 ,@(when (c-lang-const c-type-prefix-kwds)
1829 (let* ((prefix-re (c-make-keywords-re nil
1830 (c-lang-const c-type-prefix-kwds)))
1831 (type-match (+ 2
1832 (regexp-opt-depth prefix-re)
1833 (c-lang-const c-simple-ws-depth))))
1834 `((,(c-make-font-lock-search-function
1835 (concat "\\<\\(" prefix-re "\\)" ; 1
1836 (c-lang-const c-simple-ws) "+"
1837 (concat "\\(" ; 2 + prefix-re + c-simple-ws
1838 (c-lang-const c-symbol-key)
1839 "\\)"))
1840 `(,type-match
1841 'font-lock-type-face t)
1842 `((c-font-lock-declarators limit t nil nil)
1843 (save-match-data
1844 (goto-char (match-end ,type-match))
1845 (c-forward-syntactic-ws))
1846 (goto-char (match-end ,type-match))))))))
1848 ;; Fontify special declarations that lacks a type.
1849 ,@(when (c-lang-const c-typeless-decl-kwds)
1850 `((,(c-make-font-lock-search-function
1851 (concat "\\<\\("
1852 (regexp-opt (c-lang-const c-typeless-decl-kwds))
1853 "\\)\\>")
1854 '((c-font-lock-declarators limit t nil nil)
1855 (save-match-data
1856 (goto-char (match-end 1))
1857 (c-forward-syntactic-ws))
1858 (goto-char (match-end 1)))))))
1860 ;; Fontify generic colon labels in languages that support them.
1861 ,@(when (c-lang-const c-recognize-colon-labels)
1862 `(c-font-lock-labels))))
1864 (c-lang-defconst c-complex-decl-matchers
1865 "Complex font lock matchers for types and declarations. Used on level
1866 3 and higher."
1868 ;; Note: This code in this form dumps a number of functions into the
1869 ;; resulting constant, `c-matchers-3'. At run time, font lock will call
1870 ;; each of them as a "FUNCTION" (see Elisp page "Search-based
1871 ;; Fontification"). The font lock region is delimited by POINT and the
1872 ;; single parameter, LIMIT. Each of these functions returns NIL (thus
1873 ;; inhibiting spurious font-lock-keyword-face highlighting and another
1874 ;; call).
1876 t `(;; Initialize some things before the search functions below.
1877 c-font-lock-complex-decl-prepare
1879 ,@(if (c-major-mode-is 'objc-mode)
1880 ;; Fontify method declarations in Objective-C, but first
1881 ;; we have to put the `c-decl-end' `c-type' property on
1882 ;; all the @-style directives that haven't been handled in
1883 ;; `c-basic-matchers-before'.
1884 `(,(c-make-font-lock-search-function
1885 (c-make-keywords-re t
1886 ;; Exclude "@class" since that directive ends with a
1887 ;; semicolon anyway.
1888 (delete "@class"
1889 (append (c-lang-const c-protection-kwds)
1890 (c-lang-const c-other-decl-kwds)
1891 nil)))
1892 '((c-put-char-property (1- (match-end 1))
1893 'c-type 'c-decl-end)))
1894 c-font-lock-objc-methods))
1896 ;; Fontify declarators which have been cut off from their declaring
1897 ;; types at the start of the region.
1898 c-font-lock-cut-off-declarators
1900 ;; Fontify all declarations, casts and normal labels.
1901 c-font-lock-declarations
1903 ;; Fontify declarators when POINT is within their declaration.
1904 c-font-lock-enclosing-decls
1906 ;; Fontify angle bracket arglists like templates in C++.
1907 ,@(when (c-lang-const c-recognize-<>-arglists)
1908 `(c-font-lock-<>-arglists))
1910 ,@(when (c-major-mode-is 'c++-mode)
1911 `(c-font-lock-c++-lambda-captures))
1913 ;; The first two rules here mostly find occurrences that
1914 ;; `c-font-lock-declarations' has found already, but not
1915 ;; declarations containing blocks in the type (see note below).
1916 ;; It's also useful to fontify these everywhere to show e.g. when
1917 ;; a type keyword is accidentally used as an identifier.
1919 ;; Fontify basic types.
1920 ,(let ((re (c-make-keywords-re nil
1921 (c-lang-const c-primitive-type-kwds))))
1922 (if (c-major-mode-is 'pike-mode)
1923 ;; No symbol is a keyword after "->" in Pike.
1924 `(,(concat "\\(\\=.?\\|[^>]\\|[^-]>\\)"
1925 "\\<\\(" re "\\)\\>")
1926 2 font-lock-type-face)
1927 `(,(concat "\\<\\(" re "\\)\\>")
1928 1 'font-lock-type-face)))
1930 ;; Fontify types preceded by `c-type-prefix-kwds' (e.g. "struct").
1931 ,@(when (c-lang-const c-type-prefix-kwds)
1932 `((,(byte-compile
1933 `(lambda (limit)
1934 (c-fontify-types-and-refs
1935 ((c-promote-possible-types t)
1936 ;; The font-lock package in Emacs is known to clobber
1937 ;; `parse-sexp-lookup-properties' (when it exists).
1938 (parse-sexp-lookup-properties
1939 (cc-eval-when-compile
1940 (boundp 'parse-sexp-lookup-properties))))
1941 (save-restriction
1942 ;; Narrow to avoid going past the limit in
1943 ;; `c-forward-type'.
1944 (narrow-to-region (point) limit)
1945 (while (re-search-forward
1946 ,(concat "\\<\\("
1947 (c-make-keywords-re nil
1948 (c-lang-const c-type-prefix-kwds))
1949 "\\)\\>")
1950 limit t)
1951 (unless (c-skip-comments-and-strings limit)
1952 (c-forward-syntactic-ws)
1953 ;; Handle prefix declaration specifiers.
1954 (while
1956 (when (or (looking-at c-prefix-spec-kwds-re)
1957 (and (c-major-mode-is 'java-mode)
1958 (looking-at "@[A-Za-z0-9]+")))
1959 (c-forward-keyword-clause 1)
1961 (when (and c-opt-cpp-prefix
1962 (looking-at
1963 c-noise-macro-with-parens-name-re))
1964 (c-forward-noise-clause)
1965 t)))
1966 ,(if (c-major-mode-is 'c++-mode)
1967 `(when (and (c-forward-type)
1968 (eq (char-after) ?=))
1969 ;; In C++ we additionally check for a "class
1970 ;; X = Y" construct which is used in
1971 ;; templates, to fontify Y as a type.
1972 (forward-char)
1973 (c-forward-syntactic-ws)
1974 (c-forward-type))
1975 `(c-forward-type))
1976 )))))))))
1978 ;; Fontify symbols after closing braces as declaration
1979 ;; identifiers under the assumption that they are part of
1980 ;; declarations like "class Foo { ... } foo;". It's too
1981 ;; expensive to check this accurately by skipping past the
1982 ;; brace block, so we use the heuristic that it's such a
1983 ;; declaration if the first identifier is on the same line as
1984 ;; the closing brace. `c-font-lock-declarations' will later
1985 ;; override it if it turns out to be an new declaration, but
1986 ;; it will be wrong if it's an expression (see the test
1987 ;; decls-8.cc).
1988 ;; ,@(when (c-lang-const c-opt-block-decls-with-vars-key)
1989 ;; `((,(c-make-font-lock-search-function
1990 ;; (concat "}"
1991 ;; (c-lang-const c-single-line-syntactic-ws)
1992 ;; "\\(" ; 1 + c-single-line-syntactic-ws-depth
1993 ;; (c-lang-const c-type-decl-prefix-key)
1994 ;; "\\|"
1995 ;; (c-lang-const c-symbol-key)
1996 ;; "\\)")
1997 ;; `((c-font-lock-declarators limit t nil) ; That nil says use `font-lock-variable-name-face';
1998 ;; ; t would mean `font-lock-function-name-face'.
1999 ;; (progn
2000 ;; (c-put-char-property (match-beginning 0) 'c-type
2001 ;; 'c-decl-id-start)
2002 ;; ; 'c-decl-type-start)
2003 ;; (goto-char (match-beginning
2004 ;; ,(1+ (c-lang-const
2005 ;; c-single-line-syntactic-ws-depth)))))
2006 ;; (goto-char (match-end 0)))))))
2008 ;; Fontify the type in C++ "new" expressions.
2009 ,@(when (c-major-mode-is 'c++-mode)
2010 ;; This pattern is a probably a "(MATCHER . ANCHORED-HIGHLIGHTER)"
2011 ;; (see Elisp page "Search-based Fontification").
2012 `(("\\<new\\>"
2013 (c-font-lock-c++-new))))
2016 (defun c-font-lock-labels (limit)
2017 ;; Fontify all statement labels from the point to LIMIT. Assumes
2018 ;; that strings and comments have been fontified already. Nil is
2019 ;; always returned.
2021 ;; Note: This function is only used on decoration level 2; this is
2022 ;; taken care of directly by the gargantuan
2023 ;; `c-font-lock-declarations' on higher levels.
2025 ;; This function might do hidden buffer changes.
2027 (let (continue-pos id-start
2028 ;; The font-lock package in Emacs is known to clobber
2029 ;; `parse-sexp-lookup-properties' (when it exists).
2030 (parse-sexp-lookup-properties
2031 (cc-eval-when-compile
2032 (boundp 'parse-sexp-lookup-properties))))
2034 (while (re-search-forward ":[^:]" limit t)
2035 (setq continue-pos (point))
2036 (goto-char (match-beginning 0))
2037 (unless (c-skip-comments-and-strings limit)
2039 (c-backward-syntactic-ws)
2040 (and (setq id-start (c-on-identifier))
2042 (not (get-text-property id-start 'face))
2044 (progn
2045 (goto-char id-start)
2046 (c-backward-syntactic-ws)
2048 ;; Check for a char that precedes a statement.
2049 (memq (char-before) '(?\} ?\{ ?\;))
2050 ;; Check for a preceding label. We exploit the font
2051 ;; locking made earlier by this function.
2052 (and (eq (char-before) ?:)
2053 (progn
2054 (backward-char)
2055 (c-backward-syntactic-ws)
2056 (not (bobp)))
2057 (eq (get-text-property (1- (point)) 'face)
2058 c-label-face-name))
2059 ;; Check for a keyword that precedes a statement.
2060 (c-after-conditional)))
2062 (progn
2063 ;; Got a label.
2064 (goto-char id-start)
2065 (looking-at c-symbol-key)
2066 (c-put-font-lock-face (match-beginning 0) (match-end 0)
2067 c-label-face-name)))
2069 (goto-char continue-pos))))
2070 nil)
2072 (c-lang-defconst c-basic-matchers-after
2073 "Font lock matchers for various things that should be fontified after
2074 generic casts and declarations are fontified. Used on level 2 and
2075 higher."
2077 t `(,@(when (c-lang-const c-brace-list-decl-kwds)
2078 ;; Fontify the remaining identifiers inside an enum list when we start
2079 ;; inside it.
2080 `(c-font-lock-enum-tail
2081 ;; Fontify the identifiers inside enum lists. (The enum type
2082 ;; name is handled by `c-simple-decl-matchers' or
2083 ;; `c-complex-decl-matchers' below.
2084 c-font-lock-enum-body))
2086 ;; Fontify labels after goto etc.
2087 ,@(when (c-lang-const c-before-label-kwds)
2088 `(;; (Got three different interpretation levels here,
2089 ;; which makes it a bit complicated: 1) The backquote
2090 ;; stuff is expanded when compiled or loaded, 2) the
2091 ;; eval form is evaluated at font-lock setup (to
2092 ;; substitute c-label-face-name correctly), and 3) the
2093 ;; resulting structure is interpreted during
2094 ;; fontification.)
2095 (eval
2096 . ,(let* ((c-before-label-re
2097 (c-make-keywords-re nil
2098 (c-lang-const c-before-label-kwds))))
2099 `(list
2100 ,(concat "\\<\\(" c-before-label-re "\\)\\>"
2101 "\\s *"
2102 "\\(" ; identifier-offset
2103 (c-lang-const c-symbol-key)
2104 "\\)")
2105 (list ,(+ (regexp-opt-depth c-before-label-re) 2)
2106 c-label-face-name nil t))))))
2108 ;; Fontify the clauses after various keywords.
2109 ,@(when (or (c-lang-const c-type-list-kwds)
2110 (c-lang-const c-ref-list-kwds)
2111 (c-lang-const c-colon-type-list-kwds))
2112 `((,(c-make-font-lock-BO-decl-search-function
2113 (concat "\\<\\("
2114 (c-make-keywords-re nil
2115 (append (c-lang-const c-type-list-kwds)
2116 (c-lang-const c-ref-list-kwds)
2117 (c-lang-const c-colon-type-list-kwds)))
2118 "\\)\\>")
2119 '((c-fontify-types-and-refs ((c-promote-possible-types t))
2120 (c-forward-keyword-clause 1)
2121 (if (> (point) limit) (goto-char limit))))))))
2123 ,@(when (c-lang-const c-paren-type-kwds)
2124 `((,(c-make-font-lock-search-function
2125 (concat "\\<\\("
2126 (c-make-keywords-re nil
2127 (c-lang-const c-paren-type-kwds))
2128 "\\)\\>")
2129 '((c-fontify-types-and-refs ((c-promote-possible-types t))
2130 (c-forward-keyword-clause 1)
2131 (if (> (point) limit) (goto-char limit))))))))
2133 ,@(when (c-major-mode-is 'java-mode)
2134 `((eval . (list "\\<\\(@[a-zA-Z0-9]+\\)\\>" 1 c-annotation-face))))
2137 (c-lang-defconst c-matchers-1
2138 t (c-lang-const c-cpp-matchers))
2140 (c-lang-defconst c-matchers-2
2141 t (append (c-lang-const c-matchers-1)
2142 (c-lang-const c-basic-matchers-before)
2143 (c-lang-const c-simple-decl-matchers)
2144 (c-lang-const c-basic-matchers-after)))
2146 (c-lang-defconst c-matchers-3
2147 t (append (c-lang-const c-matchers-1)
2148 (c-lang-const c-basic-matchers-before)
2149 (c-lang-const c-complex-decl-matchers)
2150 (c-lang-const c-basic-matchers-after)))
2152 (defun c-compose-keywords-list (base-list)
2153 ;; Incorporate the font lock keyword lists according to
2154 ;; `c-doc-comment-style' on the given keyword list and return it.
2155 ;; This is used in the function bindings of the
2156 ;; `*-font-lock-keywords-*' symbols since we have to build the list
2157 ;; when font-lock is initialized.
2159 (unless (memq c-doc-face-name c-literal-faces)
2160 (setq c-literal-faces (cons c-doc-face-name c-literal-faces)))
2162 (let* ((doc-keywords
2163 (if (consp (car-safe c-doc-comment-style))
2164 (cdr-safe (or (assq c-buffer-is-cc-mode c-doc-comment-style)
2165 (assq 'other c-doc-comment-style)))
2166 c-doc-comment-style))
2167 (list (nconc (c--mapcan
2168 (lambda (doc-style)
2169 (let ((sym (intern
2170 (concat (symbol-name doc-style)
2171 "-font-lock-keywords"))))
2172 (cond ((fboundp sym)
2173 (funcall sym))
2174 ((boundp sym)
2175 (append (eval sym) nil)))))
2176 (if (listp doc-keywords)
2177 doc-keywords
2178 (list doc-keywords)))
2179 base-list)))
2181 ;; Kludge: If `c-font-lock-complex-decl-prepare' is on the list we
2182 ;; move it first since the doc comment font lockers might add
2183 ;; `c-type' text properties, so they have to be cleared before that.
2184 (when (memq 'c-font-lock-complex-decl-prepare list)
2185 (setq list (cons 'c-font-lock-complex-decl-prepare
2186 (delq 'c-font-lock-complex-decl-prepare
2187 (append list nil)))))
2189 list))
2191 (defun c-override-default-keywords (def-var)
2192 ;; This is used to override the value on a `*-font-lock-keywords'
2193 ;; variable only if it's nil or has the same value as one of the
2194 ;; `*-font-lock-keywords-*' variables. Older font-lock packages
2195 ;; define a default value for `*-font-lock-keywords' which we want
2196 ;; to override, but we should otoh avoid clobbering a user setting.
2197 ;; This heuristic for that isn't perfect, but I can't think of any
2198 ;; better. /mast
2199 (when (and (boundp def-var)
2200 (memq (symbol-value def-var)
2201 (cons nil
2202 (mapcar
2203 (lambda (suffix)
2204 (let ((sym (intern (concat (symbol-name def-var)
2205 suffix))))
2206 (and (boundp sym) (symbol-value sym))))
2207 '("-1" "-2" "-3")))))
2208 ;; The overriding is done by unbinding the variable so that the normal
2209 ;; defvar will install its default value later on.
2210 (makunbound def-var)))
2213 ;;; C.
2215 (c-override-default-keywords 'c-font-lock-keywords)
2217 (defconst c-font-lock-keywords-1 (c-lang-const c-matchers-1 c)
2218 "Minimal font locking for C mode.
2219 Fontifies only preprocessor directives (in addition to the syntactic
2220 fontification of strings and comments).")
2222 (defconst c-font-lock-keywords-2 (c-lang-const c-matchers-2 c)
2223 "Fast normal font locking for C mode.
2224 In addition to `c-font-lock-keywords-1', this adds fontification of
2225 keywords, simple types, declarations that are easy to recognize, the
2226 user defined types on `c-font-lock-extra-types', and the doc comment
2227 styles specified by `c-doc-comment-style'.")
2229 (defconst c-font-lock-keywords-3 (c-lang-const c-matchers-3 c)
2230 "Accurate normal font locking for C mode.
2231 Like the variable `c-font-lock-keywords-2' but detects declarations in a more
2232 accurate way that works in most cases for arbitrary types without the
2233 need for `c-font-lock-extra-types'.")
2235 (defvar c-font-lock-keywords c-font-lock-keywords-3
2236 "Default expressions to highlight in C mode.")
2238 (defun c-font-lock-keywords-2 ()
2239 (c-compose-keywords-list c-font-lock-keywords-2))
2240 (defun c-font-lock-keywords-3 ()
2241 (c-compose-keywords-list c-font-lock-keywords-3))
2242 (defun c-font-lock-keywords ()
2243 (c-compose-keywords-list c-font-lock-keywords))
2246 ;;; C++.
2248 (defun c-font-lock-c++-new (limit)
2249 ;; FIXME!!! Put in a comment about the context of this function's
2250 ;; invocation. I think it's called as an ANCHORED-MATCHER within an
2251 ;; ANCHORED-HIGHLIGHTER. (2007/2/10).
2253 ;; Assuming point is after a "new" word, check that it isn't inside
2254 ;; a string or comment, and if so try to fontify the type in the
2255 ;; allocation expression. Nil is always returned.
2257 ;; As usual, C++ takes the prize in coming up with a hard to parse
2258 ;; syntax. :P
2260 ;; This function might do hidden buffer changes.
2262 (unless (c-skip-comments-and-strings limit)
2263 (save-excursion
2264 (catch 'false-alarm
2265 ;; A "new" keyword is followed by one to three expressions, where
2266 ;; the type is the middle one, and the only required part.
2267 (let (expr1-pos expr2-pos
2268 ;; Enable recording of identifier ranges in `c-forward-type'
2269 ;; etc for later fontification. Not using
2270 ;; `c-fontify-types-and-refs' here since the ranges should
2271 ;; be fontified selectively only when an allocation
2272 ;; expression is successfully recognized.
2273 (c-record-type-identifiers t)
2274 c-record-ref-identifiers
2275 ;; The font-lock package in Emacs is known to clobber
2276 ;; `parse-sexp-lookup-properties' (when it exists).
2277 (parse-sexp-lookup-properties
2278 (cc-eval-when-compile
2279 (boundp 'parse-sexp-lookup-properties))))
2280 (c-forward-syntactic-ws)
2282 ;; The first placement arglist is always parenthesized, if it
2283 ;; exists.
2284 (when (eq (char-after) ?\()
2285 (setq expr1-pos (1+ (point)))
2286 (condition-case nil
2287 (c-forward-sexp)
2288 (scan-error (throw 'false-alarm t)))
2289 (c-forward-syntactic-ws))
2291 ;; The second expression is either a type followed by some "*" or
2292 ;; "[...]" or similar, or a parenthesized type followed by a full
2293 ;; identifierless declarator.
2294 (setq expr2-pos (1+ (point)))
2295 (cond ((eq (char-after) ?\())
2296 ((let ((c-promote-possible-types t))
2297 (c-forward-type)))
2298 (t (setq expr2-pos nil)))
2300 (when expr1-pos
2301 (cond
2302 ((not expr2-pos)
2303 ;; No second expression, so the first has to be a
2304 ;; parenthesized type.
2305 (goto-char expr1-pos)
2306 (let ((c-promote-possible-types t))
2307 (c-forward-type)))
2309 ((eq (char-before expr2-pos) ?\()
2310 ;; Got two parenthesized expressions, so we have to look
2311 ;; closer at them to decide which is the type. No need to
2312 ;; handle `c-record-ref-identifiers' since all references
2313 ;; have already been handled by other fontification rules.
2314 (let (expr1-res expr2-res)
2316 (goto-char expr1-pos)
2317 (when (setq expr1-res (c-forward-type))
2318 (unless (looking-at
2319 (cc-eval-when-compile
2320 (concat (c-lang-const c-symbol-start c++)
2321 "\\|[*:)[]")))
2322 ;; There's something after the would-be type that
2323 ;; can't be there, so this is a placement arglist.
2324 (setq expr1-res nil)))
2326 (goto-char expr2-pos)
2327 (when (setq expr2-res (c-forward-type))
2328 (unless (looking-at
2329 (cc-eval-when-compile
2330 (concat (c-lang-const c-symbol-start c++)
2331 "\\|[*:)[]")))
2332 ;; There's something after the would-be type that can't
2333 ;; be there, so this is an initialization expression.
2334 (setq expr2-res nil))
2335 (when (and (c-go-up-list-forward)
2336 (progn (c-forward-syntactic-ws)
2337 (eq (char-after) ?\()))
2338 ;; If there's a third initialization expression
2339 ;; then the second one is the type, so demote the
2340 ;; first match.
2341 (setq expr1-res nil)))
2343 ;; We fontify the most likely type, with a preference for
2344 ;; the first argument since a placement arglist is more
2345 ;; unusual than an initializer.
2346 (cond ((memq expr1-res '(t known prefix)))
2347 ((memq expr2-res '(t known prefix)))
2348 ;; Presumably 'decltype's will be fontified elsewhere.
2349 ((eq expr1-res 'decltype))
2350 ((eq expr2-res 'decltype))
2351 ((eq expr1-res 'found)
2352 (let ((c-promote-possible-types t))
2353 (goto-char expr1-pos)
2354 (c-forward-type)))
2355 ((eq expr2-res 'found)
2356 (let ((c-promote-possible-types t))
2357 (goto-char expr2-pos)
2358 (c-forward-type)))
2359 ((and (eq expr1-res 'maybe) (not expr2-res))
2360 (let ((c-promote-possible-types t))
2361 (goto-char expr1-pos)
2362 (c-forward-type)))
2363 ((and (not expr1-res) (eq expr2-res 'maybe))
2364 (let ((c-promote-possible-types t))
2365 (goto-char expr2-pos)
2366 (c-forward-type)))
2367 ;; If both type matches are 'maybe then we're
2368 ;; too uncertain to promote either of them.
2369 )))))
2371 ;; Fontify the type that now is recorded in
2372 ;; `c-record-type-identifiers', if any.
2373 (c-fontify-recorded-types-and-refs)))))
2374 nil)
2376 (c-override-default-keywords 'c++-font-lock-keywords)
2378 (defconst c++-font-lock-keywords-1 (c-lang-const c-matchers-1 c++)
2379 "Minimal font locking for C++ mode.
2380 Fontifies only preprocessor directives (in addition to the syntactic
2381 fontification of strings and comments).")
2383 (defconst c++-font-lock-keywords-2 (c-lang-const c-matchers-2 c++)
2384 "Fast normal font locking for C++ mode.
2385 In addition to `c++-font-lock-keywords-1', this adds fontification of
2386 keywords, simple types, declarations that are easy to recognize, the
2387 user defined types on `c++-font-lock-extra-types', and the doc comment
2388 styles specified by `c-doc-comment-style'.")
2390 (defconst c++-font-lock-keywords-3 (c-lang-const c-matchers-3 c++)
2391 "Accurate normal font locking for C++ mode.
2392 Like the variable `c++-font-lock-keywords-2' but detects declarations in a more
2393 accurate way that works in most cases for arbitrary types without the
2394 need for `c++-font-lock-extra-types'.")
2396 (defvar c++-font-lock-keywords c++-font-lock-keywords-3
2397 "Default expressions to highlight in C++ mode.")
2399 (defun c++-font-lock-keywords-2 ()
2400 (c-compose-keywords-list c++-font-lock-keywords-2))
2401 (defun c++-font-lock-keywords-3 ()
2402 (c-compose-keywords-list c++-font-lock-keywords-3))
2403 (defun c++-font-lock-keywords ()
2404 (c-compose-keywords-list c++-font-lock-keywords))
2407 ;;; Objective-C.
2409 (defun c-font-lock-objc-method ()
2410 ;; Assuming the point is after the + or - that starts an Objective-C
2411 ;; method declaration, fontify it. This must be done before normal
2412 ;; casts, declarations and labels are fontified since they will get
2413 ;; false matches in these things.
2415 ;; This function might do hidden buffer changes.
2417 (c-fontify-types-and-refs
2418 ((first t)
2419 (c-promote-possible-types t))
2421 (while (and
2422 (progn
2423 (c-forward-syntactic-ws)
2425 ;; An optional method type.
2426 (if (eq (char-after) ?\()
2427 (progn
2428 (forward-char)
2429 (c-forward-syntactic-ws)
2430 (c-forward-type)
2431 (prog1 (c-go-up-list-forward)
2432 (c-forward-syntactic-ws)))
2435 ;; The name. The first time it's the first part of
2436 ;; the function name, the rest of the time it's an
2437 ;; argument name.
2438 (looking-at c-symbol-key)
2439 (progn
2440 (goto-char (match-end 0))
2441 (c-put-font-lock-face (match-beginning 0)
2442 (point)
2443 (if first
2444 'font-lock-function-name-face
2445 'font-lock-variable-name-face))
2446 (c-forward-syntactic-ws)
2448 ;; Another optional part of the function name.
2449 (when (looking-at c-symbol-key)
2450 (goto-char (match-end 0))
2451 (c-put-font-lock-face (match-beginning 0)
2452 (point)
2453 'font-lock-function-name-face)
2454 (c-forward-syntactic-ws))
2456 ;; There's another argument if a colon follows.
2457 (eq (char-after) ?:)))
2458 (forward-char)
2459 (setq first nil))))
2461 (defun c-font-lock-objc-methods (limit)
2462 ;; Fontify method declarations in Objective-C. Nil is always
2463 ;; returned.
2465 ;; This function might do hidden buffer changes.
2467 (let (;; The font-lock package in Emacs is known to clobber
2468 ;; `parse-sexp-lookup-properties' (when it exists).
2469 (parse-sexp-lookup-properties
2470 (cc-eval-when-compile
2471 (boundp 'parse-sexp-lookup-properties))))
2473 (c-find-decl-spots
2474 limit
2475 "[-+]"
2477 (lambda (match-pos inside-macro &optional top-level)
2478 (forward-char)
2479 (c-font-lock-objc-method))))
2480 nil)
2482 (c-override-default-keywords 'objc-font-lock-keywords)
2484 (defconst objc-font-lock-keywords-1 (c-lang-const c-matchers-1 objc)
2485 "Minimal font locking for Objective-C mode.
2486 Fontifies only compiler directives (in addition to the syntactic
2487 fontification of strings and comments).")
2489 (defconst objc-font-lock-keywords-2 (c-lang-const c-matchers-2 objc)
2490 "Fast normal font locking for Objective-C mode.
2491 In addition to `objc-font-lock-keywords-1', this adds fontification of
2492 keywords, simple types, declarations that are easy to recognize, the
2493 user defined types on `objc-font-lock-extra-types', and the doc
2494 comment styles specified by `c-doc-comment-style'.")
2496 (defconst objc-font-lock-keywords-3 (c-lang-const c-matchers-3 objc)
2497 "Accurate normal font locking for Objective-C mode.
2498 Like the variable `objc-font-lock-keywords-2' but detects declarations in a more
2499 accurate way that works in most cases for arbitrary types without the
2500 need for `objc-font-lock-extra-types'.")
2502 (defvar objc-font-lock-keywords objc-font-lock-keywords-3
2503 "Default expressions to highlight in Objective-C mode.")
2505 (defun objc-font-lock-keywords-2 ()
2506 (c-compose-keywords-list objc-font-lock-keywords-2))
2507 (defun objc-font-lock-keywords-3 ()
2508 (c-compose-keywords-list objc-font-lock-keywords-3))
2509 (defun objc-font-lock-keywords ()
2510 (c-compose-keywords-list objc-font-lock-keywords))
2512 ;; Kludge to override the default value that
2513 ;; `objc-font-lock-extra-types' might have gotten from the font-lock
2514 ;; package. The value replaced here isn't relevant now anyway since
2515 ;; those types are builtin and therefore listed directly in
2516 ;; `c-primitive-type-kwds'.
2517 (when (equal (sort (append objc-font-lock-extra-types nil) 'string-lessp)
2518 '("BOOL" "Class" "IMP" "SEL"))
2519 (setq objc-font-lock-extra-types
2520 (cc-eval-when-compile (list (concat "[" c-upper "]\\sw*")))))
2523 ;;; Java.
2525 (c-override-default-keywords 'java-font-lock-keywords)
2527 (defconst java-font-lock-keywords-1 (c-lang-const c-matchers-1 java)
2528 "Minimal font locking for Java mode.
2529 Fontifies nothing except the syntactic fontification of strings and
2530 comments.")
2532 (defconst java-font-lock-keywords-2 (c-lang-const c-matchers-2 java)
2533 "Fast normal font locking for Java mode.
2534 In addition to `java-font-lock-keywords-1', this adds fontification of
2535 keywords, simple types, declarations that are easy to recognize, the
2536 user defined types on `java-font-lock-extra-types', and the doc
2537 comment styles specified by `c-doc-comment-style'.")
2539 (defconst java-font-lock-keywords-3 (c-lang-const c-matchers-3 java)
2540 "Accurate normal font locking for Java mode.
2541 Like variable `java-font-lock-keywords-2' but detects declarations in a more
2542 accurate way that works in most cases for arbitrary types without the
2543 need for `java-font-lock-extra-types'.")
2545 (defvar java-font-lock-keywords java-font-lock-keywords-3
2546 "Default expressions to highlight in Java mode.")
2548 (defun java-font-lock-keywords-2 ()
2549 (c-compose-keywords-list java-font-lock-keywords-2))
2550 (defun java-font-lock-keywords-3 ()
2551 (c-compose-keywords-list java-font-lock-keywords-3))
2552 (defun java-font-lock-keywords ()
2553 (c-compose-keywords-list java-font-lock-keywords))
2556 ;;; CORBA IDL.
2558 (c-override-default-keywords 'idl-font-lock-keywords)
2560 (defconst idl-font-lock-keywords-1 (c-lang-const c-matchers-1 idl)
2561 "Minimal font locking for CORBA IDL mode.
2562 Fontifies nothing except the syntactic fontification of strings and
2563 comments.")
2565 (defconst idl-font-lock-keywords-2 (c-lang-const c-matchers-2 idl)
2566 "Fast normal font locking for CORBA IDL mode.
2567 In addition to `idl-font-lock-keywords-1', this adds fontification of
2568 keywords, simple types, declarations that are easy to recognize, the
2569 user defined types on `idl-font-lock-extra-types', and the doc comment
2570 styles specified by `c-doc-comment-style'.")
2572 (defconst idl-font-lock-keywords-3 (c-lang-const c-matchers-3 idl)
2573 "Accurate normal font locking for CORBA IDL mode.
2574 Like the variable `idl-font-lock-keywords-2' but detects declarations in a more
2575 accurate way that works in most cases for arbitrary types without the
2576 need for `idl-font-lock-extra-types'.")
2578 (defvar idl-font-lock-keywords idl-font-lock-keywords-3
2579 "Default expressions to highlight in CORBA IDL mode.")
2581 (defun idl-font-lock-keywords-2 ()
2582 (c-compose-keywords-list idl-font-lock-keywords-2))
2583 (defun idl-font-lock-keywords-3 ()
2584 (c-compose-keywords-list idl-font-lock-keywords-3))
2585 (defun idl-font-lock-keywords ()
2586 (c-compose-keywords-list idl-font-lock-keywords))
2589 ;;; Pike.
2591 (c-override-default-keywords 'pike-font-lock-keywords)
2593 (defconst pike-font-lock-keywords-1 (c-lang-const c-matchers-1 pike)
2594 "Minimal font locking for Pike mode.
2595 Fontifies only preprocessor directives (in addition to the syntactic
2596 fontification of strings and comments).")
2598 (defconst pike-font-lock-keywords-2 (c-lang-const c-matchers-2 pike)
2599 "Fast normal font locking for Pike mode.
2600 In addition to `pike-font-lock-keywords-1', this adds fontification of
2601 keywords, simple types, declarations that are easy to recognize, the
2602 user defined types on `pike-font-lock-extra-types', and the doc
2603 comment styles specified by `c-doc-comment-style'.")
2605 (defconst pike-font-lock-keywords-3 (c-lang-const c-matchers-3 pike)
2606 "Accurate normal font locking for Pike mode.
2607 Like the variable `pike-font-lock-keywords-2' but detects declarations in a more
2608 accurate way that works in most cases for arbitrary types without the
2609 need for `pike-font-lock-extra-types'.")
2611 (defvar pike-font-lock-keywords pike-font-lock-keywords-3
2612 "Default expressions to highlight in Pike mode.")
2614 (defun pike-font-lock-keywords-2 ()
2615 (c-compose-keywords-list pike-font-lock-keywords-2))
2616 (defun pike-font-lock-keywords-3 ()
2617 (c-compose-keywords-list pike-font-lock-keywords-3))
2618 (defun pike-font-lock-keywords ()
2619 (c-compose-keywords-list pike-font-lock-keywords))
2622 ;;; Doc comments.
2624 (defun c-font-lock-doc-comments (prefix limit keywords)
2625 ;; Fontify the comments between the point and LIMIT whose start
2626 ;; matches PREFIX with `c-doc-face-name'. Assumes comments have been
2627 ;; fontified with `font-lock-comment-face' already. nil is always
2628 ;; returned.
2630 ;; After the fontification of a matching comment, fontification
2631 ;; according to KEYWORDS is applied inside it. It's a list like
2632 ;; `font-lock-keywords' except that anchored matches and eval
2633 ;; clauses aren't supported and that some abbreviated forms can't be
2634 ;; used. The buffer is narrowed to the comment while KEYWORDS is
2635 ;; applied; leading comment starters are included but trailing
2636 ;; comment enders for block comment are not.
2638 ;; Note that faces added through KEYWORDS should never replace the
2639 ;; existing `c-doc-face-name' face since the existence of that face
2640 ;; is used as a flag in other code to skip comments.
2642 ;; This function might do hidden buffer changes.
2644 (let (comment-beg region-beg)
2645 (if (eq (get-text-property (point) 'face)
2646 'font-lock-comment-face)
2647 ;; Handle the case when the fontified region starts inside a
2648 ;; comment.
2649 (let ((start (c-literal-start)))
2650 (setq region-beg (point))
2651 (when start
2652 (goto-char start))
2653 (when (looking-at prefix)
2654 (setq comment-beg (point)))))
2656 (while (or
2657 comment-beg
2659 ;; Search for the prefix until a match is found at the start
2660 ;; of a comment.
2661 (while (when (re-search-forward prefix limit t)
2662 (setq comment-beg (match-beginning 0))
2663 (or (not (c-got-face-at comment-beg
2664 c-literal-faces))
2665 (and (/= comment-beg (point-min))
2666 (c-got-face-at (1- comment-beg)
2667 c-literal-faces))))
2668 (setq comment-beg nil))
2669 (setq region-beg comment-beg))
2671 (if (elt (parse-partial-sexp comment-beg (+ comment-beg 2)) 7)
2672 ;; Collect a sequence of doc style line comments.
2673 (progn
2674 (goto-char comment-beg)
2675 (while (and (progn
2676 (c-forward-single-comment)
2677 (skip-syntax-forward " ")
2678 (< (point) limit))
2679 (looking-at prefix))))
2680 (goto-char comment-beg)
2681 (c-forward-single-comment))
2682 (if (> (point) limit) (goto-char limit))
2683 (setq comment-beg nil)
2685 (let ((region-end (point))
2686 (keylist keywords) keyword matcher highlights)
2687 (c-put-font-lock-face region-beg region-end c-doc-face-name)
2688 (save-restriction
2689 ;; Narrow to the doc comment. Among other things, this
2690 ;; helps by making "^" match at the start of the comment.
2691 ;; Do not include a trailing block comment ender, though.
2692 (and (> region-end (1+ region-beg))
2693 (progn (goto-char region-end)
2694 (backward-char 2)
2695 (looking-at "\\*/"))
2696 (setq region-end (point)))
2697 (narrow-to-region region-beg region-end)
2699 (while keylist
2700 (setq keyword (car keylist)
2701 keylist (cdr keylist)
2702 matcher (car keyword))
2703 (goto-char region-beg)
2704 (while (if (stringp matcher)
2705 (re-search-forward matcher region-end t)
2706 (funcall matcher region-end))
2707 (setq highlights (cdr keyword))
2708 (if (consp (car highlights))
2709 (while highlights
2710 (font-lock-apply-highlight (car highlights))
2711 (setq highlights (cdr highlights)))
2712 (font-lock-apply-highlight highlights))))
2714 (goto-char region-end)))))
2715 nil)
2716 (put 'c-font-lock-doc-comments 'lisp-indent-function 2)
2718 (defun c-find-invalid-doc-markup (regexp limit)
2719 ;; Used to fontify invalid markup in doc comments after the correct
2720 ;; ones have been fontified: Find the first occurrence of REGEXP
2721 ;; between the point and LIMIT that only is fontified with
2722 ;; `c-doc-face-name'. If a match is found then submatch 0 surrounds
2723 ;; the first char and t is returned, otherwise nil is returned.
2725 ;; This function might do hidden buffer changes.
2726 (let (start)
2727 (while (if (re-search-forward regexp limit t)
2728 (not (eq (get-text-property
2729 (setq start (match-beginning 0)) 'face)
2730 c-doc-face-name))
2731 (setq start nil)))
2732 (when start
2733 (store-match-data (list (copy-marker start)
2734 (copy-marker (1+ start))))
2735 t)))
2737 ;; GtkDoc patterns contributed by Masatake YAMATO <jet@gyve.org>.
2739 (defconst gtkdoc-font-lock-doc-comments
2740 (let ((symbol "[a-zA-Z0-9_]+")
2741 (header "^ \\* "))
2742 `((,(concat header "\\(" symbol "\\):[ \t]*$")
2743 1 ,c-doc-markup-face-name prepend nil)
2744 (,(concat symbol "()")
2745 0 ,c-doc-markup-face-name prepend nil)
2746 (,(concat header "\\(" "@" symbol "\\):")
2747 1 ,c-doc-markup-face-name prepend nil)
2748 (,(concat "[#%@]" symbol)
2749 0 ,c-doc-markup-face-name prepend nil))
2752 (defconst gtkdoc-font-lock-doc-protection
2753 `(("< \\(public\\|private\\|protected\\) >"
2754 1 ,c-doc-markup-face-name prepend nil)))
2756 (defconst gtkdoc-font-lock-keywords
2757 `((,(lambda (limit)
2758 (c-font-lock-doc-comments "/\\*\\*$" limit
2759 gtkdoc-font-lock-doc-comments)
2760 (c-font-lock-doc-comments "/\\*< " limit
2761 gtkdoc-font-lock-doc-protection)
2762 ))))
2764 ;; Javadoc.
2766 (defconst javadoc-font-lock-doc-comments
2767 `(("{@[a-z]+[^}\n\r]*}" ; "{@foo ...}" markup.
2768 0 ,c-doc-markup-face-name prepend nil)
2769 ("^\\(/\\*\\)?\\(\\s \\|\\*\\)*\\(@[a-z]+\\)" ; "@foo ..." markup.
2770 3 ,c-doc-markup-face-name prepend nil)
2771 (,(concat "</?\\sw" ; HTML tags.
2772 "\\("
2773 (concat "\\sw\\|\\s \\|[=\n\r*.:]\\|"
2774 "\"[^\"]*\"\\|'[^']*'")
2775 "\\)*>")
2776 0 ,c-doc-markup-face-name prepend nil)
2777 ("&\\(\\sw\\|[.:]\\)+;" ; HTML entities.
2778 0 ,c-doc-markup-face-name prepend nil)
2779 ;; Fontify remaining markup characters as invalid. Note
2780 ;; that the Javadoc spec is hazy about when "@" is
2781 ;; allowed in non-markup use.
2782 (,(lambda (limit)
2783 (c-find-invalid-doc-markup "[<>&]\\|{@" limit))
2784 0 'font-lock-warning-face prepend nil)))
2786 (defconst javadoc-font-lock-keywords
2787 `((,(lambda (limit)
2788 (c-font-lock-doc-comments "/\\*\\*" limit
2789 javadoc-font-lock-doc-comments)))))
2791 ;; Pike autodoc.
2793 (defconst autodoc-decl-keywords
2794 ;; Adorned regexp matching the keywords that introduce declarations
2795 ;; in Pike Autodoc.
2796 (cc-eval-when-compile
2797 (c-make-keywords-re t '("@decl" "@elem" "@index" "@member") 'pike-mode)))
2799 (defconst autodoc-decl-type-keywords
2800 ;; Adorned regexp matching the keywords that are followed by a type.
2801 (cc-eval-when-compile
2802 (c-make-keywords-re t '("@elem" "@member") 'pike-mode)))
2804 (defun autodoc-font-lock-line-markup (limit)
2805 ;; Fontify all line oriented keywords between the point and LIMIT.
2806 ;; Nil is always returned.
2808 ;; This function might do hidden buffer changes.
2810 (let ((line-re (concat "^\\(\\(/\\*!\\|\\s *\\("
2811 c-current-comment-prefix
2812 "\\)\\)\\s *\\)@[A-Za-z_-]+\\(\\s \\|$\\)"))
2813 (markup-faces (list c-doc-markup-face-name c-doc-face-name)))
2815 (while (re-search-forward line-re limit t)
2816 (goto-char (match-end 1))
2818 (if (looking-at autodoc-decl-keywords)
2819 (let* ((kwd-pos (point))
2820 (start (match-end 1))
2821 (pos start)
2822 end)
2824 (c-put-font-lock-face (point) pos markup-faces)
2826 ;; Put a declaration end mark at the markup keyword and
2827 ;; remove the faces from the rest of the line so that it
2828 ;; gets refontified as a declaration later on by
2829 ;; `c-font-lock-declarations'.
2830 (c-put-char-property (1- pos) 'c-type 'c-decl-end)
2831 (goto-char pos)
2832 (while (progn
2833 (end-of-line)
2834 (setq end (point))
2835 (and (eq (char-before) ?@)
2836 (not (eobp))
2837 (progn (forward-char)
2838 (skip-syntax-forward " ")
2839 (looking-at c-current-comment-prefix))))
2840 (goto-char (match-end 0))
2841 (c-remove-font-lock-face pos (1- end))
2842 (c-put-font-lock-face (1- end) end markup-faces)
2843 (setq pos (point)))
2845 ;; Include the final newline in the removed area. This
2846 ;; has no visual effect but it avoids some tricky special
2847 ;; cases in the testsuite wrt the differences in string
2848 ;; fontification in Emacs vs XEmacs.
2849 (c-remove-font-lock-face pos (min (1+ (point)) (point-max)))
2851 ;; Must handle string literals explicitly inside the declaration.
2852 (goto-char start)
2853 (while (re-search-forward
2854 "\"\\([^\\\"]\\|\\\\.\\)*\"\\|'\\([^\\']\\|\\\\.\\)*'"
2855 end 'move)
2856 (c-put-font-lock-string-face (match-beginning 0)
2857 (point)))
2859 ;; Fontify types after keywords that always are followed
2860 ;; by them.
2861 (goto-char kwd-pos)
2862 (when (looking-at autodoc-decl-type-keywords)
2863 (c-fontify-types-and-refs ((c-promote-possible-types t))
2864 (goto-char start)
2865 (c-forward-syntactic-ws)
2866 (c-forward-type))))
2868 ;; Mark each whole line as markup, as long as the logical line
2869 ;; continues.
2870 (while (progn
2871 (c-put-font-lock-face (point)
2872 (progn (end-of-line) (point))
2873 markup-faces)
2874 (and (eq (char-before) ?@)
2875 (not (eobp))
2876 (progn (forward-char)
2877 (skip-syntax-forward " ")
2878 (looking-at c-current-comment-prefix))))
2879 (goto-char (match-end 0))))))
2881 nil)
2883 (defconst autodoc-font-lock-doc-comments
2884 `(("@\\(\\w+{\\|\\[\\([^]@\n\r]\\|@@\\)*\\]\\|[@}]\\|$\\)"
2885 ;; In-text markup.
2886 0 ,c-doc-markup-face-name prepend nil)
2887 (autodoc-font-lock-line-markup)
2888 ;; Fontify remaining markup characters as invalid.
2889 (,(lambda (limit)
2890 (c-find-invalid-doc-markup "@" limit))
2891 0 'font-lock-warning-face prepend nil)
2894 (defun autodoc-font-lock-keywords ()
2895 ;; Note that we depend on that `c-current-comment-prefix' has got
2896 ;; its proper value here.
2898 ;; This function might do hidden buffer changes.
2900 ;; The `c-type' text property with `c-decl-end' is used to mark the
2901 ;; end of the `autodoc-decl-keywords' occurrences to fontify the
2902 ;; following declarations.
2903 (setq c-type-decl-end-used t)
2905 `((,(lambda (limit)
2906 (c-font-lock-doc-comments "/[*/]!" limit
2907 autodoc-font-lock-doc-comments)))))
2910 ;; 2006-07-10: awk-font-lock-keywords has been moved back to cc-awk.el.
2911 (cc-provide 'cc-fonts)
2913 ;; Local Variables:
2914 ;; indent-tabs-mode: t
2915 ;; tab-width: 8
2916 ;; End:
2917 ;;; cc-fonts.el ends here