views:

633

answers:

4

When I use dired mode to browse around and find a file I want to open in Emacs, dired opens a new buffer for each directory I visit when looking for the file each time I select a directory with Enter, which means I can end up with a lot of buffers I don't want:

. * newer                    0  Fundamental       c:/work/stackoverflow/batch/mydir/newer
 %  mydir                  302  Dired by name     c:/work/stackoverflow/batch/mydir/
 %  batch                  616  Dired by name     c:/work/stackoverflow/batch/
 %  stackoverflow         1017  Dired by name     c:/work/stackoverflow/
 %  work                  2545  Dired by name     c:/work/
  * *scratch*              190  Lisp Interaction
 %  *Completions*          162  Completion List
  * *Messages*            2163  Fundamental

Is there any way to make dired re-use a single buffer? I tried M-x customize-group for group dired but didn't see anything promising in there.

Alternatively, does anyone have a macro to close all open dired buffers?

+2  A: 

When browsing in dired instead of hitting enter to see a directory use i then it adds that directory to the current buffer.

Mark
+1 This does help but I'm not sure I like have lots of directories in one buffer.
Dave Webb
A: 

dired-x allows this - do M-x customize-group dired-x and set 'Dired Find Subdir' to on

Alex Ott
Tried this and it doesn't seem to work.
Dave Webb
I think this does something different.
Joel J. Adamson
+17  A: 

Use a (dired-find-alternate-file) instead of Enter

Also, see this page:

http://www.emacswiki.org/emacs/DiredReuseDirectoryBuffer

scottfrazer
Exactly what I want. Even gets rid of the dired buffer altogether if open the file with `a` too!
Dave Webb
+3  A: 

I've never managed to get toggle-dired-find-file-reuse-dir to work reliably - I still end up with a variety of dired buffers open, and I'm never quite sure how.

Recently I discovered dired-single (http://www.emacswiki.org/cgi-bin/wiki/dired-single.el) which seems to work better for me. If you want it guarantees a single dired buffer, and also has a nice command dired-single-magic-buffer which will take you to the open dired buffer if you have one, and opens one if you don't.

There are some other alternatives if it isn't the multiple dired buffers per se that annoy, so much as the way they pollute your buffer lists. For example, elscreen.el has a dired plugin that keeps the dired buffers in their own tab, and the excellent ibuffer mode allows you to group dired buffers together when you list buffers.

Hope that helps!

Simon

Simon