emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master a285645: CC Mode: Fix the fontification of a spurio


From: Alan Mackenzie
Subject: [Emacs-diffs] master a285645: CC Mode: Fix the fontification of a spuriously recognised enum member.
Date: Fri, 30 Dec 2016 15:34:56 +0000 (UTC)

branch: master
commit a285645b8ba0b01e559a26258035ae1a70e3fad2
Author: Alan Mackenzie <address@hidden>
Commit: Alan Mackenzie <address@hidden>

    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.
---
 lisp/progmodes/cc-fonts.el |   35 ++++++++++++++++++-----------------
 lisp/progmodes/cc-langs.el |   18 ++++++++++++++++++
 2 files changed, 36 insertions(+), 17 deletions(-)

diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el
index 39e68f0..c213f1f 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)
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 83b8db3..e80dc92 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]