mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-15 10:30:25 -08:00
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.
This commit is contained in:
parent
543532313a
commit
a285645b8b
2 changed files with 36 additions and 17 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -3292,6 +3292,24 @@ the invalidity of the putative template construct."
|
|||
c++ "[<;{},>()]")
|
||||
(c-lang-defvar c-<>-notable-chars-re (c-lang-const c-<>-notable-chars-re))
|
||||
|
||||
(c-lang-defconst c-enum-clause-introduction-re
|
||||
;; A regexp loosely matching the start of an enum clause, starting at the
|
||||
;; keyword itself, and extending up to the "{". It may match text which
|
||||
;; isn't such a construct; more accurate tests will rule these out when
|
||||
;; needed.
|
||||
t (if (c-lang-const c-brace-list-decl-kwds)
|
||||
(concat
|
||||
"\\<\\("
|
||||
(c-make-keywords-re nil (c-lang-const c-brace-list-decl-kwds))
|
||||
"\\)\\>"
|
||||
;; Disallow various common punctuation chars that can't come
|
||||
;; before the '{' of the enum list, to avoid searching too far.
|
||||
"[^][{};/#=]*"
|
||||
"{")
|
||||
"\\<\\>"))
|
||||
(c-lang-defvar c-enum-clause-introduction-re
|
||||
(c-lang-const c-enum-clause-introduction-re))
|
||||
|
||||
(c-lang-defconst c-enums-contain-decls
|
||||
"Non-nil means that an enum structure can contain declarations."
|
||||
t nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue