Function: dirvish--clear-session
dirvish--clear-session is a natively compiled function defined in
dirvish.el.
Signature
(dirvish--clear-session DV &optional FROM-QUIT)
Documentation
Reset DV's slot and kill its buffers.
FROM-QUIT is used to signify the calling command.
Source Code
;; Defined in /nix/store/1gijwny2yx4fggrsb9l110h1ybs1gdk5-emacs-packages-deps/share/emacs/site-lisp/elpa/dirvish-20260725.1520/dirvish.el
(defun dirvish--clear-session (dv &optional from-quit)
"Reset DV's slot and kill its buffers.
FROM-QUIT is used to signify the calling command."
(let* ((idx (dv-index dv)) (ff (dv-curr-layout dv)) (wcon (dv-winconf dv))
(server-buf? (lambda (root) (with-current-buffer (cdr root)
(bound-and-true-p server-buffer-clients))))
(keep (list idx)) roots kill-buffer-hook)
(cl-loop with killer = (lambda (r) (unless (member r keep) (kill-buffer (cdr r))))
for root in (setq roots (dv-roots dv))
if (or (get-buffer-window (cdr root)) (funcall server-buf? root))
do (cl-pushnew root keep :test #'equal)
finally do (mapc killer roots))
(when (and ff wcon) (set-window-configuration wcon))
(set-window-fringes
nil (frame-parameter nil 'left-fringe) (frame-parameter nil 'left-fringe))
(mapc #'dirvish--kill-buffer (dv-preview-buffers dv))
(mapc #'dirvish--kill-buffer (dv-special-buffers dv))
(when (or (null dirvish-reuse-session)
(eq dirvish-reuse-session (if from-quit 'open 'quit)))
(unless (or (funcall server-buf? idx) ; client buf or displayed elsewhere
(length> (get-buffer-window-list (cdr idx)) 1))
(kill-buffer (cdr idx))))
(setq roots (cl-remove-if-not (lambda (i) (buffer-live-p (cdr i))) keep))
(setf (dv-preview-hash dv) (dirvish--ht) (dv-parent-hash dv) (dirvish--ht)
(dv-roots dv) roots (dv-index dv) (car roots)
(dv-preview-buffers dv) nil (dv-winconf dv) nil)
(unless roots (remhash (dv-id dv) dirvish--sessions))))