C++ Mode. Fix anomaly occurring when a ">" is deleted then reinserted.
This fontification anomaly happened because after deleting the ">", c-forward-<>-arglist parses the preceding identifier as a putative type but stores it in c-found-types before it becomes clear it is not an unambiguous type. c-forward-<>-arglist fails, leaving the spurious type id in c-found-types. Fix this by "binding" c-found-types "to itself" in c-forward-<>-arglist, and restoring the original value when that function call fails. * lisp/progmodes/cc-engine.el (c-copy-found-types): New function. (c-forward-<>-arglist): Record the original value of c-found-types at the beginning of the function, and restore it at the end on failure. * lisp/progmodes/cc-mode.el (c-unfind-coalesced-tokens): Rewrite more accurately.
This commit is contained in:
parent
1f08279e1b
commit
7eef16a923
2 changed files with 39 additions and 21 deletions
|
@ -6091,6 +6091,13 @@ comment at the start of cc-engine.el for more info."
|
|||
;; Clears `c-found-types'.
|
||||
(setq c-found-types (make-vector 53 0)))
|
||||
|
||||
(defun c-copy-found-types ()
|
||||
(let ((copy (make-vector 53 0)))
|
||||
(mapatoms (lambda (sym)
|
||||
(intern (symbol-name sym) copy))
|
||||
c-found-types)
|
||||
copy))
|
||||
|
||||
(defun c-add-type (from to)
|
||||
;; Add the given region as a type in `c-found-types'. If the region
|
||||
;; doesn't match an existing type but there is a type which is equal
|
||||
|
@ -7059,6 +7066,7 @@ comment at the start of cc-engine.el for more info."
|
|||
;; This function might do hidden buffer changes.
|
||||
|
||||
(let ((start (point))
|
||||
(old-found-types (c-copy-found-types))
|
||||
;; If `c-record-type-identifiers' is set then activate
|
||||
;; recording of any found types that constitute an argument in
|
||||
;; the arglist.
|
||||
|
@ -7074,6 +7082,7 @@ comment at the start of cc-engine.el for more info."
|
|||
(nconc c-record-found-types c-record-type-identifiers)))
|
||||
t)
|
||||
|
||||
(setq c-found-types old-found-types)
|
||||
(goto-char start)
|
||||
nil)))
|
||||
|
||||
|
|
|
@ -437,27 +437,36 @@ preferably use the `c-mode-menu' language constant directly."
|
|||
t))))
|
||||
|
||||
(defun c-unfind-coalesced-tokens (beg end)
|
||||
;; unless the non-empty region (beg end) is entirely WS and there's at
|
||||
;; least one character of WS just before or after this region, remove
|
||||
;; the tokens which touch the region from `c-found-types' should they
|
||||
;; be present.
|
||||
(or (c-partial-ws-p beg end)
|
||||
(save-excursion
|
||||
(progn
|
||||
(goto-char beg)
|
||||
(or (eq beg (point-min))
|
||||
(c-skip-ws-backward (1- beg))
|
||||
(/= (point) beg)
|
||||
(= (c-backward-token-2) 1)
|
||||
(c-unfind-type (buffer-substring-no-properties
|
||||
(point) beg)))
|
||||
(goto-char end)
|
||||
(or (eq end (point-max))
|
||||
(c-skip-ws-forward (1+ end))
|
||||
(/= (point) end)
|
||||
(progn (forward-char) (c-end-of-current-token) nil)
|
||||
(c-unfind-type (buffer-substring-no-properties
|
||||
end (point))))))))
|
||||
;; If removing the region (beg end) would coalesce an identifier ending at
|
||||
;; beg with an identifier (fragment) beginning at end, or an identifier
|
||||
;; fragment ending at beg with an identifier beginning at end, remove the
|
||||
;; pertinent identifier(s) from `c-found-types'.
|
||||
(save-excursion
|
||||
(when (< beg end)
|
||||
(goto-char beg)
|
||||
(when
|
||||
(and (not (bobp))
|
||||
(progn (c-backward-syntactic-ws) (eq (point) beg))
|
||||
(/= (skip-chars-backward c-symbol-chars (1- (point))) 0)
|
||||
(progn (goto-char beg) (c-forward-syntactic-ws) (<= (point) end))
|
||||
(> (point) beg)
|
||||
(goto-char end)
|
||||
(looking-at c-symbol-char-key))
|
||||
(goto-char beg)
|
||||
(c-simple-skip-symbol-backward)
|
||||
(c-unfind-type (buffer-substring-no-properties (point) beg)))
|
||||
|
||||
(goto-char end)
|
||||
(when
|
||||
(and (not (eobp))
|
||||
(progn (c-forward-syntactic-ws) (eq (point) end))
|
||||
(looking-at c-symbol-char-key)
|
||||
(progn (c-backward-syntactic-ws) (>= (point) beg))
|
||||
(< (point) end)
|
||||
(/= (skip-chars-backward c-symbol-chars (1- (point))) 0))
|
||||
(goto-char (1+ end))
|
||||
(c-end-of-current-token)
|
||||
(c-unfind-type (buffer-substring-no-properties end (point)))))))
|
||||
|
||||
;; c-maybe-stale-found-type records a place near the region being
|
||||
;; changed where an element of `found-types' might become stale. It
|
||||
|
|
Loading…
Add table
Reference in a new issue