Function: vundo--calculate-shortest-route
vundo--calculate-shortest-route is a natively compiled function
defined in vundo.el.
Signature
(vundo--calculate-shortest-route FROM TO)
Documentation
Calculate the shortest route from FROM to TO node.
Return (SOURCE STOP1 STOP2 ... DEST), meaning you should undo the modifications from DEST to SOURCE. Each STOP is an intermediate stop. Eg, (6 5 4 3). Return nil if there’s no valid route.
Source Code
;; Defined in /nix/store/386w2ds6bdh3gcz9k23jssw4cni4lfr2-emacs-packages-deps/share/emacs/site-lisp/elpa/vundo-2.4.0/vundo.el
;;; Traverse undo tree
(defun vundo--calculate-shortest-route (from to)
"Calculate the shortest route from FROM to TO node.
Return (SOURCE STOP1 STOP2 ... DEST), meaning you should undo the
modifications from DEST to SOURCE. Each STOP is an intermediate
stop. Eg, (6 5 4 3). Return nil if there’s no valid route."
(let (route-list)
;; Find all valid routes.
(dolist (source (vundo--eqv-list-of from))
(dolist (dest (vundo--eqv-list-of to))
;; We only allow route in this direction.
(if (> (vundo-m-idx source) (vundo-m-idx dest))
(push (cons (vundo-m-idx source)
(vundo-m-idx dest))
route-list))))
;; Find the shortest route.
(setq route-list
(seq-sort
(lambda (r1 r2)
;; Ie, distance between SOURCE and DEST in R1 compare
;; against distance in R2.
(< (- (car r1) (cdr r1)) (- (car r2) (cdr r2))))
route-list))
(if-let* ((route (car route-list))
(source (car route))
(dest (cdr route)))
(number-sequence source dest -1))))