30.7 Deleting Frames

A live frame is one that has not been deleted. When a frame is deleted, it is removed from its terminal display, although it may continue to exist as a Lisp object until there are no more references to it.

Command: delete-frame &optional frame force

This function deletes the frame frame. The argument frame must specify a live frame (see below) and defaults to the selected frame.

It first deletes any child frame of frame (see Child Frames) and any frame whose delete-before frame parameter (see Frame Interaction Parameters) specifies frame. All such deletions are performed recursively; so this step makes sure that no other frames with frame as their ancestor will exist. Then, unless frame specifies a tooltip, this function runs the hook delete-frame-functions (each function getting one argument, frame) before actually killing the frame. After actually killing the frame and removing the frame from the frame list, delete-frame runs after-delete-frame-functions.

Note that a frame cannot be deleted as long as its minibuffer serves as surrogate minibuffer for another frame (see Minibuffers and Frames). Normally, you cannot delete a frame if all other frames are invisible, but if force is non-nil, then you are allowed to do so. Also, the initial terminal frame of an Emacs process running as daemon (see daemon in The GNU Emacs Manual) can be deleted if and only if force is non-nil.

Function: frame-live-p frame

This function returns non-nil if the frame frame has not been deleted. The possible non-nil return values are like those of framep. See Frames.

Some window managers provide a command to delete a window. These work by sending a special message to the program that operates the window. When Emacs gets one of these commands, it generates a delete-frame event, whose normal definition is a command that calls the function delete-frame. See Miscellaneous System Events.

Command: delete-other-frames &optional frame iconify

This command deletes all frames on frame’s terminal, except frame. If frame uses another frame’s minibuffer, that minibuffer frame is left untouched. The argument frame must specify a live frame and defaults to the selected frame. Internally, this command works by calling delete-frame with force nil for all frames that shall be deleted.

This function does not delete any of frame’s child frames (see Child Frames). If frame is a child frame, it deletes frame’s siblings only.

With the prefix argument iconify, the frames are iconified rather than deleted.

The following function checks whether a frame can be safely deleted. It is useful for avoiding the situation whereby a subsequent call of delete-frame fails to delete its argument frame and/or signals an error. To that end, your Lisp program should call delete-frame only if the following function returns non-nil.

Function: frame-deletable-p &optional frame

This function returns non-nil if the frame specified by frame can be safely deleted. frame must be a live frame and defaults to the selected frame.

A frame cannot be safely deleted in the following cases:

  • It is the only visible or iconified frame (see Visibility of Frames).
  • It hosts the active minibuffer window and minibuffer windows do not follow the selected frame (see (emacs)Basic Minibuffer).
  • All other visible or iconified frames are either child frames (see Child Frames) or have a non-nil delete-before parameter.
  • The frame or one of its descendants hosts the minibuffer window of a frame that is not a descendant of the frame (see Child Frames).

These conditions cover most cases where delete-frame might fail when called from top-level. They do not catch some special cases like, for example, deleting a frame during a drag-and-drop operation (see Drag and Drop). In any such case, it will be better to wrap the delete-frame call in a condition-case form.