Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
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
    
@Gilles thanks, fixed –  Riccardo Murri Sep 28 '10 at 7:33
    
Yeah, both work great. Thanks. –  Bruce Connor Sep 28 '10 at 11:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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