summaryrefslogtreecommitdiff
path: root/lisp/progmodes/cc-fonts.el
diff options
context:
space:
mode:
authorAlan Mackenzie <acm@muc.de>2016-12-30 15:31:42 +0000
committerAlan Mackenzie <acm@muc.de>2016-12-30 15:31:42 +0000
commita285645b8ba0b01e559a26258035ae1a70e3fad2 (patch)
tree787ddbdd0069b56c737d94880ae0bf2e64e978d0 /lisp/progmodes/cc-fonts.el
parent543532313a1d9570d6a74a7846b4e776a2282964 (diff)
downloademacs-a285645b8ba0b01e559a26258035ae1a70e3fad2.tar.gz
emacs-a285645b8ba0b01e559a26258035ae1a70e3fad2.tar.bz2
emacs-a285645b8ba0b01e559a26258035ae1a70e3fad2.zip
CC Mode: Fix the fontification of a spuriously recognised enum member.
The "enum" was in an argument list, but triggered the fontification of a following identifier in the function block as though it were in an enum declaration. * lisp/progmodes/cc-fonts.el (c-font-lock-enum-body): New function. (c-basic-matchers-after): Replace the inline stanza for enum elements with a call to c-font-lock-enum-body. * lisp/progmodes/cc-langs.el (c-enum-clause-introduction-re): New language variable.
Diffstat (limited to 'lisp/progmodes/cc-fonts.el')
-rw-r--r--lisp/progmodes/cc-fonts.el35
1 files changed, 18 insertions, 17 deletions
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el
index 39e68f0b871..c213f1f198e 100644
--- a/lisp/progmodes/cc-fonts.el
+++ b/lisp/progmodes/cc-fonts.el
@@ -1493,6 +1493,22 @@ casts and declarations are fontified. Used on level 2 and higher."
nil)))
+(defun c-font-lock-enum-body (limit)
+ ;; Fontify the identifiers of each enum we find by searching forward.
+ ;;
+ ;; 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".
+ (while (search-forward-regexp c-enum-clause-introduction-re limit t)
+ (when (save-excursion
+ (backward-char)
+ (c-backward-over-enum-header))
+ (c-forward-syntactic-ws)
+ (c-font-lock-declarators limit t nil t)))
+ nil)
+
(defun c-font-lock-enum-tail (limit)
;; Fontify an enum's identifiers when POINT is within the enum's brace
;; block.
@@ -2020,29 +2036,14 @@ on level 2 only and so aren't combined with `c-complex-decl-matchers'."
generic casts and declarations are fontified. Used on level 2 and
higher."
- t `(,@(when (c-lang-const c-brace-id-list-kwds)
+ t `(,@(when (c-lang-const c-brace-list-decl-kwds)
;; Fontify the remaining identifiers inside an enum list when we start
;; inside it.
`(c-font-lock-enum-tail
;; Fontify the identifiers inside enum lists. (The enum type
;; name is handled by `c-simple-decl-matchers' or
;; `c-complex-decl-matchers' below.
- (,(c-make-font-lock-search-function
- (concat
- "\\<\\("
- (c-make-keywords-re nil (c-lang-const c-brace-id-list-kwds))
- "\\)\\>"
- ;; Disallow various common punctuation chars that can't come
- ;; before the '{' of the enum list, to avoid searching too far.
- "[^][{};/#=]*"
- "{")
- '((c-font-lock-declarators limit t nil t)
- (save-match-data
- (goto-char (match-end 0))
- (c-put-char-property (1- (point)) 'c-type
- 'c-decl-id-start)
- (c-forward-syntactic-ws))
- (goto-char (match-end 0)))))))
+ c-font-lock-enum-body))
;; Fontify labels after goto etc.
,@(when (c-lang-const c-before-label-kwds)