;;; cc-fonts.el --- font lock support for CC Mode
-;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
;; Authors: 2003- Alan Mackenzie
;; 2002- Martin Stjernholm
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with this program; see the file COPYING. If not, write to
-;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
`(;; The stuff after #error and #warning is a message, so
;; fontify it as a string.
,@(when (c-lang-const c-cpp-message-directives)
- (let* ((re (c-make-keywords-re nil
+ (let* ((re (c-make-keywords-re 'appendable ; nil
(c-lang-const c-cpp-message-directives)))
(re-depth (regexp-opt-depth re)))
`((,(concat noncontinued-line-end
(c-lang-const c-opt-cpp-prefix)
re
"\\s +\\(.*\\)$")
- ,(+ ncle-depth re-depth 1) font-lock-string-face))))
+ ,(+ ncle-depth re-depth 1) font-lock-string-face t))))
;; Fontify filenames in #include <...> as strings.
,@(when (c-lang-const c-cpp-include-directives)
))
(defun c-font-lock-complex-decl-prepare (limit)
+ ;; This function will be called from font-lock for a region bounded by POINT
+ ;; and LIMIT, as though it were to identify a keyword for
+ ;; font-lock-keyword-face. It always returns NIL to inhibit this and
+ ;; prevent a repeat invocation. See elisp/lispref page "Search-based
+ ;; Fontification".
+ ;;
;; Called before any of the matchers in `c-complex-decl-matchers'.
- ;; Nil is always returned.
;;
;; This function does hidden buffer changes.
nil)
(defun c-font-lock-<>-arglists (limit)
+ ;; This function will be called from font-lock for a region bounded by POINT
+ ;; and LIMIT, as though it were to identify a keyword for
+ ;; font-lock-keyword-face. It always returns NIL to inhibit this and
+ ;; prevent a repeat invocation. See elisp/lispref page "Search-based
+ ;; Fontification".
+ ;;
;; Fontify types and references in names containing angle bracket
;; arglists from the point to LIMIT. Note that
- ;; `c-font-lock-declarations' already has handled many of them. Nil
- ;; is always returned.
+ ;; `c-font-lock-declarations' already has handled many of them.
;;
;; This function might do hidden buffer changes.
font-lock-keyword-face))
(defun c-font-lock-declarations (limit)
+ ;; This function will be called from font-lock for a region bounded by POINT
+ ;; and LIMIT, as though it were to identify a keyword for
+ ;; font-lock-keyword-face. It always returns NIL to inhibit this and
+ ;; prevent a repeat invocation. See elisp/lispref page "Search-based
+ ;; Fontification".
+ ;;
;; Fontify all the declarations, casts and labels from the point to LIMIT.
- ;; Assumes that strings and comments have been fontified already. Nil is
- ;; always returned.
+ ;; Assumes that strings and comments have been fontified already.
;;
;; This function might do hidden buffer changes.
;; `c-forward-decl-or-cast-1' and `c-forward-label' for
;; later fontification.
(c-record-type-identifiers t)
+ label-type
c-record-ref-identifiers
;; Make `c-forward-type' calls mark up template arglists if
;; it finds any. That's necessary so that we later will
(c-fontify-recorded-types-and-refs)
nil))
- ;; It was a false alarm.
+ ;; It was a false alarm. Check if we're in a label (or other
+ ;; construct with `:' except bitfield) instead.
(goto-char start-pos)
- ;; The below code attempts to fontify the case constants in
- ;; c-label-face-name, but it cannot catch every case [sic].
- ;; And do we want to fontify case constants anyway?
- (c-forward-label t match-pos nil)
-;;; (when (c-forward-label t match-pos nil)
-;;; ;; Can't use `c-fontify-types-and-refs' here since we
-;;; ;; should use the label face.
-;;; (save-excursion
-;;; (while c-record-ref-identifiers
-;;; (let ((elem (car c-record-ref-identifiers))
-;;; c-record-type-identifiers)
-;;; (goto-char (cdr elem))
-;;; ;; Find the end of any label.
-;;; (while (and (re-search-forward "\\sw\\|:" nil t)
-;;; (progn (backward-char 1) t)
-;;; (or (re-search-forward
-;;; "\\=0[Xx][0-9A-Fa-f]+\\|\\([0-9]+\\)" nil t)
-;;; (c-forward-name)))
-;;; (c-backward-syntactic-ws)
-;;; (let ((end (point)))
-;;; ;; Now find the start of the bit we regard as the label.
-;;; (when (and (c-simple-skip-symbol-backward)
-;;; (not (c-get-char-property (point) 'face)))
-;;; (c-put-font-lock-face (point) end c-label-face-name))
-;;; (goto-char end))))
-;;; (setq c-record-ref-identifiers (cdr c-record-ref-identifiers))))
-;;; ;; `c-forward-label' probably has added a `c-decl-end'
-;;; ;; marker, so return t to `c-find-decl-spots' to signal
-;;; ;; that.
-;;; t)
- )))
+ (when (setq label-type (c-forward-label t match-pos nil))
+ ;; Can't use `c-fontify-types-and-refs' here since we
+ ;; use the label face at times.
+ (cond ((eq label-type 'goto-target)
+ (c-put-font-lock-face (caar c-record-ref-identifiers)
+ (cdar c-record-ref-identifiers)
+ c-label-face-name))
+ ((eq label-type 'qt-1kwd-colon)
+ (c-put-font-lock-face (caar c-record-ref-identifiers)
+ (cdar c-record-ref-identifiers)
+ 'font-lock-keyword-face))
+ ((eq label-type 'qt-2kwds-colon)
+ (mapc
+ (lambda (kwd)
+ (c-put-font-lock-face (car kwd) (cdr kwd)
+ 'font-lock-keyword-face))
+ c-record-ref-identifiers)))
+ (setq c-record-ref-identifiers nil)
+ ;; `c-forward-label' has probably added a `c-decl-end'
+ ;; marker, so return t to `c-find-decl-spots' to signal
+ ;; that.
+ t))))
nil)))
"Complex font lock matchers for types and declarations. Used on level
3 and higher."
+ ;; Note: This code in this form dumps a number of funtions into the
+ ;; resulting constant, `c-matchers-3'. At run time, font lock will call
+ ;; each of them as a "FUNCTION" (see Elisp page "Search-based
+ ;; Fontification"). The font lock region is delimited by POINT and the
+ ;; single parameter, LIMIT. Each of these functions returns NIL (thus
+ ;; inhibiting spurious font-lock-keyword-face highlighting and another
+ ;; call).
+
t `(;; Initialize some things before the search functions below.
c-font-lock-complex-decl-prepare
;; Fontify the type in C++ "new" expressions.
,@(when (c-major-mode-is 'c++-mode)
+ ;; This pattern is a probably a "(MATCHER . ANCHORED-HIGHLIGHTER)"
+ ;; (see Elisp page "Search-based Fontification").
`(("\\<new\\>"
(c-font-lock-c++-new))))
))
0 ,c-doc-markup-face-name prepend nil)
(,(concat header "\\(" "@" symbol "\\):")
1 ,c-doc-markup-face-name prepend nil)
- (,(concat "[#%]" symbol)
+ (,(concat "[#%@]" symbol)
0 ,c-doc-markup-face-name prepend nil))
))
;; 2006-07-10: awk-font-lock-keywords has been moved back to cc-awk.el.
(cc-provide 'cc-fonts)
-;;; arch-tag: 2f65f405-735f-4da5-8d4b-b957844c5203
+;; arch-tag: 2f65f405-735f-4da5-8d4b-b957844c5203
;;; cc-fonts.el ends here