reddit / emacs
What’s the point of dired creating a new buffer for each directory visited?
CorysInTheHouse69 · 2022-12-29 00:47
Title
ieure · 2022-12-29 01:17
Plenty of usecases: say you're marking stuff you think you want to delete, but want to look inside a directory to check if it has stuff you want to save.
You can press `a` instead of `RET` if you prefer to replace the current buffer with whatever point's on.
nv-elisp · 2022-12-29 01:18
In Emacs 28.1 and above there's a `dired-kill-when-opening-new-dired-buffer` user option.
As far as what "the point" of it behaving that way is:
- that's how it was implemented
- it allows one to quickly change between directories by selecting buffers
I'm sure there are other people who have other uses for multiple dired buffers as well.
AnugNef4 · 2022-12-29 02:05
My emacs instances routinely have > 100 buffers going, according to C-x C-b. I don't notice any performance impact. :shrug emoji:
CorysInTheHouse69 · 2022-12-29 02:27
Thanks, I was worried about performance issues
CorysInTheHouse69 · 2022-12-29 02:28
I see. That actually makes a lot of sense. Thanks
00-11 · 2022-12-29 02:40
Yes, the vanilla Emacs behavior is to create a new Dired buffer each time, with the result that you can accumulate lots of them that you don’t necessarily want to keep around.
Sometimes you want new buffers created, sometimes you don't. There are good reasons (others have mentioned some here) why you often *do* want new Dired buffers. But sometimes you don't.
With [Dired+](https://www.emacswiki.org/emacs/DiredPlus) the choice of whether to create new buffers or reuse existing buffers is yours.
You can just use `C-M-R` (aka `C-M-S-r`) anytime, to toggle whether Dired buffers get reused. **I added this feature to Dired+ in 2005 - 16 years ago.**
Plus, there are separate commands, so even without toggling you can get one or the other behavior (reuse or new) as a one-off anytime. If you want to do that then just bind the reuse commands to keys.
To set reuse as the default behavior, just put this in your init file:
(diredp-toggle-find-file-reuse-dir 1)
I tried to get vanilla Emacs to adopt such a feature long ago, to no avail.
Emacs finally added a way to *almost* get such behavior, by adding option `dired-kill-when-opening-new-dired-buffer` (a 40-char name!) in the latest Emacs release (28). But that makes you decide statically whether you want such behavior: either reuse all the time or none of the time.
IOW, vanilla Emacs saddles you with either *always* creating new buffers or *never* doing so. It's better to just toggle the behavior anytime you like. Emacs could at least have used a minor mode (toggle) instead of just adding a Boolean option. Maybe that minor change will come someday.
----
On a related note, be aware that you can use `C-x C-v` (`find-alternate-file`) on a directory name, to kill the current buffer (whether Dired or not) and replace it with a Dired buffer. This is particularly handy in that when you just hit `RET`, keeping the same current directory, its behavior is similar to but different from `g` (`revert-buffer`).
Whereas `g` rereads/refreshes the directory, it intentionally *keeps Dired state* such as the markings, inserted subdir listings, `ls` switches, and the set of omitted files. `C-x C-v` keeps no state - it gives you a clean slate each time. Both `g` and `C-x C-v` are useful -- just be aware of the difference.
(In addition to `C-x C-v` you have `a`, command `dired-find-alternate-file`, which just does a `C-x C-v` on the directory or file of the current line.)
republic_of_mao · 2022-12-29 02:53
I use "i" (dired-maybe-insert-subdir) when I want to stay in the same buffer.
Sometimes, it's just useful to have different dired buffers. I usually have about 10-50 open at any time. Recently, I started to use "ibuffer" with filter groups to keep things from getting out of hand.
FrozenOnPluto · 2022-12-29 06:02
There is a melpa package that just has it open in place IIRC
revrari100 · 2022-12-29 06:15
Dired+ obviates this problem. See this video:
[https://youtu.be/Dom2kbG4XwM](https://youtu.be/Dom2kbG4XwM)
Reuse dired buffers 16:50
wunderspud7575 · 2022-12-29 08:57
I wonder if it is worth retrying to get some of the Dired+ enhancements added to core Emacs now? The project seems to be much more open to new ideas and modernization than it was 15 years ago.
AuroraDraco · 2022-12-29 11:07
I doubt you can hit that. Have never encountered it myself nor have heard anyone speak of it.
Maybe if you go to a few thousands it might I guess, but I wouldn't really worry
ftrx · 2022-12-29 11:21
IMVHO historically since directories was (and are technically) not a "folder" but a "directory" witch means a list of files, like an index, then well, you edit such file, an index. As you visit individual files so you visit individual special index files named directories.
Something similar was also far after an RH idiosyncrasy from RH8-9 or so with Nautilus/Gnome 2 where by defaults any double-clicked directory open in a new windows. The world change such behavior but they insist for long.
Gallipo · 2022-12-29 12:24
I use dired-buffers as a list of "visited places" and I can switch back to any of them witch `C-x b`
sunnyata · 2022-12-29 15:37
> I added this feature to Dired+ in 2005 - 16 years ago.
Thanks for that! :-)
TheFrenchPoulp · 2022-12-29 16:49
I gave it a try when I saw the post and decided to come back later see if anyone mentions the alternate command: afaik `a` doesn't actually kill the dired buffers
My idea was to swap the 2 behaviors `a` and `RET` since as you mentioned one might want the 2 behaviors in different contexts so the static custom is not that useful in that regard. But when testing the 2, I noticed dired buffer were still available as I navigated through directories using the alternate command
bagtowneast · 2022-12-29 18:32
I've been stumped for a while. How do you undo the results of "i" when I no longer want that subdir in the buffer?
barbaneigro · 2022-12-29 21:18
yep, I too find it immensely annoying.
00-11 · 2022-12-29 22:12
`a` does `find-alternate-file` on the file or directory of the current line (as its doc tells you).
If you do it on the line of the current Dired directory, which is `.`, then it does the same thing as `C-x C-v RET`: replaces the current listing by a new listing of the same directory. That is, it reuses the current Dired buffer (for the same directory).
If you do it on some other line then no, it doesn't kill/reuse the current Dired buffer. If you do it on a directory line other than `.` then it creates a new Dired buffer for that directory.
This is why I separated mention of `C-x C-v` and `a` from the description I gave of the feature of replacing the current Dired listing with another one, reusing the same buffer. I used a separator line, like this:
----
00-11 · 2022-12-29 22:19
Feel free to try. `M-x report-emacs-bug` is also for enhancement requests. I suggest you propose small bits (features) of Dired+ at a time (one per ER). And they'll request a patch no doubt. I've given up on that, in general.
If they do accept some patch for a bit of it, they'll likely want some changes or impose limitations, some of which might be equivalent but others of which might be less than what Dired+ provides.
In the latter case I'll need to anyway continue to include that bit in Dired+ (because it's designed to be compatible with multiple Emacs releases).
In the former case I'll be able to remove it for the new releases of Emacs that come to include it.
Good luck. (Oh, and it's not about "modernization". ;-))
republic_of_mao · 2022-12-29 22:34
"C-u k" (dired-do-kill-lines with a prefix) at the subdir heading. Doesn't work at the top level.
another option is:
"$" (dired-hide-subdir) collapses the subdir. Does work at the top level.
yet another is:
"C-/" (dired-undo). I never use this, but it does work!
aside: I love magit and org mode as much as anybody, but in my opinion, dired the most killer of emacs's killer apps. no other file browser allows you to do what you can do with dired.
bagtowneast · 2022-12-29 22:47
Thanks!
I've only just started to use dired, and it's starting to work well for me.
CGenie · 2022-12-30 06:48
[https://www.manueluberti.eu/emacs/2021/07/14/dired/](https://www.manueluberti.eu/emacs/2021/07/14/dired/)
Since Emacs 28.1 you can do:
(setq dired-kill-when-opening-new-dired-buffer 1)
terminal_cope · 2022-12-31 01:48
Yeah, it's just a cache, `midnight-mode` can keep it under control if necessary.
terminal_cope · 2022-12-31 03:31
`dired-subtree` lets you insert and remove the subtrees inline.
bagtowneast · 2022-12-31 19:38
Thanks!