views:

286

answers:

5

Hi, is there a way to have dired operate in a single window so that when I traverse through directories I don't have n number of dired buffers for the intermediate directories? However - if I start another dired buffer in a completely separate directory (from the minibuffer rather than hitting [enter] on a subdirectory in an already open dired instance) I'd like to retain the two separate dired buffers... I guess I'm using ido-dired since I have ido-mode on but I don't know that the solution would be different? Thanks much!

+1  A: 

Like this?

(defadvice dired-find-file (around kill-old-buffer activate)
    "When navigate from one dired buffer to another, kill the old one."
    (let ((old-buffer (current-buffer))
          (new-buffer (dired-get-filename))) 
      ad-do-it
      (kill-buffer old-buffer)
      (switch-to-buffer new-buffer)
))
Kilian Foth
+1  A: 

If you mostly want to have each dired buffer work with various subdirs that are all under a single hierarchy (e.g. one dired buffer for each of several ongoing projects), you can use the built-in i (dired-maybe-insert-subdir) and k (dired-do-kill-lines on the header of an inserted subdir to remove it from the buffer) commands. They will let you edit multiple directories inside a single dired buffer. You might want a small custom command and to remap RET if it is too ingrained in your muscle memory though.

Chris Johnsen
A: 

Duplicate question:

http://stackoverflow.com/questions/1839313/how-do-i-stop-emacs-dired-mode-from-opening-so-many-buffers/1839493

scottfrazer
Post as comment to OP not a new anwser.
Török Gábor
+6  A: 

I reduce the dired-buffer clutter by hitting a (dired-find-alternate-file) on subdirectories, rather than RET; that recycles the current dired window.

offby1