Windows – Customize windows when you open Emacs

Customize windows when you open Emacs… here is a solution to the problem.

Customize windows when you open Emacs

I want to launch three files in emacs from the terminal and split the windows in emacs into three so that each of the three windows contains one file. It’s also important to me that window is divided in some way. I can get the correct split manually by opening emacs and pressing C-x 3, C-x o, C-x 2. Anyone know how to do this by configuring an .emacs or bash script? I’m going to open about 300 files this way, so doing this automatically helps me a lot.

Edit:
I have to open 3 different files each time. I would be happy if I could open from the terminal like this:
emacs file 1 file 2 file 3

The next three files
emacs file4 file 5 file6

Just in case:
– Run Linux
– Use the latest emacs

Solution

Does this meet your requirements?

(defun open-files (first second third)
  (interactive "fFirst: \nfSecond: \nfThird: ")
  (find-file first)
  (split-window-horizontally)
  (other-window 1)
  (find-file second)
  (split-window-vertically)
  (other-window 1)
  (find-file third))

EDIT: I’ve made the function interactive, or can call it from the command line like this:

emacs --eval='(open-files "/tmp/first" "/tmp/second" "/tmp/third")'

You can wrap it in a bash script to make it easier to call.

Related Problems and Solutions