mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 05:03:04 +00:00
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.
This commit is contained in:
parent
e45e3de357
commit
476bc77c34
@ -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))
|
||||
|
@ -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)))
|
||||
|
@ -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))))
|
||||
|
Loading…
x
Reference in New Issue
Block a user