3

Running emacs with multiple files automatically opens the "Buffer List" split-window.

eg:

emacs -Q *.txt

Opens a split window, one which contains a list of buffers.

How can multiple files be opened in a single window without any splits?

3

The user option which determines whether a Buffer Menu is displayed is inhibit-startup-buffer-menu:

inhibit-startup-buffer-menu is a variable defined in ‘startup.el’.
Its value is nil

Documentation:
Non-nil inhibits display of buffer list when more than 2 files are loaded.

You can customize this variable.

If you set it to t in your user-init-file or invoke Emacs via

emacs -Q --eval '(setq inhibit-startup-buffer-menu t)' *.txt

the Buffer Menu will not be shown, but you will still get a window split when more than one file argument is supplied. Enforcing no window splits at all may be slightly more involved, judging from the description of --file arguments in (emacs) Action Arguments:

‘FILE’
‘--file=FILE’
‘--find-file=FILE’
‘--visit=FILE’
     Visit the specified FILE.  See Visiting.

     When Emacs starts up, it displays the startup buffer in one window,
     and the buffer visiting FILE in another window (see Windows).
     If you supply more than one file argument, the displayed file is
     the last one specified on the command line; the other files are
     visited but their buffers are not shown.

     If the startup buffer is disabled (see Entering Emacs), then
     FILE is visited in a single window if one file argument was
     supplied; with two file arguments, Emacs displays the files in two
     different windows; with more than two file argument, Emacs displays
     the last file specified in one window, plus a Buffer Menu in a
     different window (see Several Buffers).  To inhibit using the
     Buffer Menu for this, change the variable
     ‘inhibit-startup-buffer-menu’ to ‘t’.

Update

Indeed splitting the window when more than one file argument is supplied is hard-coded in the command-line-1 subroutine in lisp/startup.el:

(when (> displayable-buffers-len 0)
  (switch-to-buffer (car displayable-buffers)))
(when (> displayable-buffers-len 1)
  (switch-to-buffer-other-window (car (cdr displayable-buffers)))
  ;; Focus on the first buffer.
  (other-window -1))

One way around this is to arrange for your desired window configuration to take effect when Emacs is done splitting windows to its heart's content, e.g.

(add-hook 'window-setup-hook #'delete-other-windows)

This has the same effect as typing C-x1 (M-x delete-other-windows) post-startup. Equivalently on the command line:

emacs -Q --eval '(add-hook (quote window-setup-hook) (function delete-other-windows))' *.txt

This hook will ensure the Buffer Menu is not shown even when inhibit-startup-buffer-menu is nil, but you should still set it to t if you do not want the menu to be created in the background at all.

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.