5

Whenever I open more than one file at the same time with emacs, as in:

emacs foo.dat bar.dat

The window that opens will be split between the two files (a buffer for each file). I would like to avoid that. Is there a line I can place in my .emacs file to keep that from happening? I would like emacs to only open one buffer in the window, no matter how many files I'm loading.

I'm using version 23.1.1.

5

The following code works for me (add into ~/.emacs):

(add-hook 'emacs-startup-hook
          (lambda () (delete-other-windows)) t)

The emacs-startup-hook is run after loading the init file and processing the command line, so all files have been loaded and opened; calling delete-other-windows leaves just one of them visible (normally the last one given on the command line).

Note: you might also need to customize inhibit-startup-screen and set it to t for the above to work.

  • 1
    It's unlikely to matter in this case, but you should always use add-hook for hooks, rather than manipulate the list directly. In an unrelated note, curiously, if inhibit-startup-screen if left off, you get exactly two windows: one for the last file on the command line and one with the startup screen. – Gilles Sep 27 '10 at 21:08

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.