emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 7eef16a: C++ Mode. Fix anomaly occurring when a ">"


From: Alan Mackenzie
Subject: [Emacs-diffs] master 7eef16a: C++ Mode. Fix anomaly occurring when a ">" is deleted then reinserted.
Date: Thu, 13 Jul 2017 15:59:57 -0400 (EDT)

branch: master
commit 7eef16a923fa54ec0a88e00e75176a844dbd2944
Author: Alan Mackenzie <address@hidden>
Commit: Alan Mackenzie <address@hidden>

    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.
---
 lisp/progmodes/cc-engine.el |  9 ++++++++
 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 e880bd3..22f5b90 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."
   ;; 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)))
 
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 23044b1..bf0439f 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."
        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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]