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).

2 Answers 2


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.)

  • 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, 2011 at 16:52
  • @Eddy: Please consider upvoting answers you accept, as the answer probably was helpful ;) Nov 19, 2012 at 5:34

I'm not too familiar with ibuffer, but if your files are sequentially numbered, grid-files-sq might be something like what you're looking for, or you can use GridLayout

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.