6

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.

3 Answers 3

5

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.

3
  • 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, 2011 at 19:59
  • @zack its simple. put that into if like (if (window-system) (split-window-horizontally))
    – kindahero
    Sep 23, 2011 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, 2011 at 19:21
2

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.

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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