Emacs:在不同目录中的同名缓冲区之间切换

发布于 2024-10-31 15:11:35 字数 397 浏览 6 评论 0原文

我有两个同名但位于不同目录的文件:

apples/main.cpp
oranges/main.cpp

我通过 emacs apples/main.cpp Oranges/main.cpp 在一个 emacs 窗口中打开它们

当我使用 Cx b 要在这两个缓冲区之间切换,缓冲区名称为“main.cpp”和“main.cpp<2>”。我希望在切换缓冲区时能够看到这两个文件的完整路径,这样我就可以消除苹果和橙子版本之间的歧义。有办法做到这一点吗?

一种方法可能是修改生成 <2> 的任何代码。在第二个 main.cpp 之后,当 Emacs 检测到具有该名称的缓冲区已打开时。但是,我找不到如何执行此操作。

I have two files with the same name but in different directories:

apples/main.cpp
oranges/main.cpp

I open them in one emacs window via emacs apples/main.cpp oranges/main.cpp

When I use C-x b to switch between these two buffers, the buffer names are "main.cpp" and "main.cpp<2>". I would love to be able to see the full path of these two files when switching buffers, so that I may disambiguate between the apples and the oranges version. Is there a way to do this?

One way could be to modify whatever code generates the <2> after the second main.cpp when Emacs detects that a buffer with that name is already open. However, I couldn't find how to do this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

年少掌心 2024-11-07 15:11:35

使用 uniquify。我这样使用它:

(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)

Use uniquify. I use it like that:

(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
护你周全 2024-11-07 15:11:35

扩展托马斯的答案。

除了 forward 之外,您还可以考虑 uniquify-buffer-name-style 的其他选项:

文件 /foo/bar/mumble/name 和 /baz/quux/mumble/name 将具有以下内容各种样式的缓冲区名称:

forward        bar/mumble/name  quux/mumble/name
reverse        name\mumble\bar  name\mumble\quux
post-forward   name|bar/mumble  name|quux/mumble
post-forward-angle-brackets   name<bar/mumble>  name<quux/mumble>

如果要删除冲突文件的公共目录后缀,请将下面的行添加到您的 emacs init 文件中。

(setq uniquify-strip-common-suffix t)

现在,如果您打开 /a1/b/c/d 和 /a2/b/c/d,缓冲区名称将显示
“d|a1”和“d|a2”而不是“d|a1/b/c”和“d|a2/b/c”。

Expanding on Tomasz's answer.

There are other options for uniquify-buffer-name-style, besides forward, that you may consider:

Files /foo/bar/mumble/name and /baz/quux/mumble/name would have the following buffer names in the various styles:

forward        bar/mumble/name  quux/mumble/name
reverse        name\mumble\bar  name\mumble\quux
post-forward   name|bar/mumble  name|quux/mumble
post-forward-angle-brackets   name<bar/mumble>  name<quux/mumble>

If you want to strip common directory suffixes of conflicting files, add the line below to your emacs init file.

(setq uniquify-strip-common-suffix t)

Now, if you open /a1/b/c/d and /a2/b/c/d, the buffer names will say
"d|a1" and "d|a2" instead of "d|a1/b/c" and "d|a2/b/c".

丢了幸福的猪 2024-11-07 15:11:35

使用 lusty 浏览器。配置它:

(require 'lusty-explorer)

;; Override the normal file-opening and buffer switching.
(global-set-key (kbd "C-x C-f") 'lusty-file-explorer)
(global-set-key (kbd "C-x b")   'lusty-buffer-explorer))

Use lusty explorer. Configure it with:

(require 'lusty-explorer)

;; Override the normal file-opening and buffer switching.
(global-set-key (kbd "C-x C-f") 'lusty-file-explorer)
(global-set-key (kbd "C-x b")   'lusty-buffer-explorer))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文