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.
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
quit-restore-windowdescribed next to deal with the window and its buffer.
This function handles window and its buffer after quitting. The optional argument window must be a live window and defaults to the selected one. The function's behavior is determined by the four elements of the list specified by the
quit-restorewindow parameter (see Window Parameters), which is set to
The first element of the
quit-restoreparameter is one of the symbols
window, meaning that the window has been specially created by
frame, a separate frame has been created;
same, the window has only ever displayed this buffer; or
other, the window showed another buffer before.
windowaffect how the window is quit, while
otheraffect the redisplay of buffers previously shown in this window.
The second element is either one of the symbols
frame, or a list whose elements are the buffer shown in the window before, that buffer's window start and window point positions, and the window's height at that time. If that buffer is still live when the window is quit, then the function
quit-restore-windowreuses the window to display the buffer.
The third element is the window selected at the time the parameter was created. If
quit-restore-windowdeletes the window passed to it as argument, it then tries to reselect this window.
The fourth element is the buffer whose display caused the creation of this parameter.
quit-restore-windowdeletes the specified window only if it still shows that buffer.
The window is deleted entirely if: 1) the first element of the
quit-restoreparameter is one of 'window or 'frame, 2) the window has no history of previously-displayed buffers, and 3) the displayed buffer matches the one in the fourth element of the
quit-restoreparameter. 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 sole argument.
If the third element of the
quit-restoreparameter is a list of buffer, window start (see Window Start and End), and point (see Window Point), and that buffer is still live, the buffer will be displayed, and start and point set accordingly. If, in addition, window's buffer was temporarily resized, this function will also try to restore the original height of window.
Otherwise, if window was previously used for displaying other buffers (see Window History), the most recent buffer in that history will be displayed.
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-bufferwill 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-bufferwill 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-bufferswitch to this buffer again without killing the buffer.
- This means to kill window's buffer.
Typically, the display routines run by
display-bufferwill set the
quit-restorewindow parameter correctly. It's also possible to set it manually, using the following code for displaying buffer in window:(display-buffer-record-window type window buffer) (set-window-buffer window buffer) (set-window-prev-buffers window nil)
Setting the window history to
nilensures that a future call to
quit-windowcan delete the window altogether.
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
bury-buffer(see Buffer List) when the selected window is dedicated and shows the buffer to bury. It is also called by
quit-restore-window(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 killed.
The default is to call
iconify-frame(see Visibility of Frames). Alternatively, you may specify either
delete-frame(see Deleting Frames) to remove the frame from its display,
make-frame-invisibleto make the frame invisible,
ignoreto 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.
For a particular frame, the value specified here may be overridden by that frame's
auto-hide-functionframe parameter (see Frame Interaction Parameters).