1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

* lisp/simple.el (undo-redo): New command

(undo--last-change-was-undo-p): New function.

* test/lisp/simple-tests.el (simple-tests--exec): New function.
(simple-tests--undo): New test.
This commit is contained in:
Stefan Monnier 2020-02-08 22:06:41 -05:00
parent fe903c5ab7
commit 2645ae1222
4 changed files with 72 additions and 0 deletions

View file

@ -2662,6 +2662,30 @@ Contrary to `undo', this will not redo a previous undo."
(interactive "*p")
(let ((undo-no-redo t)) (undo arg)))
(defun undo--last-change-was-undo-p (undo-list)
(while (and (consp undo-list) (eq (car undo-list) nil))
(setq undo-list (cdr undo-list)))
(gethash undo-list undo-equiv-table))
(defun undo-redo (&optional arg)
"Undo the last ARG undos."
(interactive "*p")
(cond
((not (undo--last-change-was-undo-p buffer-undo-list))
(user-error "No undo to undo"))
(t
(let* ((ul buffer-undo-list)
(new-ul
(let ((undo-in-progress t))
(while (and (consp ul) (eq (car ul) nil))
(setq ul (cdr ul)))
(primitive-undo arg ul)))
(new-pul (undo--last-change-was-undo-p new-ul)))
(message "Redo%s" (if undo-in-region " in region" ""))
(setq this-command 'undo)
(setq pending-undo-list new-pul)
(setq buffer-undo-list new-ul)))))
(defvar undo-in-progress nil
"Non-nil while performing an undo.
Some change-hooks test this variable to do something different.")