同名文件之间的 Emacs 导航 [英] Emacs navigation between files with same names

查看:9
本文介绍了同名文件之间的 Emacs 导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直是 GNU Emacs 文件导航模型的粉丝.我一直在用 C-x C-f ..., C-x b; 切换缓冲区.C-mouse-1 偶尔.

I've long been a fan of GNU Emacs' file navigation model. I've been switching buffers with C-x C-f ..., C-x b; C-mouse-1 occasionally.

但是,最近我发现自己正在编写具有相同名称但位于不同目录中的多个文件集的项目,这些文件如下所示:

However, recently I've been finding myself programming on projects that have sets of several files with the same names, but in different directories, along these lines:

package/message.py
package/message.zcml
package/ui/message.py
package/ui/message.zcml
package/ui2/message.py
package/ui2/message.zcml

在这些情况下,我常用的缓冲区切换工具效率不高.很难记住我想要的文件是在缓冲区 message.py<2> 还是 message.py<3> 中,并且在它们之间切换非常麻烦Cx b.也许我想要的是标签栏或菜单之类的东西,我可以在其中排列我正在处理的文件并让它们保持它们的空间排列,这样我就可以在它们之间快速切换.我简要查看了 speedbartabbar-mode,但没有找到太多帮助.有什么建议吗?

In these circumstances my usual buffer switching tools are not very efficient. It's hard to remember whether the file I want is in the buffer message.py<2> or message.py<3>, and it's pretty fussy to switch between them with C-x b. What I would like, perhaps, is something like tab bar or a menu where I could arrange the files I'm working on and have them maintain their spatial arrangement, so that I could quickly switch beetween them. I briefly looked at speedbar and tabbar-mode, but didn't find much help. Any suggestions?

推荐答案

除了使用 uniquify 来获得更有用的缓冲区名称之外,您可能还想考虑使用 ibuffer满足您的空间安排"需求的群组.您可以根据过滤器集创建命名组,并且可以根据文件路径 (*) 进行过滤,因此您可以轻松地为每个目录创建单独的组.

Along with using uniquify to obtain more helpful buffer names, you might want to look into using ibuffer groups for your "spatial arrangement" needs. You can create named groups based on sets of filters, and you can filter on file path(*), so you could easily have separate groups for each of those directories.

我强烈建议将 C-xC-b 绑定到 ibuffer 以替代默认设置.

I highly recommend binding C-xC-b to ibuffer as a replacement for the default.

除此之外,如果您将 ido-modeuniquify 配置结合使用,那么当您键入 Cxb 要切换缓冲区,您可以键入并匹配(唯一)缓冲区名称的任何部分.如果您启用 ido-enable-flex-matching (或者,使用类似 LustyExplorer 相反)然后您可以键入该缓冲区名称的未连接部分,模糊匹配将智能地缩小列表(例如,键入mez2"可能足以隔离message.zcml|ui2").

Aside from that, if you use ido-mode in conjunction with the uniquify config, then when you type C-xb to switch buffers, you can type and match against any part of the (uniquified) buffer name. If you enable ido-enable-flex-matching (or alternatively, use something like LustyExplorer instead) then you can type unconnected parts of that buffer name, and the fuzzy matching will narrow the list intelligently (e.g. typing "mez2" might be enough to isolate "message.zcml|ui2").

(*) 我个人更喜欢 ibuffer 在我制作文件名过滤器时匹配 dired 缓冲区和文件缓冲区,因此我相应地重新定义了该过滤器:

(*) Personally I prefer ibuffer to match dired buffers as well as file buffers when I make a filename filter, so I redefine that filter accordingly:

;; Enable ibuffer-filter-by-filename to filter on directory names too.
(eval-after-load "ibuf-ext"
  '(define-ibuffer-filter filename
     "Toggle current view to buffers with file or directory name matching QUALIFIER."
     (:description "filename"
      :reader (read-from-minibuffer "Filter by file/directory name (regexp): "))
     (ibuffer-awhen (or (buffer-local-value 'buffer-file-name buf)
                        (buffer-local-value 'dired-directory buf))
       (string-match qualifier it))))

这篇关于同名文件之间的 Emacs 导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆