Function: delete-other-frames

delete-other-frames is an interactive and byte-compiled function defined in frame.el.gz.

Signature

(delete-other-frames &optional FRAME ICONIFY)

Documentation

Delete all frames on FRAME's terminal, except FRAME.

If FRAME uses another frame's minibuffer, the minibuffer frame is left untouched. Do not delete any of FRAME's child frames. If FRAME is a child frame, delete its siblings only. FRAME must be a live frame and defaults to the selected one. If the prefix arg ICONIFY is non-nil, just iconify the frames rather than deleting them.

View in manual

Probably introduced at or before Emacs version 21.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/frame.el.gz
(defun delete-other-frames (&optional frame iconify)
  "Delete all frames on FRAME's terminal, except FRAME.
If FRAME uses another frame's minibuffer, the minibuffer frame is
left untouched.  Do not delete any of FRAME's child frames.  If
FRAME is a child frame, delete its siblings only.  FRAME must be
a live frame and defaults to the selected one.
If the prefix arg ICONIFY is non-nil, just iconify the frames rather than
deleting them."
  (interactive "i\nP")
  (setq frame (window-normalize-frame frame))
  (let ((minibuffer-frame (window-frame (minibuffer-window frame)))
	(terminal (frame-terminal frame))
        (parent (frame-parent frame))
	(frames (frame-list)))
    ;; In a first round consider minibuffer-less frames only.
    (dolist (this frames)
      (unless (or (eq this frame)
		  (eq this minibuffer-frame)
		  (not (eq (frame-terminal this) terminal))
		  (eq (window-frame (minibuffer-window this)) this)
                  ;; When FRAME is a child frame, delete its siblings
                  ;; only.
                  (and parent (not (eq (frame-parent this) parent)))
                  ;; Do not delete frame descending from FRAME.
                  (frame-ancestor-p frame this))
        (if iconify (iconify-frame this) (delete-frame this))))
    ;; In a second round consider all remaining frames.
    (dolist (this frames)
      ;; We did not recalculate FRAMES so make sure THIS is still a live
      ;; frame since otherwise 'frame-terminal' will throw an error.
      (unless (or (not (frame-live-p this))
                  (eq this frame)
		  (eq this minibuffer-frame)
		  (not (eq (frame-terminal this) terminal))
                  ;; When FRAME is a child frame, delete its siblings
                  ;; only.
                  (and parent (not (eq (frame-parent this) parent)))
                  ;; Do not delete frame descending from FRAME.
                  (frame-ancestor-p frame this))
        (if iconify (iconify-frame this) (delete-frame this))))))