Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I almost always use Emacs in a one-frame, two-window configuration (that is, one OS window with two Emacs windows inside it). I have the default-frame-alist set so that frames appear at the right size, but then I have to manually split them (with C-x 3). Is there a way to tell Emacs to do that automatically when each new frame is created?

EDIT: If I do happen to create a new frame at some point, I want it to be split vertically as well. Therefore, (when window-system (split-window-horizontally)) in .emacs won't do the job, because it only applies to the initial frame. What I think I need is a hook that runs in the context of each new frame after the default-frame-alist is applied.

share|improve this question

Just add

(split-window-horizontally)

to your .emacs file.

With C-h k you can check which Emacs function is linked to your shortcut. It's very useful if you are not familiar good enough with Emacs functions.

share|improve this answer
    
This is a bit too indiscriminate. For instance, I do not want this to happen if I'm running Emacs in a terminal (which I do do from time to time). – zwol Sep 22 '11 at 19:59
    
@zack its simple. put that into if like (if (window-system) (split-window-horizontally)) – kindahero Sep 23 '11 at 7:38
    
It took me a long time to figure out why I didn't like this answer, but I finally did; please see the edited question. – zwol Nov 15 '11 at 19:21

It's not exactly what you are asking for, but it's a nice way to get two windows side by side.

You can set the variables split-height-threshold and split-width-threshold, to change the behavior of split-window-sensibly. This way every time a new window pops up, say by autocompletion or by pressing o in a dired buffer, the frame gets split horizontally.

;; only split horizontally
(setq split-height-threshold nil
      split-width-threshold 0)

New frames will still start with only one window, but the first time a new window pops up, you will get one window on the left side and another on the right side.

share|improve this answer

To prevent from automatical vertical buffer splitting when e.g. visiting an item in a grep buffer the setting

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

is useful.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .