aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2017-05-12 21:11:49 +0000
committerAlan Mackenzie2017-05-12 21:11:49 +0000
commit0e09d00f29e370ecfe2f2b22acff7b98c448bc30 (patch)
tree4891922642a9348d6921ed3d75af37c3faee857e
parentafd8c762b7bb534f5686a0273f42cb7cd08e0d6f (diff)
downloademacs-0e09d00f29e370ecfe2f2b22acff7b98c448bc30.tar.gz
emacs-0e09d00f29e370ecfe2f2b22acff7b98c448bc30.zip
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.
-rw-r--r--lisp/progmodes/cc-engine.el25
-rw-r--r--lisp/progmodes/cc-langs.el15
2 files changed, 38 insertions, 2 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 6d7bab7a65c..9773b1ca85b 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."
8092 ;; initializing brace lists. 8092 ;; initializing brace lists.
8093 (let (found) 8093 (let (found)
8094 (while 8094 (while
8095 (and (setq found (c-syntactic-re-search-forward 8095 (and (progn
8096 "[;,]\\|\\s)\\|\\'\\|\\(=\\|\\s(\\)" limit t t)) 8096 ;; In the next loop, we keep searching forward whilst
8097 ;; we find ":"s which aren't single colons inside C++
8098 ;; "for" statements.
8099 (while
8100 (and
8101 (setq found
8102 (c-syntactic-re-search-forward
8103 "[;:,]\\|\\s)\\|\\'\\|\\(=\\|\\s(\\)"
8104 limit t t))
8105 (eq (char-before) ?:)
8106 (if (looking-at c-:-op-cont-regexp)
8107 (progn (goto-char (match-end 0)) t)
8108 (not
8109 (and (c-major-mode-is 'c++-mode)
8110 (save-excursion
8111 (and
8112 (c-go-up-list-backward)
8113 (eq (char-after) ?\()
8114 (progn (c-backward-syntactic-ws)
8115 (c-simple-skip-symbol-backward))
8116 (looking-at c-paren-stmt-key))))))))
8117 found)
8097 (eq (char-before) ?\[) 8118 (eq (char-before) ?\[)
8098 (c-go-up-list-forward)) 8119 (c-go-up-list-forward))
8099 (setq brackets-after-id t)) 8120 (setq brackets-after-id t))
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 3b455fc0908..84d4eab75af 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -1334,6 +1334,21 @@ operators."
1334(c-lang-defvar c-multichar->-op-not->>-regexp 1334(c-lang-defvar c-multichar->-op-not->>-regexp
1335 (c-lang-const c-multichar->-op-not->>-regexp)) 1335 (c-lang-const c-multichar->-op-not->>-regexp))
1336 1336
1337(c-lang-defconst c-:-op-cont-tokens
1338 ;; A list of second and subsequent characters of all multicharacter tokens
1339 ;; that begin with ":".
1340 t (c-filter-ops (c-lang-const c-all-op-syntax-tokens)
1341 t
1342 "\\`:."
1343 (lambda (op) (substring op 1))))
1344
1345(c-lang-defconst c-:-op-cont-regexp
1346 ;; Regexp matching the second and subsequent characters of all
1347 ;; multicharacter tokens that begin with ":".
1348 t (c-make-keywords-re nil (c-lang-const c-:-op-cont-tokens)))
1349(c-lang-defvar c-:-op-cont-regexp
1350 (c-lang-const c-:-op-cont-regexp))
1351
1337(c-lang-defconst c-stmt-delim-chars 1352(c-lang-defconst c-stmt-delim-chars
1338 ;; The characters that should be considered to bound statements. To 1353 ;; The characters that should be considered to bound statements. To
1339 ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to 1354 ;; optimize `c-crosses-statement-barrier-p' somewhat, it's assumed to