I would like to be able to automate the process of opening several files in emacs under a single frame, so that the frame splits up into multiple windows. Currently I am only able to open 2 files in a single emacs frame (2 windows) by typing this in a linux terminal: emacs file1 file2. However, if I try to open more than 2 files, for example by typing emacs file1 file2 file3 then it will open file3 in one window and in the other window it will come up with a 'CRM buffer' which lists the files in the directory.

How do I get it to open more than 2 files, so that the emacs frame is split up into more than 2 windows?

Note that 'window' means window in the emacs sense, not in the MS windows sense (frames).

link|improve this question

48% accept rate
feedback

1 Answer

up vote 0 down vote accepted

You can prevent the buffer list from coming up by setting inhibit-startup-buffer-menu to t as described here. However, that still does not result in more than 2 windows. Looking at the initialization code in startup.el, this does not seem to be customizable.

However, the ibuffer command ibuffer-do-view (bound to v) displays multiple buffers in the way you want. You can use it programatically. Put this in your .emacs file:

(defun view-files-in-windows ()
  (ibuffer)                      ; Activate ibuffer mode.
  (ibuffer-mark-special-buffers) ; Mark the special buffers.
  (ibuffer-toggle-marks)         ; Toggle buffers, leaving the non-special ones
  (ibuffer-do-view))             ; Show each buffer in a different window.

Then run emacs like this:

$ emacs file1 file2 file3 file4 --eval "(view-files-in-windows)"

(It fails if there are too many files and the windows would become too small.)

link|improve this answer
Nice one thanks! Is there a way to start it so that the 4 windows appear in 2 rows instead of one column? – Eddy Aug 1 '11 at 16:52
feedback

Your Answer

 
or
required, but never shown

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