如何阻止 emacs dired 模式打开如此多的缓冲区?

发布于 2024-08-13 11:24:05 字数 979 浏览 8 评论 0原文

当我使用 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-groupdired 但没有看到任何有希望的东西。

或者,有人有一个宏来关闭所有打开的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

孤独岁月 2024-08-20 11:24:05

使用 a (dired-find-alternate-file) 而不是 Enter

另请参阅此页面:

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

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

Also, see this page:

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

习惯成性 2024-08-20 11:24:05

当在 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.

黯淡〆 2024-08-20 11:24:05

在 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 either dired-find-file (RET) or dired-up-directory (^).

无妨# 2024-08-20 11:24:05

我从来没有设法让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

愿与i 2024-08-20 11:24:05

来自 Xah Lee,网址为 http://ergoemacs.org/emacs/emacs_dired_tips.html

;; Make dired open in the same window when using RET or ^
(put 'dired-find-alternate-file 'disabled nil) ; disables warning
(define-key dired-mode-map (kbd "RET") 'dired-find-alternate-file) ; was dired-advertised-find-file
(define-key dired-mode-map (kbd "^") (lambda () (interactive) (find-alternate-file "..")))  ; was dired-up-directory

From Xah Lee, at http://ergoemacs.org/emacs/emacs_dired_tips.html

;; Make dired open in the same window when using RET or ^
(put 'dired-find-alternate-file 'disabled nil) ; disables warning
(define-key dired-mode-map (kbd "RET") 'dired-find-alternate-file) ; was dired-advertised-find-file
(define-key dired-mode-map (kbd "^") (lambda () (interactive) (find-alternate-file "..")))  ; was dired-up-directory
小嗷兮 2024-08-20 11:24:05

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文