Subject: Re: bug#39680: 27.0.60; electric-pair-mode broken by undo

From: Kévin Le Gouguec <[email-masked]>
Date: Wed, 13 May 2020 12:08:30 +0200

unarchive 39680
thanks

João Távora <[email-masked]> writes:

> If you see this consistently failing when you revert the earlier fix and
> passing now, I'd just add it to test/lisp/electric-tests.el.

Thank you for prompting me to check; infuriatingly, this test does *not*
fail when reverting Stefan's fix, although the manual recipe (39680#5)
fails consistently.  Obviously I'm missing something and the test needs
more work.

>                                                               A short
> docstring summarily explaining what is being tested is useful.  Or maybe
> not, I think can read it without it.

FWIW I've added a docstring and moved the test to electric-tests.el,
right after the "backspacing" tests.

diff --git a/test/lisp/electric-tests.el b/test/lisp/electric-tests.el
index 6334c62a31..d259f31a4c 100644
--- a/test/lisp/electric-tests.el
+++ b/test/lisp/electric-tests.el
@@ -545,6 +545,22 @@ js-mode-braces-with-layout-and-indent
       (goto-char 2)
       (electric-pair-delete-pair 1)
       (should (equal "" (buffer-string))))))
+
+;;; Undoing
+(ert-deftest electric-pair-undo-unrelated-state ()
+  "Make sure `undo' does not get confused by `electric-pair-mode' (bug#39680)."
+  (with-temp-buffer
+    (buffer-enable-undo)
+    (electric-pair-local-mode)
+    (let ((last-command-event ?\())
+      (self-insert-command 1))
+    (undo-boundary)
+    (insert "a")
+    (undo-boundary)
+    (call-interactively #'undo)
+    (let ((last-command-event ?\())
+      (self-insert-command 1))
+    (should (string= (buffer-string) "(())"))))
 
 
 ;;; Electric newlines between pairs