This section describes the basic facility that chooses a window to
display a buffer in—display-buffer. Higher-level functions and
commands, like switch-to-buffer and pop-to-buffer, use this
subroutine. Here we describe how to use display-buffer and how
to customize it.
This command makes buffer-or-name appear in some window, but it does not select that window and does not make the buffer specified by buffer-or-name current. The identity of the selected window is unaltered by this function. The argument buffer-or-name must be a buffer or the name of an existing buffer.
not-this-window non-
nilmeans to display the specified buffer in a window other than the selected one, even if it is already displayed in the selected window. This can cause the buffer to appear in two windows at once. Otherwise, if buffer-or-name is already being displayed in any window, that is good enough, so this function does nothing.
display-bufferreturns the window chosen to display buffer-or-name.If the optional argument frame is non-
nil, it specifies which frames to check when deciding whether the buffer is already displayed. If the buffer is already displayed in some window on one of these frames,display-buffersimply returns that window. Here are the possible values of frame:
nilmeans consider windows on the selected frame. (Actually, the last non-minibuffer frame.)tmeans consider windows on all frames.visiblemeans consider windows on all visible frames.- 0 means consider windows on all visible or iconified frames.
- A frame means consider windows on that frame only.
Precisely how
display-bufferfinds or creates a window depends on the variables described below.
If this variable is non-
nil,display-buffersearches visible and iconified frames for a window displaying buffer-or-name. If there is such a window,display-buffermakes that window's frame visible and raises it if necessary, and returns the window. If there is no such window ordisplay-buffer-reuse-framesisnil, the behavior ofdisplay-bufferis determined by the variables described next.
This variable specifies whether
display-bufferis allowed to split (see Splitting Windows) an existing window. If this variable is non-nil,display-buffertries to split the largest or least recently used window on the selected frame. (If the selected frame is a minibuffer-only frame,display-buffertries to split a window on another frame instead.) If this variable isnilor the variablepop-up-frames(see below) is non-nil,display-bufferdoes not split any window.
This variable must specify a function with one argument, which is a window. The
display-bufferroutines will call this function with one or more candidate windows when they look for a window to split. The function is expected to split that window and return the new window. If the function returnsnil, this means that the argument window cannot (or shall not) be split.The default value of
split-window-preferred-functionis the functionsplit-window-sensiblydescribed below. If you customize this option, bear in mind that thedisplay-bufferroutines may call your function up to two times when trying to split a window. The argument of the first call is the largest window on the chosen frame (as returned byget-largest-window). If that call fails to return a live window, your function is called a second time with the least recently used window on that frame (as returned byget-lru-window).The function specified by this option may try to split any other window instead of the argument window. Note that the window selected at the time
display-bufferwas invoked is still selected when your function is called. Hence, you can split the selected window (instead of the largest or least recently used one) by simply ignoring the window argument in the body of your function. You can even choose to not split any window as long as the return value of your function specifies a live window ornil, but you are not encouraged to do so unconditionally. If you wantdisplay-bufferto never split any windows, setpop-up-windowstonil.
This function takes a window as argument and tries to split that window in a suitable way. The two variables described next are useful for tuning the behavior of this function.
This variable specifies whether
split-window-sensiblymay split windows vertically. If it is an integer,split-window-sensiblytries to vertically split a window only if it has at least this many lines. If the window has less lines, splitting fails, or the value of this variable isnil,split-window-sensiblywill try to split the window horizontally, subject to restrictions ofsplit-width-threshold(see below). If splitting horizontally fails too and the window is the only window on its frame,split-window-sensiblywill try to split the window vertically disregarding the value ofsplit-height-threshold. If this fails as well,split-window-sensiblyreturnsnil.
split-window-sensiblydoes not split vertically a window whose height is fixed (see Resizing Windows). Also, it vertically splits a window only if the space taken up by that window can accommodate two windows one above the other that are both at leastwindow-min-heightlines tall. Moreover, if the window that shall be split has a mode line,split-window-sensiblydoes not split the window unless the new window can accomodate a mode line too.
This variable specifies whether
split-window-sensiblymay split windows horizontally. If it is an integer,split-window-sensiblytries to horizontally split a window only if it has at least this many columns. If it isnil,split-window-sensiblywill not split the window horizontally. (It still might split the window vertically, though, see above.)
split-window-sensiblydoes not split horizontally a window if that window's width is fixed (see Resizing Windows). Also, it horizontally splits a window only if the space that window takes up can accommodate two windows side by side that are both at leastwindow-min-widthcolumns wide.
This variable specifies whether
display-buffershould even out window heights if the buffer gets displayed in an existing window, above or beneath another window. Ifeven-window-heightsis non-nil, the default, window heights will be evened out. If either of the involved window has fixed height (see Resizing Windows) oreven-window-heightsisnil, the original window heights will be left alone.
This variable specifies whether
display-buffershould make new frames. If it is non-nil,display-bufferlooks for a window already displaying buffer-or-name on any visible or iconified frame. If it finds such a window, it makes that window's frame visible and raises it if necessary, and returns the window. Otherwise it makes a new frame, unless the variable's value isgraphic-onlyand the selected frame is not on a graphic display. See Frames, for more information.Note that the value of
pop-up-windowsdoes not matter ifpop-up-framesis non-nil. Ifpop-up-framesisnil, thendisplay-buffereither splits a window or reuses one.
This variable specifies how to make a new frame if
pop-up-framesis non-nil.The value of this variable must be a function of no arguments. When
display-buffermakes a new frame, it does so by calling that function, which should return a frame. The default value of this variable is a function that creates a frame using the parameters specified bypop-up-frame-alistdescribed next.
This variable holds an alist specifying frame parameters used by the default value of
pop-up-frame-functionfor making new frames. See Frame Parameters, for more information about frame parameters.
A list of buffer names identifying buffers that should be displayed specially. If the name of buffer-or-name is in this list,
display-bufferhandles the buffer specially. By default, special display means to give the buffer a dedicated frame.If an element is a list, instead of a string, then the car of that list is the buffer name, and the rest of that list says how to create the frame. There are two possibilities for the rest of that list (its cdr): It can be an alist, specifying frame parameters, or it can contain a function and arguments to give to it. (The function's first argument is always the buffer to be displayed; the arguments from the list come after that.)
For example:
(("myfile" (minibuffer) (menu-bar-lines . 0)))specifies to display a buffer named ‘myfile’ in a dedicated frame with specified
minibufferandmenu-bar-linesparameters.The list of frame parameters can also use the phony frame parameters
same-frameandsame-window. If the specified frame parameters include(same-window .value)and value is non-nil, that means to display the buffer in the current selected window. Otherwise, if they include(same-frame .value)and value is non-nil, that means to display the buffer in a new window in the currently selected frame.
A list of regular expressions specifying buffers that should be displayed specially. If the buffer's name matches any of the regular expressions in this list,
display-bufferhandles the buffer specially. By default, special display means to give the buffer a dedicated frame.If an element is a list, instead of a string, then the car of the list is the regular expression, and the rest of the list says how to create the frame. See
special-display-buffer-namesabove.
This function returns non-
nilif displaying a buffer named buffer-name withdisplay-bufferwould create a special frame. The value istif it would use the default frame parameters, or else the specified list of frame parameters.
This variable holds the function to call to display a buffer specially. It receives the buffer as an argument, and should return the window in which it is displayed. The default value of this variable is
special-display-popup-frame, see below.
This function tries to make buffer visible in a frame of its own. If buffer is already displayed in some window, it makes that window's frame visible and raises it. Otherwise, it creates a frame that is dedicated to buffer. The return value is the window used to display buffer.
If args is an alist, it specifies frame parameters for the new frame. If args is a list whose car is a symbol, then
(carargs)is called as a function to actually create and set up the frame; it is called with buffer as first argument, and(cdrargs)as additional arguments.This function always uses an existing window displaying buffer, whether or not it is in a frame of its own; but if you set up the above variables in your init file, before buffer was created, then presumably the window was previously made by this function.
This variable holds frame parameters for
special-display-popup-frameto use when it creates a frame.
A list of buffer names for buffers that should be displayed in the selected window. If the buffer's name is in this list,
display-bufferhandles the buffer by switching to it in the selected window.
A list of regular expressions that specify buffers that should be displayed in the selected window. If the buffer's name matches any of the regular expressions in this list,
display-bufferhandles the buffer by switching to it in the selected window.
This function returns
tif displaying a buffer named buffer-name withdisplay-bufferwould put it in the selected window.
This variable is the most flexible way to customize the behavior of
display-buffer. If it is non-nil, it should be a function thatdisplay-buffercalls to do the work. The function should accept two arguments, the first two arguments thatdisplay-bufferreceived. It should choose or create a window, display the specified buffer in it, and then return the window.This variable takes precedence over all the other options described above.
If all options described above fail to produce a suitable window,
display-buffer tries to reuse an existing window. As a last
resort, it will try to display buffer-or-name on a separate frame.
In that case, the value of pop-up-frames is disregarded.