Function: consult--buffer-preview

consult--buffer-preview is a byte-compiled function defined in consult.el.

Signature

(consult--buffer-preview)

Documentation

Buffer preview function.

Source Code

;; Defined in ~/.emacs.d/elpa/consult-20260805.1130/consult.el
(defun consult--buffer-preview ()
  "Buffer preview function."
  (let ((orig-buf (window-buffer (consult--original-window)))
        (orig-prev (copy-sequence (window-prev-buffers)))
        (orig-next (copy-sequence (window-next-buffers)))
        (orig-bl (copy-sequence (frame-parameter nil 'buffer-list)))
        (orig-bbl (copy-sequence (frame-parameter nil 'buried-buffer-list)))
        other-win)
    (lambda (action cand)
      (pcase action
        ('return
         ;; Restore buffer list for the current tab
         (set-frame-parameter nil 'buffer-list orig-bl)
         (set-frame-parameter nil 'buried-buffer-list orig-bbl))
        ('exit
         (set-window-prev-buffers other-win orig-prev)
         (set-window-next-buffers other-win orig-next))
        ('preview
         ;; Prevent opening the preview in another tab, since restoring the tab
         ;; status is difficult and also costly.
         (cl-letf* (((symbol-function #'display-buffer-in-tab) #'ignore)
                    ((symbol-function #'display-buffer-in-new-tab) #'ignore))
           (when (and (eq consult--buffer-display #'switch-to-buffer-other-window)
                      (not other-win))
             (switch-to-buffer-other-window orig-buf 'norecord)
             (setq other-win (selected-window)))
           (let ((win (or other-win (selected-window)))
                 (buf (or (and cand (get-buffer cand)) orig-buf)))
             (when (and (window-live-p win) (buffer-live-p buf)
                        (not (buffer-match-p consult-preview-excluded-buffers buf)))
               (with-selected-window win
                 (unless (or orig-prev orig-next)
                   (setq orig-prev (copy-sequence (window-prev-buffers))
                         orig-next (copy-sequence (window-next-buffers))))
                 (switch-to-buffer buf 'norecord))))))))))