如何阻止 emacs dired 模式打开如此多的缓冲区?
当我使用 dired
模式 要浏览并查找我想要在 Emacs 中打开的文件,每次我使用 Enterdired 都会为我在查找文件时访问的每个目录打开一个新缓冲区kbd>,这意味着我最终可能会得到很多我不想要的缓冲区:
. * 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
有没有办法让 dired
重新使用单个缓冲区?我尝试了 Mx custom-group
组 dired
但没有看到任何有希望的东西。
或者,有人有一个宏来关闭所有打开的dired
缓冲区吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
使用 a (
dired-find-alternate-file
) 而不是 Enter另请参阅此页面:
http://www.emacswiki.org/emacs/DiredReuseDirectoryBuffer
Use a (
dired-find-alternate-file
) instead of EnterAlso, see this page:
http://www.emacswiki.org/emacs/DiredReuseDirectoryBuffer
当在 dired 中浏览而不是按 Enter 键查看目录时,请使用 i ,然后将该目录添加到当前缓冲区。
When browsing in dired instead of hitting enter to see a directory use i then it adds that directory to the current buffer.
在 Emacs 28 中,您只需
(setf dired-kill-when-opening-new-dired-buffer t)
即可。这适用于dired-find-file
(RET
) 或dired-up-directory
(^
)。In Emacs 28, you can just
(setf dired-kill-when-opening-new-dired-buffer t)
. This works for eitherdired-find-file
(RET
) ordired-up-directory
(^
).我从来没有设法让toggle-dired-find-file-reuse-dir可靠地工作——我仍然最终打开了各种dired缓冲区,而且我从来不太确定如何做到这一点。
最近我发现了 dired-single (http://www.emacswiki.org/ cgi-bin/wiki/dired-single.el)这似乎对我来说效果更好。如果你想要它保证一个单一的 dired 缓冲区,并且还有一个很好的命令 dired-single-magic-buffer ,如果你有的话,它会带你到打开的 dired 缓冲区,如果没有的话,打开一个。
如果不是多个 Dired 缓冲区本身令人烦恼,或者它们污染缓冲区列表的方式,还有其他一些替代方案。例如,elscreen.el 有一个 dired 插件,可以将 dired 缓冲区保留在自己的选项卡中,并且出色的 ibuffer 模式允许您在列出缓冲区时将 dired 缓冲区分组在一起。
希望有帮助!
西蒙
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
来自 Xah Lee,网址为 http://ergoemacs.org/emacs/emacs_dired_tips.html
From Xah Lee, at http://ergoemacs.org/emacs/emacs_dired_tips.html
Dired+ 允许您选择执行此操作,并且它允许您可以随时打开/关闭它。
另请参阅 http://www.emacswiki.org/emacs/DiredReuseDirectoryBuffer。
Dired+ lets you do this optionally, and it lets you toggle it on/off anytime.
See also http://www.emacswiki.org/emacs/DiredReuseDirectoryBuffer.