When you want to get rid of a window used for displaying a buffer, you
(see Deleting Windows) to remove that window from its frame. If the
buffer is shown on a separate frame, you might want to call
delete-frame (see Deleting Frames) instead. If, on the other
hand, a window has been reused for displaying the buffer, you might
prefer showing the buffer previously shown in that window, by calling the
switch-to-prev-buffer (see Window History).
Finally, you might want to either bury (see Buffer List) or kill
(see Killing Buffers) the window’s buffer.
The following command uses information on how the window for displaying the buffer was obtained in the first place, thus attempting to automate the above decisions for you.
quit-window&optional kill window
This command quits window and buries its buffer. The argument
window must be a live window and defaults to the selected one.
With prefix argument kill non-
nil, it kills the buffer
instead of burying it. It calls the function
described next to deal with the window and its buffer.
quit-restore-window&optional window bury-or-kill
This function tries to restore the state of window that existed before its buffer was displayed in it. The optional argument window must be a live window and defaults to the selected one.
If window was created specially for displaying its buffer, this
function deletes window provided its frame contains at least one
other live window. If window is the only window on its frame and
there are other frames on the frame’s terminal, the value of the
optional argument bury-or-kill determines how to proceed with the
window. If bury-or-kill equals
kill, the frame is deleted
unconditionally. Otherwise, the fate of the frame is determined by
calling frame-auto-hide-function (see below) with that frame as
Otherwise, this function tries to redisplay the buffer previously shown in window. It also tries to restore the window start (see Window Start and End) and point (see Window Point) positions of the previously shown buffer. If, in addition, window’s buffer was temporarily resized, this function will also try to restore the original height of window.
The cases described so far require that the buffer shown in window
is still the buffer displayed by the last buffer display function for
this window. If another buffer has been shown in the meantime, or the
buffer previously shown no longer exists, this function calls
switch-to-prev-buffer (see Window History) to show some other
The optional argument bury-or-kill specifies how to deal with window’s buffer. The following values are handled:
This means to not deal with the buffer in any particular way. As a
consequence, if window is not deleted, invoking
switch-to-prev-buffer will usually show the buffer again.
This means that if window is not deleted, its buffer is moved to
the end of window’s list of previous buffers, so it’s less likely
that a future invocation of
switch-to-prev-buffer will switch to
it. Also, it moves the buffer to the end of the frame’s buffer list.
This means that if window is not deleted, its buffer is removed
from window’s list of previous buffers. Also, it moves the buffer
to the end of the frame’s buffer list. This value provides the most
reliable remedy to not have
switch-to-prev-buffer switch to this
buffer again without killing the buffer.
This means to kill window’s buffer.
quit-restore-window bases its decisions on information stored in
quit-restore window parameter (see Window Parameters), and resets that parameter to
nil after it’s done.
The following option specifies how to deal with a frame containing just one window that should be either quit, or whose buffer should be buried.
The function specified by this option is called to automatically hide frames. This function is called with one argument—a frame.
The function specified here is called by
(see Buffer List) when the selected window is dedicated and shows
the buffer to bury. It is also called by
(see above) when the frame of the window to quit has been specially
created for displaying that window’s buffer and the buffer is not
The default is to call
iconify-frame (see Visibility of Frames). Alternatively, you may specify either
(see Deleting Frames) to remove the frame from its display,
ignore to leave the frame unchanged, or any other function that
can take a frame as its sole argument.
Note that the function specified by this option is called only if the specified frame contains just one live window and there is at least one other frame on the same terminal.