diff options
| author | Alan Mackenzie | 2017-07-13 19:56:00 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2017-07-13 19:56:00 +0000 |
| commit | 7eef16a923fa54ec0a88e00e75176a844dbd2944 (patch) | |
| tree | efbc000f0b52351b7ac0321f42cb06c282e5df2e | |
| parent | 1f08279e1b20bd1e07132b6ee0a25a154811615a (diff) | |
| download | emacs-7eef16a923fa54ec0a88e00e75176a844dbd2944.tar.gz emacs-7eef16a923fa54ec0a88e00e75176a844dbd2944.zip | |
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.
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 9 | ||||
| -rw-r--r-- | lisp/progmodes/cc-mode.el | 51 |
2 files changed, 39 insertions, 21 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index e880bd39321..22f5b906e4e 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -6091,6 +6091,13 @@ comment at the start of cc-engine.el for more info." | |||
| 6091 | ;; Clears `c-found-types'. | 6091 | ;; Clears `c-found-types'. |
| 6092 | (setq c-found-types (make-vector 53 0))) | 6092 | (setq c-found-types (make-vector 53 0))) |
| 6093 | 6093 | ||
| 6094 | (defun c-copy-found-types () | ||
| 6095 | (let ((copy (make-vector 53 0))) | ||
| 6096 | (mapatoms (lambda (sym) | ||
| 6097 | (intern (symbol-name sym) copy)) | ||
| 6098 | c-found-types) | ||
| 6099 | copy)) | ||
| 6100 | |||
| 6094 | (defun c-add-type (from to) | 6101 | (defun c-add-type (from to) |
| 6095 | ;; Add the given region as a type in `c-found-types'. If the region | 6102 | ;; Add the given region as a type in `c-found-types'. If the region |
| 6096 | ;; doesn't match an existing type but there is a type which is equal | 6103 | ;; 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." | |||
| 7059 | ;; This function might do hidden buffer changes. | 7066 | ;; This function might do hidden buffer changes. |
| 7060 | 7067 | ||
| 7061 | (let ((start (point)) | 7068 | (let ((start (point)) |
| 7069 | (old-found-types (c-copy-found-types)) | ||
| 7062 | ;; If `c-record-type-identifiers' is set then activate | 7070 | ;; If `c-record-type-identifiers' is set then activate |
| 7063 | ;; recording of any found types that constitute an argument in | 7071 | ;; recording of any found types that constitute an argument in |
| 7064 | ;; the arglist. | 7072 | ;; the arglist. |
| @@ -7074,6 +7082,7 @@ comment at the start of cc-engine.el for more info." | |||
| 7074 | (nconc c-record-found-types c-record-type-identifiers))) | 7082 | (nconc c-record-found-types c-record-type-identifiers))) |
| 7075 | t) | 7083 | t) |
| 7076 | 7084 | ||
| 7085 | (setq c-found-types old-found-types) | ||
| 7077 | (goto-char start) | 7086 | (goto-char start) |
| 7078 | nil))) | 7087 | nil))) |
| 7079 | 7088 | ||
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index 23044b1f4f4..bf0439ffe8a 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el | |||
| @@ -437,27 +437,36 @@ preferably use the `c-mode-menu' language constant directly." | |||
| 437 | t)))) | 437 | t)))) |
| 438 | 438 | ||
| 439 | (defun c-unfind-coalesced-tokens (beg end) | 439 | (defun c-unfind-coalesced-tokens (beg end) |
| 440 | ;; unless the non-empty region (beg end) is entirely WS and there's at | 440 | ;; If removing the region (beg end) would coalesce an identifier ending at |
| 441 | ;; least one character of WS just before or after this region, remove | 441 | ;; beg with an identifier (fragment) beginning at end, or an identifier |
| 442 | ;; the tokens which touch the region from `c-found-types' should they | 442 | ;; fragment ending at beg with an identifier beginning at end, remove the |
| 443 | ;; be present. | 443 | ;; pertinent identifier(s) from `c-found-types'. |
| 444 | (or (c-partial-ws-p beg end) | 444 | (save-excursion |
| 445 | (save-excursion | 445 | (when (< beg end) |
| 446 | (progn | 446 | (goto-char beg) |
| 447 | (goto-char beg) | 447 | (when |
| 448 | (or (eq beg (point-min)) | 448 | (and (not (bobp)) |
| 449 | (c-skip-ws-backward (1- beg)) | 449 | (progn (c-backward-syntactic-ws) (eq (point) beg)) |
| 450 | (/= (point) beg) | 450 | (/= (skip-chars-backward c-symbol-chars (1- (point))) 0) |
| 451 | (= (c-backward-token-2) 1) | 451 | (progn (goto-char beg) (c-forward-syntactic-ws) (<= (point) end)) |
| 452 | (c-unfind-type (buffer-substring-no-properties | 452 | (> (point) beg) |
| 453 | (point) beg))) | 453 | (goto-char end) |
| 454 | (goto-char end) | 454 | (looking-at c-symbol-char-key)) |
| 455 | (or (eq end (point-max)) | 455 | (goto-char beg) |
| 456 | (c-skip-ws-forward (1+ end)) | 456 | (c-simple-skip-symbol-backward) |
| 457 | (/= (point) end) | 457 | (c-unfind-type (buffer-substring-no-properties (point) beg))) |
| 458 | (progn (forward-char) (c-end-of-current-token) nil) | 458 | |
| 459 | (c-unfind-type (buffer-substring-no-properties | 459 | (goto-char end) |
| 460 | end (point)))))))) | 460 | (when |
| 461 | (and (not (eobp)) | ||
| 462 | (progn (c-forward-syntactic-ws) (eq (point) end)) | ||
| 463 | (looking-at c-symbol-char-key) | ||
| 464 | (progn (c-backward-syntactic-ws) (>= (point) beg)) | ||
| 465 | (< (point) end) | ||
| 466 | (/= (skip-chars-backward c-symbol-chars (1- (point))) 0)) | ||
| 467 | (goto-char (1+ end)) | ||
| 468 | (c-end-of-current-token) | ||
| 469 | (c-unfind-type (buffer-substring-no-properties end (point))))))) | ||
| 461 | 470 | ||
| 462 | ;; c-maybe-stale-found-type records a place near the region being | 471 | ;; c-maybe-stale-found-type records a place near the region being |
| 463 | ;; changed where an element of `found-types' might become stale. It | 472 | ;; changed where an element of `found-types' might become stale. It |