branch: master
commit 16c2b38bce60d455fd93f6187ac020e6236e79e9
Author: Noam Postavsky <[email protected]>
Commit: Noam Postavsky <[email protected]>
Update `yas--take-care-of-redo' call in buffer undo list
On 2018-01-01 "Fix undo when first line indentation moves snippet
forward", `yas--take-care-of-redo' removed the BEG and END arguments,
but the call added to `buffer-undo-list' from `yas--snippet-revive',
was not updated accordingly.
* yasnippet.el (yas--snippet-revive): Remove `beg' and `end' from
`yas--take-care-of-redo' entry.
* yasnippet-tests.el (undo-redo): New test.
---
yasnippet-tests.el | 24 ++++++++++++++++++++++++
yasnippet.el | 2 +-
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index 1851986..1b62fa6 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -297,6 +297,30 @@ attention to case differences."
;; (should (string= (yas--buffer-contents)
;; "brother from another mother!"))))
+(ert-deftest undo-redo ()
+ "Check redoing of snippet undo."
+ (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")
+ (let ((pre-expand-string (buffer-string)))
+ (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.
+ (ert-simulate-command '(undo)) ; Undo expansion.
+ (should (string= (buffer-string) pre-expand-string))
+ (ert-simulate-command '(move-end-of-line 1))
+ (push nil buffer-undo-list)
+ (ert-simulate-command '(undo)) ; Redo (re-expand snippet).
+ (should (string-match-p "\\`one,and done" (buffer-string)))))))
+
(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 a12baf9..ac8a01d 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -3869,7 +3869,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 `(apply yas--take-care-of-redo ,beg ,end ,snippet)
+ (push `(apply yas--take-care-of-redo ,snippet)
buffer-undo-list)))
(defun yas--snippet-create (content expand-env begin end)