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.
This commit is contained in:
Noam Postavsky 2018-01-21 15:13:25 -05:00
parent 203059a95e
commit 16c2b38bce
2 changed files with 25 additions and 1 deletions

View File

@ -297,6 +297,30 @@ attention to case differences."
;; (should (string= (yas--buffer-contents) ;; (should (string= (yas--buffer-contents)
;; "brother from another mother!")))) ;; "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) (defun yas-test-expand-and-undo (mode snippet-entry initial-contents)
(yas-with-snippet-dirs (yas-with-snippet-dirs
`((".emacs.d/snippets" (,(symbol-name mode) ,snippet-entry))) `((".emacs.d/snippets" (,(symbol-name mode) ,snippet-entry)))

View File

@ -3869,7 +3869,7 @@ After revival, push the `yas--take-care-of-redo' in the
(when (yas--maybe-move-to-active-field snippet) (when (yas--maybe-move-to-active-field snippet)
(setf (yas--snippet-control-overlay snippet) (yas--make-control-overlay snippet beg end)) (setf (yas--snippet-control-overlay snippet) (yas--make-control-overlay snippet beg end))
(overlay-put (yas--snippet-control-overlay snippet) 'yas--snippet snippet) (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))) buffer-undo-list)))
(defun yas--snippet-create (content expand-env begin end) (defun yas--snippet-create (content expand-env begin end)