Function: vundo--move-to-node
vundo--move-to-node is a natively compiled function defined in
vundo.el.
Signature
(vundo--move-to-node CURRENT DEST ORIG-BUFFER MOD-LIST)
Documentation
Move from CURRENT node to DEST node by undoing in ORIG-BUFFER.
ORIG-BUFFER must be at CURRENT state. MOD-LIST is the list you
get from vundo--mod-list-from. You should refresh vundo buffer
after calling this function. (You can call this function
repeatedly before refreshing, but moving back-and-forth might not
work, see docstring of ‘vundo--trim-undo-list’.)
This function modifies the content of ORIG-BUFFER.
Source Code
;; Defined in /nix/store/386w2ds6bdh3gcz9k23jssw4cni4lfr2-emacs-packages-deps/share/emacs/site-lisp/elpa/vundo-2.4.0/vundo.el
(defun vundo--move-to-node (current dest orig-buffer mod-list)
"Move from CURRENT node to DEST node by undoing in ORIG-BUFFER.
ORIG-BUFFER must be at CURRENT state. MOD-LIST is the list you
get from `vundo--mod-list-from'. You should refresh vundo buffer
after calling this function. (You can call this function
repeatedly before refreshing, but moving back-and-forth might not
work, see docstring of ‘vundo--trim-undo-list’.)
This function modifies the content of ORIG-BUFFER."
(cl-assert (not (eq current dest)))
;; 1. Find the route we want to take.
(if-let* ((route (vundo--calculate-shortest-route current dest)))
(let* ((source-idx (car route))
(dest-idx (car (last route)))
;; The complete undo-list that stops at SOURCE.
(undo-list-at-source
(vundo-m-undo-list (aref mod-list source-idx)))
;; The complete undo-list that stops at DEST.
(undo-list-at-dest
(vundo-m-undo-list (aref mod-list dest-idx)))
;; We will undo these modifications.
(planned-undo (vundo--list-subtract
undo-list-at-source undo-list-at-dest))
;; We don’t want to quit in the middle of this function.
(inhibit-quit t))
(with-current-buffer orig-buffer
(setq-local buffer-read-only t)
;; 2. Undo. This will undo modifications in PLANNED-UNDO and
;; add new entries to `buffer-undo-list'.
(let ((undo-in-progress t))
(cl-loop
for step = (- source-idx dest-idx)
then (1- step)
while (and (> step 0)
;; If there is a quit signal, we break the
;; loop, continue to step 3 and 4, then quits
;; when we go out of the let-form.
(not quit-flag))
for stop = (1- source-idx) then (1- stop)
do
(progn
;; Stop at each intermediate stop along the route to
;; create trim points for future undo.
(setq planned-undo (primitive-undo 1 planned-undo))
(cl-assert (not (and (consp buffer-undo-list)
(null (car buffer-undo-list)))))
(let ((undo-list-at-stop
(vundo-m-undo-list (aref mod-list stop))))
(puthash buffer-undo-list (or undo-list-at-stop t)
undo-equiv-table))
(push nil buffer-undo-list))))
;; 3. Some misc work.
(when vundo--message
(message "%s -> %s Steps: %s Undo-list len: %s"
(mapcar #'vundo-m-idx (vundo--eqv-list-of
(aref mod-list source-idx)))
(mapcar #'vundo-m-idx (vundo--eqv-list-of
(aref mod-list dest-idx)))
(length planned-undo)
(length buffer-undo-list)))
(when-let ((win (get-buffer-window)))
(set-window-point win (point)))))
(error "No possible route")))