Function: vundo--find-last-saved

vundo--find-last-saved is a natively compiled function defined in vundo.el.

Signature

(vundo--find-last-saved NODE &optional ARG)

Documentation

Return the last saved node prior to NODE.

ARG (default 1) specifies the number of saved nodes to move backwards in history. ARG<0 indicates moving that many saved nodes forward in history. Returns nil if no such saved node exists.

Source Code

;; Defined in /nix/store/386w2ds6bdh3gcz9k23jssw4cni4lfr2-emacs-packages-deps/share/emacs/site-lisp/elpa/vundo-2.4.0/vundo.el
(defun vundo--find-last-saved (node &optional arg)
  "Return the last saved node prior to NODE.
ARG (default 1) specifies the number of saved nodes to move
backwards in history.  ARG<0 indicates moving that many saved
nodes forward in history.  Returns nil if no such saved node
exists."
  (let* ((arg (or arg 1))
         (past (>= arg 0))
         (cnt (abs arg))
         (master (vundo--master-eqv-mod-of node))
         (midx (vundo-m-idx master))
         last-node)
    (if (assq master vundo--timestamps)
        (setq last-node master)
      ;; No timestamp here, find closest master idx on saved list in
      ;; the direction indicated by ARG.
      (cl-loop with val = (if past -1 most-positive-fixnum)
               with between = (if past #'< #'>)
               for (n . _) in vundo--timestamps
               for idx = (vundo-m-idx n)
               if (funcall between val idx midx)
               do (setq val idx last-node n))
      ;; Use up one count when getting started.
      (when last-node (setq cnt (1- cnt))))

    ;; Found one, but more to go.
    (if (and last-node (> cnt 0))
        (let ((vt (if past vundo--timestamps
                    (reverse vundo--timestamps))))
          (while (and vt (not (eq (caar vt) last-node)))
            (setq vt (cdr vt)))
          (caar (nthcdr cnt vt)))
      last-node)))