You can make Emacs do this by customizing the variable split-window-preferred-function
:
(defun my-split-window-sensibly (&optional window)
(let ((window (or window (selected-window))))
(or (and (window-splittable-p window t)
;; Split window horizontally.
(with-selected-window window
(split-window-right)))
(and (window-splittable-p window)
;; Split window vertically.
(with-selected-window window
(split-window-below)))
(and (eq window (frame-root-window (window-frame window)))
(not (window-minibuffer-p window))
;; If WINDOW is the only window on its frame and is not the
;; minibuffer window, try to split it horizontally disregarding
;; the value of `split-width-threshold'.
(let ((split-width-threshold 0))
(when (window-splittable-p window t)
(with-selected-window window
(split-window-right))))))))
(setq split-window-preferred-function 'my-split-window-sensibly)
The variable split-window-preferred-function
specifies a function for splitting a window, in order to make a new window for displaying a buffer. It is used by the display-buffer-pop-up-window
action function to actually split the window.
By default, it is set to split-window-sensibly
. The function I am providing above is a modified version of split-window-sensibly
(defined in window.el
) that simply reverses the steps of the original function, causing Emacs to "prefer" side-by-side window splits over stacked ones.