Function: push-window-buffer-onto-prev
push-window-buffer-onto-prev is a byte-compiled function defined in
window.el.gz.
Signature
(push-window-buffer-onto-prev &optional WINDOW)
Documentation
Push entry for WINDOW's buffer onto WINDOW's prev-buffers list.
WINDOW must be a live window and defaults to the selected one.
Any duplicate entries for the buffer in the list are removed.
Source Code
;; Defined in /usr/src/emacs/lisp/window.el.gz
;;; Windows and buffers.
;; `prev-buffers' and `next-buffers' are two reserved window slots used
;; for (1) determining which buffer to show in the window when its
;; buffer shall be buried or killed and (2) which buffer to show for
;; `switch-to-prev-buffer' and `switch-to-next-buffer'.
;; `prev-buffers' consists of <buffer, window-start, window-point>
;; triples. The entries on this list are ordered by the time their
;; buffer has been removed from the window, the most recently removed
;; buffer's entry being first. The window-start and window-point
;; components are `window-start' and `window-point' at the time the
;; buffer was removed from the window which implies that the entry must
;; be added when `set-window-buffer' removes the buffer from the window.
;; `next-buffers' is the list of buffers that have been replaced
;; recently by `switch-to-prev-buffer'. These buffers are the least
;; preferred candidates of `switch-to-prev-buffer' and the preferred
;; candidates of `switch-to-next-buffer' to switch to. This list is
;; reset to nil by any action changing the window's buffer with the
;; exception of `switch-to-prev-buffer' and `switch-to-next-buffer'.
;; `switch-to-prev-buffer' pushes the buffer it just replaced on it,
;; `switch-to-next-buffer' pops the last pushed buffer from it.
;; Both `prev-buffers' and `next-buffers' may reference killed buffers
;; if such a buffer was killed while the window was hidden within a
;; window configuration. Such killed buffers get removed whenever
;; `switch-to-prev-buffer' or `switch-to-next-buffer' encounter them.
;; The following function is called by `set-window-buffer' _before_ it
;; replaces the buffer of the argument window with the new buffer.
(defun push-window-buffer-onto-prev (&optional window)
"Push entry for WINDOW's buffer onto WINDOW's prev-buffers list.
WINDOW must be a live window and defaults to the selected one.
Any duplicate entries for the buffer in the list are removed."
(let* ((window (window-normalize-window window t))
(buffer (window-buffer window))
(w-list (window-prev-buffers window))
(entry (assq buffer w-list)))
(when entry
(setq w-list (assq-delete-all buffer w-list)))
(let ((start (window-start window))
(point (window-point window)))
(setq entry
(cons buffer
(with-current-buffer buffer
(if entry
;; We have an entry, update marker positions.
(list (set-marker (nth 1 entry) start)
(set-marker (nth 2 entry) point))
(list (copy-marker start)
(copy-marker
;; Preserve window-point-insertion-type
;; (Bug#12855)
point window-point-insertion-type))))))
(set-window-prev-buffers window (cons entry w-list)))))