Function: delete-other-windows

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

Signature

(delete-other-windows &optional WINDOW INTERACTIVE)

Documentation

Make WINDOW fill its frame.

WINDOW must be a valid window and defaults to the selected one. Return nil.

If the variable ignore-window-parameters is non-nil or the delete-other-windows parameter of WINDOW equals t, do not pay attention to any other parameters of WINDOW. Otherwise, if the delete-other-windows parameter of WINDOW specifies a function, call that function with WINDOW as its sole argument and return the value returned by that function.

Else, if WINDOW is part of an atomic window, call this function with the root of the atomic window as its argument. Signal an error if that root window is the root window of WINDOW's frame. Also signal an error if WINDOW is a side window. Do not delete any window whose no-delete-other-windows parameter is non-nil.

View in manual

Probably introduced at or before Emacs version 24.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/window.el.gz
(defun delete-other-windows (&optional window interactive)
  "Make WINDOW fill its frame.
WINDOW must be a valid window and defaults to the selected one.
Return nil.

If the variable `ignore-window-parameters' is non-nil or the
`delete-other-windows' parameter of WINDOW equals t, do not pay
attention to any other parameters of WINDOW.  Otherwise, if the
`delete-other-windows' parameter of WINDOW specifies a function,
call that function with WINDOW as its sole argument and return
the value returned by that function.

Else, if WINDOW is part of an atomic window, call this function
with the root of the atomic window as its argument.  Signal an
error if that root window is the root window of WINDOW's frame.
Also signal an error if WINDOW is a side window.  Do not delete
any window whose `no-delete-other-windows' parameter is non-nil."
  (interactive "i\np")
  (setq window (window-normalize-window window))
  (let* ((frame (window-frame window))
	 (function (window-parameter window 'delete-other-windows))
	 atom-root main)
    (window--check frame)
    (catch 'done
      (cond
       ;; Ignore window parameters if `ignore-window-parameters' is t or
       ;; `delete-other-windows' is t.
       ((or ignore-window-parameters (eq function t)))
       ((functionp function)
	;; The `delete-other-windows' parameter specifies the function
	;; to call.  If the function is `ignore' no windows are deleted.
	;; It's up to the function called to avoid infinite recursion.
	(throw 'done (funcall function window)))
       ((and (window-parameter window 'window-atom)
	     (setq atom-root (window-atom-root window))
	     (not (eq atom-root window)))
	(if (eq atom-root (frame-root-window frame))
	    (error "Root of atomic window is root window of its frame")
	  (throw 'done (delete-other-windows atom-root))))
       ((window-parameter window 'window-side)
	(error "Cannot make side window the only window"))
       ((and (window-minibuffer-p window)
	     (not (eq window (frame-root-window window))))
	(error "Can't expand minibuffer to full frame")))

      (cond
       ((or ignore-window-parameters
            (not (window-with-parameter 'no-delete-other-windows nil frame)))
        (setq main (frame-root-window frame)))
       ((catch 'tag
          (walk-window-tree
           (lambda (other)
             (when (or (and (window-parameter other 'window-side)
                            (not (window-parameter
                                  other 'no-delete-other-windows)))
                       (and (not (window-parameter other 'window-side))
                            (window-parameter
                             other 'no-delete-other-windows)))
               (throw 'tag nil)))
           nil nil 'nomini)
          t)
        (setq main (window-main-window frame)))
       (t
        ;; Delete windows via `delete-window' because we found either a
        ;; deletable side window or a non-deletable non-side-window.
        (dolist (other (window-list frame))
          (when (and (window-live-p other)
                     (not (eq other window))
                     (not (window-parameter
                           other 'no-delete-other-windows))
                     ;; When WINDOW and the other window are part of the
                     ;; same atomic window, don't delete the other.
                     (or (not atom-root)
                         (not (eq (window-atom-root other) atom-root))))
            (condition-case nil
                (delete-window other)
              (error nil))))
        (throw 'done nil)))

      ;; If WINDOW is the main window of its frame do nothing.
      (if (eq window main)
          ;; Give a message to the user if this has been called as a
          ;; command.
          (when (and interactive
                     (not (or executing-kbd-macro noninteractive)))
            (message "No other windows to delete"))
	(delete-other-windows-internal window main)
	(window--check frame))
      ;; Always return nil.
      nil)))