Function: window-deletable-p
window-deletable-p is a byte-compiled function defined in
window.el.gz.
Signature
(window-deletable-p &optional WINDOW NO-RUN)
Documentation
Return t if WINDOW can be safely deleted from its frame.
WINDOW must be a valid window and defaults to the selected one.
Return frame if WINDOW is the root window of its frame and that
frame can be safely deleted.
Return tab if WINDOW's tab can be safely closed that will
effectively delete the window.
Unless the optional argument NO-RUN is non-nil, run the abnormal hook
window-deletable-functions and return nil if any function on that hook
returns nil.
Source Code
;; Defined in /usr/src/emacs/lisp/window.el.gz
(defun window-deletable-p (&optional window no-run)
"Return t if WINDOW can be safely deleted from its frame.
WINDOW must be a valid window and defaults to the selected one.
Return `frame' if WINDOW is the root window of its frame and that
frame can be safely deleted.
Return `tab' if WINDOW's tab can be safely closed that will
effectively delete the window.
Unless the optional argument NO-RUN is non-nil, run the abnormal hook
`window-deletable-functions' and return nil if any function on that hook
returns nil."
(setq window (window-normalize-window window))
(unless (or ignore-window-parameters
(eq (window-parameter window 'delete-window) t))
;; Handle atomicity.
(when (window-parameter window 'window-atom)
(setq window (window-atom-root window))))
(let ((frame (window-frame window)))
(cond
((and (> (frame-parameter frame 'tab-bar-lines) 0)
;; Fall back to frame handling in case of less than 2 tabs.
(> (length (funcall tab-bar-tabs-function frame)) 1)
;; Close the tab with the initial window (bug#59862).
(or (eq (nth 1 (window-parameter window 'quit-restore)) 'tab)
;; Or with the only window on the frame (bug#71386).
(frame-root-window-p window))
;; Don't close the tab if more windows were created explicitly.
(< (seq-count (lambda (w)
(memq (car (window-parameter w 'quit-restore))
'(window tab frame same)))
(window-list-1 nil 'nomini frame))
2))
'tab)
((frame-root-window-p window)
;; WINDOW's frame can be deleted only if there are other frames
;; on the same terminal, and it does not contain the active
;; minibuffer.
(unless (or (not (frame-deletable-p (window-frame window)))
(or no-run
(if (window-live-p window)
(not (with-current-buffer (window-buffer window)
(run-hook-with-args-until-failure
'window-deletable-functions window t)))
(not (run-hook-with-args-until-failure
'window-deletable-functions window t)))))
'frame))
((window-minibuffer-p window)
;; If WINDOW is the minibuffer window of a non-minibuffer-only
;; frame, it cannot be deleted separately.
nil)
((and (or ignore-window-parameters
(not (eq window (window-main-window frame))))
(or no-run
(if (window-live-p window)
(with-current-buffer (window-buffer window)
(run-hook-with-args-until-failure
'window-deletable-functions window nil))
(run-hook-with-args-until-failure
'window-deletable-functions window nil))))
;; Otherwise, WINDOW can be deleted unless it is the main window
;; of its frame.
t))))