Each window remembers in a list the buffers it has previously
displayed, and the order in which these buffers were removed from it.
This history is used, for example, by
(see Buffers and Windows), and when quitting windows
(see Quitting Windows). The list is automatically maintained by
Emacs, but you can use the following functions to explicitly inspect
or alter it:
This function returns a list specifying the previous contents of window. The optional argument window should be a live window and defaults to the selected one.
Each list element has the form
window-pos), where buffer is a buffer previously shown in
the window, window-start is the window start position
(see The Window Start and End Positions) when that buffer was last shown, and
window-pos is the point position (see Windows and Point) when
that buffer was last shown in window.
The list is ordered so that earlier elements correspond to more recently-shown buffers, and the first element usually corresponds to the buffer most recently removed from the window.
This function sets window’s previous buffers to the value of
prev-buffers. The argument window must be a live window
and defaults to the selected one. The argument prev-buffers
should be a list of the same form as that returned by
In addition, each window maintains a list of next buffers, which
is a list of buffers re-shown by
below). This list is mainly used by
switch-to-next-buffer for choosing buffers to switch to.
This function returns the list of buffers recently re-shown in
switch-to-prev-buffer. The window
argument must denote a live window or
nil (meaning the selected
This function sets the next buffer list of window to
next-buffers. The window argument should be a live window
nil (meaning the selected window). The argument
next-buffers should be a list of buffers.
The following commands can be used to cycle through the global buffer
list, much like
they cycle according to the specified window’s history list, rather
than the global buffer list. In addition, they restore
window-specific window start and point positions, and may show a
buffer even if it is already shown in another window. The
switch-to-prev-buffer command, in particular, is used by
quit-window to find a replacement buffer for a window.
This command displays the previous buffer in window. The
argument window should be a live window or
the selected window). If the optional argument bury-or-kill is
nil, this means that the buffer currently shown in
window is about to be buried or killed and consequently should
not be switched to in future invocations of this command.
The previous buffer is usually the buffer shown before the buffer
currently shown in window. However, a buffer that has been buried
or killed, or has been already shown by a recent invocation of
switch-to-prev-buffer, does not qualify as previous buffer.
If repeated invocations of this command have already shown all buffers previously shown in window, further invocations will show buffers from the buffer list of the frame window appears on (see The Buffer List).
switch-to-prev-buffer-skip described below can be
used to inhibit switching to certain buffers, for example, to those
already shown in another window. Also, if window’s frame has a
buffer-predicate parameter (see Buffer Parameters), that
predicate may inhibit switching to certain buffers.
This command switches to the next buffer in window, thus undoing
the effect of the last
switch-to-prev-buffer command in
window. The argument window must be a live window and
defaults to the selected one.
If there is no recent invocation of
can be undone, this function tries to show a buffer from the buffer list
of the frame window appears on (see The Buffer List).
switch-to-prev-buffer-skip and the
buffer-predicate (see Buffer Parameters) of window’s
frame affect this command as they do for
switch-to-next-buffer can switch to a buffer that is already
shown in another window. The following option can be used to override
If this variable is
switch to any buffer, including those already shown in other windows.
If this variable is non-
refrain from switching to certain buffers. The following values can
thismeans do not switch to a buffer shown on the frame that hosts the window
switch-to-prev-bufferis acting upon.
visiblemeans do not switch to a buffer shown on any visible frame.
tmeans do not switch to a buffer shown on any live frame.
switch-to-prev-buffer, a buffer
switch-to-prev-bufferintends to switch to and the bury-or-kill argument of
switch-to-prev-buffer. If that function returns non-
switch-to-prev-bufferwill refrain from switching to the buffer specified by the second argument.
switch-to-next-buffer obeys this option in a
similar way. If this option specifies a function,
switch-to-next-buffer will call that function with the third
Note that since
switch-to-prev-buffer is called by
quit-restore-window as well, customizing this option may also
affect the behavior of Emacs when a window is quit or a buffer gets
buried or killed.
Note also that under certain circumstances
ignore this option, for example, when there is only one buffer left
these functions can switch to.
This user option should be either a regular expression or a list of
regular expressions. Buffers whose names match one of those regular
expressions will be ignored by
switch-to-next-buffer (except when there’s no other buffer to