When I do M-x compile, emacs will split my window to launch compilation and show its logs in a new window. As I understand, it has some algorithm to decide how to split the window.

So, when I have just one window with code opened on my big monitor, for some reason, instead of more-convenient horizontal split (showing compile-log side-by-side on the right and code on left), it splits window vertically. How could that be tweaked? Thank you.

3 Answers 3


The function that splits the window is split-window-sensibly, which can be tweaked by split-width-threshold and split-height-threshold, as Stefan suggested.

Alternatively, you can tell Emacs to use a different function to split the window by setting split-window-preferred-function (the default is split-window-sensibly). For more details see C-h v split-window-sensibly RET.

  • 3
    This helped me out too, but It seems like the thresholds should be in the reverse order. For example, I would like to be able to say "if this window is really wide, split it vertically so things don't get wrapped/cutoff, and if it is really long, split it horizontally". This seems more "sensible" to me, but am I missing something in the rational for having the settings work the way they do?
    – elethan
    Commented Nov 24, 2015 at 16:10
  • 1
    @elethan absolutely agree on this. Code/text is usually located in left part of your buffer, so splitting it vertically doesn't cut amount of code you see and must go by default if it's possible, otherwise (when it's too narrow) – go with splitting vertically, cutting amount of code you see in half. Commented Nov 25, 2015 at 10:57
  • Looking at the source code for split-window-sensibly, there's no way to reverse the order. You will have to write (or find) a new function and set it as split-window-preferred-function.
    – bmag
    Commented Nov 25, 2015 at 17:57
  • I used this answer to fix it for myself. Commented Oct 9, 2016 at 12:22

C-h v split-width-threshold RET should give you some useful info about that. There's also split-height-threshold, of course.


I haven't found any answer to the original post, which I take to be: “How can I make sure that my window is always split horizontally, no matter what”, so here is what's worked for me:

(setq split-width-threshold nil)

It is strange that this works, as – according to the documentation of the variable split-width-threshold – this should have exactly the opposite effect:

“If this is nil, ‘split-window-sensibly’ is not allowed to split a window horizontally.”

So maybe this is a result of some bug, but it works for me, unlike other methods I tried. In particular, the following, suggested by the documentation of split-window-sensibly, does not work for me:

(setq split-height-threshold nil)
(setq split-width-threshold 0)


P.S. My emacs version: GNU Emacs 26.3 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.14) of 2020-03-26, modified by Debian

  • Thank you! An answer that works without needing to read through pounds of nonsense.! Commented Jul 4, 2023 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.