From 71b7ad0cf7dc85b786ba225ff84f842459ba4581 Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Wed, 31 Aug 2022 18:46:06 +0000 Subject: C++ Mode: Fontify functions correctly with commas in template expressions This fixes bug #57318. Also apply an optimization which marks generic expressions as already analyzed, thus avoiding repeating this analysis when not needed. This optimization prevents the fix slowing down scrolling when the C++ source has lots of template structures. * lisp/progmodes/cc-engine.el (top-level) Near the beginning of the file, add a comment describing the new text property c-<>-c-types-set. (c-update-brace-stack): Bind c-restricted-<>-arglists to nil rather than t around the call to c-forward-<>-arglist. (c-forward-<>-arglist-recur): Allow the abbreviated analysis of a generic expression also when the opening < is marked with a c-<>-c-types-set text property. Set this property at the same time as the c-type properties are set on the commas inside the template structure. * lisp/progmodes/cc-fonts.el (c-font-lock-complex-decl-prepare): Clear the c-<>-c-types-set text property, along with c-type, from the region being fontified. --- lisp/progmodes/cc-engine.el | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'lisp/progmodes/cc-engine.el') diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index b2d1f15d398..94225d6e3e9 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el @@ -142,6 +142,11 @@ ;; Put on the brace which introduces a brace list and on the commas ;; which separate the elements within it. ;; +;; 'c-<>-c-types-set +;; This property is set on an opening angle bracket, and indicates that +;; any "," separators within the template/generic expression have been +;; marked with a 'c-type property value 'c-<>-arg-sep (see above). +;; ;; 'c-awk-NL-prop ;; Used in AWK mode to mark the various kinds of newlines. See ;; cc-awk.el. @@ -6137,7 +6142,7 @@ comment at the start of cc-engine.el for more info." (forward-char)))) (backward-char) (if (let ((c-parse-and-markup-<>-arglists t) - (c-restricted-<>-arglists t)) + c-restricted-<>-arglists) (c-forward-<>-arglist nil)) ; Should always work. (when (> (point) to) (setq bound-<> (point))) @@ -8505,9 +8510,9 @@ multi-line strings (but not C++, for example)." arg-start-pos) ;; If the '<' has paren open syntax then we've marked it as an angle ;; bracket arglist before, so skip to the end. - (if (and (not c-parse-and-markup-<>-arglists) - syntax-table-prop-on-<) - + (if (and syntax-table-prop-on-< + (or (not c-parse-and-markup-<>-arglists) + (c-get-char-property (point) 'c-<>-c-types-set))) (progn (forward-char) (if (and (c-go-up-list-forward) @@ -8604,6 +8609,7 @@ multi-line strings (but not C++, for example)." (c-unmark-<->-as-paren (point))))) (c-mark-<-as-paren start) (c-mark->-as-paren (1- (point))) + (c-put-char-property start 'c-<>-c-types-set t) (c-truncate-lit-pos-cache start)) (setq res t) nil)) ; Exit the loop. -- cgit v1.2.3