emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 0e09d00: Fontify C++ for loop variable as variable,


From: Alan Mackenzie
Subject: [Emacs-diffs] master 0e09d00: Fontify C++ for loop variable as variable, even when followed by parentheses
Date: Fri, 12 May 2017 17:16:45 -0400 (EDT)

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

    Fontify C++ for loop variable as variable, even when followed by parentheses
    
    In the following: "for (auto *Friend : Class->friends()) {", "Friend" was
    getting fontified as a function, due to insufficient checking of the tokens
    between it and "()".
    
    * lisp/progmodes/cc-langs.el (c-:-op-cont-tokens, c-:-op-cont-regexp): New
    lang-consts/vars.
    
    * lisp/progmodes/cc-engine.el (c-forward-declarator): After finding a 
putative
    declarator's identifier, check for a ":" token inside a for's parentheses, 
and
    abort the search for "(" if this is found.
---
 lisp/progmodes/cc-engine.el | 25 +++++++++++++++++++++++--
 lisp/progmodes/cc-langs.el  | 15 +++++++++++++++
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 6d7bab7..9773b1c 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -8092,8 +8092,29 @@ comment at the start of cc-engine.el for more info."
         ;; initializing brace lists.
         (let (found)
           (while
-              (and (setq found (c-syntactic-re-search-forward
-                                "[;,]\\|\\s)\\|\\'\\|\\(=\\|\\s(\\)" limit t 
t))
+              (and (progn
+                     ;; In the next loop, we keep searching forward whilst
+                     ;; we find ":"s which aren't single colons inside C++
+                     ;; "for" statements.
+                     (while
+                         (and
+                          (setq found
+                                (c-syntactic-re-search-forward
+                                 "[;:,]\\|\\s)\\|\\'\\|\\(=\\|\\s(\\)"
+                                 limit t t))
+                          (eq (char-before) ?:)
+                          (if (looking-at c-:-op-cont-regexp)
+                              (progn (goto-char (match-end 0)) t)
+                            (not
+                             (and (c-major-mode-is 'c++-mode)
+                                  (save-excursion
+                                    (and
+                                     (c-go-up-list-backward)
+                                     (eq (char-after) ?\()
+                                     (progn (c-backward-syntactic-ws)
+                                            (c-simple-skip-symbol-backward))
+                                     (looking-at c-paren-stmt-key))))))))
+                     found)
                    (eq (char-before) ?\[)
                    (c-go-up-list-forward))
             (setq brackets-after-id t))
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 3b455fc..84d4eab 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -1334,6 +1334,21 @@ operators."
 (c-lang-defvar c-multichar->-op-not->>-regexp
   (c-lang-const c-multichar->-op-not->>-regexp))
 
+(c-lang-defconst c-:-op-cont-tokens
+  ;; A list of second and subsequent characters of all multicharacter tokens
+  ;; that begin with ":".
+  t (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
+                 t
+                 "\\`:."
+                 (lambda (op) (substring op 1))))
+
+(c-lang-defconst c-:-op-cont-regexp
+  ;; Regexp matching the second and subsequent characters of all
+  ;; multicharacter tokens that begin with ":".
+  t (c-make-keywords-re nil (c-lang-const c-:-op-cont-tokens)))
+(c-lang-defvar c-:-op-cont-regexp
+  (c-lang-const c-:-op-cont-regexp))
+
 (c-lang-defconst c-stmt-delim-chars
   ;; The characters that should be considered to bound statements.  To
   ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to



reply via email to

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