display-buffer command (as well as commands that call it
internally) chooses a window to display by following the steps given
below. See Choosing a Window for Displaying a
Buffer in The Emacs Lisp Reference Manual, for details about how
to alter this sequence of steps.
display-buffer-same-windowaction function (see Action Functions for Buffer Display in The Emacs Lisp Reference Manual) to the option
display-buffer-alist(see Choosing a Window for Displaying a Buffer in The Emacs Lisp Reference Manual). For example, to display the buffer *scratch* preferably in the selected window write:
(customize-set-variable 'display-buffer-alist '(("\\*scratch\\*" (display-buffer-same-window))))
reusable-framesaction alist entry (see Action Alists for Buffer Display in The Emacs Lisp Reference Manual). See the next step for an example of how to do that.
display-buffer-base-action(see Choosing a Window for Displaying a Buffer in The Emacs Lisp Reference Manual) as follows:
(customize-set-variable 'display-buffer-base-action '((display-buffer-reuse-window display-buffer-pop-up-frame) (reusable-frames . 0)))
This customization will also try to make the preceding step search for a reusable window on all visible or iconified frames.
The split can be either vertical or horizontal, depending on the
split-width-threshold. These variables should have integer
split-height-threshold is smaller than the chosen
window’s height, the split puts the new window below. Otherwise, if
split-width-threshold is smaller than the window’s width, the
split puts the new window on the right. If neither condition holds,
Emacs tries to split so that the new window is below—but only if the
window was not split before (to avoid excessive splitting).
reusable-framesaction alist entry (see above) the window may be also on another frame.