Function: delete-windows-on

delete-windows-on is an interactive and byte-compiled function defined in window.el.gz.

Signature

(delete-windows-on &optional BUFFER-OR-NAME FRAME)

Documentation

Delete all windows showing BUFFER-OR-NAME.

BUFFER-OR-NAME may be a buffer or the name of an existing buffer and defaults to the current buffer.

Interactively, this command will prompt for the buffer name. A prefix argument of 0 (zero) means that only windows in the current terminal's frames will be deleted. Any other prefix argument means that only windows in the current frame will be deleted.

The following non-nil values of the optional argument FRAME have special meanings:

- t means consider all windows on the selected frame only.

- visible means consider all windows on all visible frames on
  the current terminal.

- 0 (the number zero) means consider all windows on all visible
  and iconified frames on the current terminal.

- A frame means consider all windows on that frame only.

Any other value of FRAME means consider all windows on all frames.

Interactively, FRAME is the prefix argument, so you can use C-u (universal-argument) 0 to specify all windows only on the current terminal's frames.

If a frame's root window shows the buffer specified by BUFFER-OR-NAME, is dedicated to that buffer, that frame does not host the active minibuffer window and there is at least one other frame on that frame's terminal, delete that frame. Otherwise, do not delete a frame's root window if it shows the buffer specified by BUFFER-OR-NAME and do not delete any frame's main window showing that buffer either. Rather, in any such case, call either quit-restore-window (provided kill-buffer-quit-windows is non-nil) or switch-to-prev-buffer to show another buffer in that window and make sure the window is no more dedicated to its buffer.

If the buffer specified by BUFFER-OR-NAME is shown in a minibuffer window, do nothing for that window. For any window that does not show that buffer, remove the buffer from that window's lists of previous and next buffers and remove any quit-restore and quit-restore-prev parameters naming it.

View in manual

Probably introduced at or before Emacs version 19.17.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/window.el.gz
(defun delete-windows-on (&optional buffer-or-name frame)
  "Delete all windows showing BUFFER-OR-NAME.
BUFFER-OR-NAME may be a buffer or the name of an existing buffer
and defaults to the current buffer.

Interactively, this command will prompt for the buffer name.  A
prefix argument of 0 (zero) means that only windows in the
current terminal's frames will be deleted.  Any other prefix
argument means that only windows in the current frame will be
deleted.

The following non-nil values of the optional argument FRAME
have special meanings:

- t means consider all windows on the selected frame only.

- `visible' means consider all windows on all visible frames on
  the current terminal.

- 0 (the number zero) means consider all windows on all visible
  and iconified frames on the current terminal.

- A frame means consider all windows on that frame only.

Any other value of FRAME means consider all windows on all
frames.

Interactively, FRAME is the prefix argument, so you can
use \\[universal-argument] 0 to specify all windows only on
the current terminal's frames.

If a frame's root window shows the buffer specified by BUFFER-OR-NAME,
is dedicated to that buffer, that frame does not host the active
minibuffer window and there is at least one other frame on that frame's
terminal, delete that frame.  Otherwise, do not delete a frame's root
window if it shows the buffer specified by BUFFER-OR-NAME and do not
delete any frame's main window showing that buffer either.  Rather, in
any such case, call either `quit-restore-window' (provided
`kill-buffer-quit-windows' is non-nil) or `switch-to-prev-buffer' to
show another buffer in that window and make sure the window is no more
dedicated to its buffer.

If the buffer specified by BUFFER-OR-NAME is shown in a minibuffer
window, do nothing for that window.  For any window that does not show
that buffer, remove the buffer from that window's lists of previous and
next buffers and remove any `quit-restore' and `quit-restore-prev'
parameters naming it."
  (interactive
   (let ((frame (cond
                 ((and (numberp current-prefix-arg)
                       (zerop current-prefix-arg))
                  0)
                 (current-prefix-arg t))))
     (list (read-buffer "Delete windows on (buffer): "
                        nil nil
                        (lambda (buf)
                          (get-buffer-window
                           (if (consp buf) (car buf) buf)
                           (cond
                            ((null frame) t)
                            ((numberp frame) frame)))))
           frame)))
  (let ((buffer (window-normalize-buffer buffer-or-name))
	;; Handle the "inverted" meaning of the FRAME argument wrt other
	;; `window-list-1' based functions.
	(frames (cond ((not frame) t) ((eq frame t) nil) (t frame))))
    (dolist (window (window-list-1 nil 'nomini frames))
      (if (eq (window-buffer window) buffer)
	  ;; Don't run 'window-deletable-functions'.
	  (let ((deletable (window-deletable-p window t))
                (dedicated (window-dedicated-p window)))
	    (cond
	     ((and (eq deletable 'frame) dedicated)
	      ;; Delete frame if and only if window is dedicated.
	      (delete-frame (window-frame window)))
	     ((eq deletable t)
	      ;; Delete window.
	      (delete-window window))
	     (kill-buffer-quit-windows
	      (quit-restore-window window 'bury)
	      (when (window-live-p window)
		;; Unrecord BUFFER in this window.
		(unrecord-window-buffer window buffer t)))
	     (t
	      ;; In window switch to previous buffer.
	      (set-window-dedicated-p window nil)
	      (switch-to-prev-buffer window 'bury)
	      ;; Restore the dedicated 'side' flag.
	      (when (eq dedicated 'side)
                (set-window-dedicated-p window 'side))
	      (when (window-live-p window)
		;; Unrecord BUFFER in this window.
		(unrecord-window-buffer window buffer t)))))
	;; If a window doesn't show BUFFER, unrecord BUFFER in it.
	(unrecord-window-buffer window buffer t)))))