2

I would like to be able to specify the window layout of the Emacs when starting it from commandline.

More specifically, I invoke "emacs file1 file2 file3 file4" and would, for example, like see

+---------+                             +--------+
|  file1  |                             |  buff  |
|         |                             |  list  |
+---------+    instead of the default   +--------+  that I see currently
|         |                             |        |
|  file3  |                             |  file4 |
+---------+                             +--------+

My emacs is GNU Emacs 24.0.91.1, and I do not use emacsclient.

Note, I do not want to make the change permanent. That is why I ask for command-line solution.

Boris Bukh
  • 165
  • 7

1 Answers1

2

Put the following in layout.el

(setq inhibit-startup-screen t)

(defun ordered-window-list-aux (tree)
  (if (windowp tree)
      (list tree)
    (append (ordered-window-list-aux (nth 2 tree))
            (ordered-window-list-aux (nth 3 tree)))))

(defun ordered-window-list ()
  "Lists windows from top to bottom, left to right."
  (ordered-window-list-aux
   (car (window-tree))))

(require 'cl)

(defun fill-windows ()
  "Make window list display recent buffer."
  (mapcar*
   (lambda (win buf)
     (set-window-buffer win buf))
   (nreverse (ordered-window-list))
   (buffer-list)))

(delete-other-windows)

;; your window configuration
(split-window-horizontally)
(split-window-vertically)

;; Make window list display recent buffer
(fill-windows)

Then

emacs blah foo bar --load layout.el

The only thing you have to do is customizing the layout the way you want using a combination of the following functions:

(split-window-horizontally)
(split-window-vertically)
(other-windows 1)
thisirs
  • 790
  • 6
  • 6
  • Thanks for your help. Whereas the code you provided does not work for me (and I do not understand it to fix it). However, what you do gave me an idea how to solve my problem. I created "layout.el" as you suggested, and added a single line "(add-hook 'emacs-startup-hook (lambda () (other-window 1) (switch-to-buffer "bar")))" to achieve the effect my original question wanted. To get additional modifications, I can use (split-window-horizontally) (split-window-vertically) as you suggested. – Boris Bukh Apr 11 '12 at 09:42
  • If I use the code as given, then I get fours windows. The bottommost is largest takes the bottom half of the frame, and contains "bar", above it there are three windows. The rightmost of them takes the right half of space and contains "foo". The left-top part is split between "blah" and "*Scratch", with "blah" on the bottom, and "*scratch" on the top. If I comment out "(split-window-vertically)", I get three windows with "blah", "foo" and "bar". If in addition I comment out "(split-window-horizontally)", I get "foo" on top and "Buffer List" on the bottom. – Boris Bukh Apr 11 '12 at 17:26
  • It seems that at startup emacs is splitting the window depending on its size and on how many files are being opened. The splash screen is also interfering with the window configuration... A `(delete-other-window)` before setting your window configuration seems to fix this. Also set `(setq inhibit-startup-screen t)` – thisirs Apr 12 '12 at 07:47
  • Thanks for your help! It has really been helpful. – Boris Bukh Apr 12 '12 at 13:18
  • 1
    There is actually no need for `ordered-window-*` functions. See `walk-window-tree` – thisirs May 03 '12 at 12:29