emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] master 476bc77 35/42: Fix snippet undo


From: Noam Postavsky
Subject: [elpa] master 476bc77 35/42: Fix snippet undo
Date: Sun, 22 Dec 2019 17:38:02 -0500 (EST)

branch: master
commit 476bc77c34edc9ff24ed39c55ab1b1baa103d39a
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>

    Fix snippet undo
    
    * yasnippet.el (yas--snippet-revive): Add revived snippet to
    yas--active-snippets.
    * yasnippet-debug.el (yas-debug-snippets): Print yas--active-snippets
    length.
    * yasnippet-tests.el (undo-revive-and-do-again): New test.
---
 yasnippet-debug.el |  2 ++
 yasnippet-tests.el | 25 +++++++++++++++++++++++++
 yasnippet.el       |  1 +
 3 files changed, 28 insertions(+)

diff --git a/yasnippet-debug.el b/yasnippet-debug.el
index 38d7a3a..d33e8a5 100644
--- a/yasnippet-debug.el
+++ b/yasnippet-debug.el
@@ -254,6 +254,8 @@ buffer-locally, otherwise install it globally.  If HOOK is
             (setq yas-debug-target-snippets
                   (cl-delete-if-not #'yas--snippet-p 
yas-debug-target-snippets)))
           (let ((yas-debug-recently-live-indicators nil))
+            (printf "(length yas--snippets-snippets) => %d\n"
+                    (length yas--active-snippets))
             (dolist (snippet (or yas-debug-target-snippets
                                  (yas-active-snippets)))
               (printf "snippet %d\n" (yas--snippet-id snippet))
diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index 7791db8..cdd42bf 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -346,6 +346,31 @@ attention to case differences."
         (ert-simulate-command '(undo))  ; Redo (re-expand snippet).
         (should (string-match-p "\\`one,and done" (buffer-string)))))))
 
+(ert-deftest undo-revive-and-do-again ()
+  "Check undo-revived snippet is properly ended."
+  ;; See https://github.com/joaotavora/yasnippet/issues/1006.
+  (yas-with-snippet-dirs '((".emacs.d/snippets"
+                            ("emacs-lisp-mode" ("x" . "${1:one},and done"))))
+    (with-temp-buffer
+      (emacs-lisp-mode)
+      (yas-reload-all)
+      (yas-minor-mode 1)
+      (yas-expand-snippet "x$0")
+      (setq buffer-undo-list nil)
+      (ert-simulate-command '(yas-expand))
+      (push nil buffer-undo-list)
+      (ert-simulate-command '(yas-next-field)) ; $1 -> exit snippet.
+      (should (string-match-p "\\`one,and done" (buffer-string)))
+      (push nil buffer-undo-list)
+      (ert-simulate-command '(undo))    ; Revive snippet.
+      (yas-mock-insert "abc")
+      (ert-simulate-command '(yas-next-field)) ; $1 -> exit snippet again.
+      (should (string-match-p "\\`abc,and done" (buffer-string)))
+      ;; We should have exited snippet and cleaned up any overlays.
+      (should-not (cl-some (lambda (o) (overlay-get o 'yas--snippet))
+                           (overlays-in (point-min) (point-max)))))))
+
+
 (defun yas-test-expand-and-undo (mode snippet-entry initial-contents)
   (yas-with-snippet-dirs
    `((".emacs.d/snippets" (,(symbol-name mode) ,snippet-entry)))
diff --git a/yasnippet.el b/yasnippet.el
index 9951940..67cecb8 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -4149,6 +4149,7 @@ After revival, push the `yas--take-care-of-redo' in the
   (when (yas--maybe-move-to-active-field snippet)
     (setf (yas--snippet-control-overlay snippet) (yas--make-control-overlay 
snippet beg end))
     (overlay-put (yas--snippet-control-overlay snippet) 'yas--snippet snippet)
+    (push snippet yas--active-snippets)
     (when (listp buffer-undo-list)
       (push `(apply yas--take-care-of-redo ,snippet)
             buffer-undo-list))))



reply via email to

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