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.
This commit is contained in:
Alan Mackenzie 2022-08-31 18:46:06 +00:00
parent dbfe57472e
commit 71b7ad0cf7
2 changed files with 20 additions and 15 deletions

View file

@ -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.

View file

@ -934,17 +934,16 @@ casts and declarations are fontified. Used on level 2 and higher."
(save-excursion
(let ((pos (point)))
(c-backward-syntactic-ws (max (- (point) 500) (point-min)))
(c-clear-char-properties
(if (and (not (bobp))
(memq (c-get-char-property (1- (point)) 'c-type)
'(c-decl-arg-start
c-decl-end
c-decl-id-start
c-decl-type-start
c-not-decl)))
(1- (point))
pos)
limit 'c-type)))
(when (and (not (bobp))
(memq (c-get-char-property (1- (point)) 'c-type)
'(c-decl-arg-start
c-decl-end
c-decl-id-start
c-decl-type-start
c-not-decl)))
(setq pos (1- (point))))
(c-clear-char-properties pos limit 'c-type)
(c-clear-char-properties pos limit 'c-<>-c-types-set)))
;; Update `c-state-cache' to the beginning of the region. This will
;; make `c-beginning-of-syntax' go faster when it's used later on,