简体   繁体   English

重新格式化emacs缓冲区列表中的“文件”字段?

[英]reformat 'File' field in emacs buffer list?

Context: using the Buffer List in Emacs to see what I'm doing, choose a buffer to visit, etc. FYI, I use fairly deep (sub-)directory organization to organize my files. 上下文:使用Emacs中的“ 缓冲区列表”来查看我在做什么,选择要访问的缓冲区等。仅供参考,我使用相当深的(子)目录组织来组织我的文件。

When I have lots of files open from the same subdirectory, the 'File' field mostly shows the part of the pathname that is the same for all files, ie the first 2-3 layers in my hierarchy of directories. 当我从同一子目录中打开大量文件时,“文件”字段通常显示路径名中与所有文件相同的部分,即目录层次结构中的前2-3层。 So it gives me high-level info that's not very useful. 因此,它给我提供的高级信息不是很有用。 The 'Buffer' field shows me the filename. “缓冲区”字段显示了文件名。 That gives me low-level info that's too specific. 这给了我太具体的低层信息。

Is there a way to reformat the 'File' field to show me the most useful part of the file's path, ie the last couple of sub-directories the file is contained in and the filename? 有没有一种方法可以重新格式化“文件”字段,以向我显示文件路径中最有用的部分,即文件所包含的最后两个子目录以及文件名? Literally, maybe the last characters of the path, instead of the first ? 从字面上看,也许是路径的最后一个字符,而不是第一个?

I prefer ibuffer for this sort of thing over buffer-menu. 我喜欢ibuffer而不是buffer-menu。 It allows you to group the file names by their name. 它允许您按文件名对文件名进行分组。

For instance, I have this in my .emacs (stolen from emacs-fu for the most part). 例如,我的.emacs文件中有此文件(大多数情况下是从emacs-fu中窃取的)。

(require 'ibuffer) 
(setq ibuffer-saved-filter-groups
  (quote (("default"      
           ("MyProject"
            (filename . "/path/to/my/project/"))
           ("Programming"
            (or
             (mode . sh-mode)                 
             (mode . c-mode)
             (mode . cperl-mode)
             (mode . python-mode)
             (mode . emacs-lisp-mode)

             ;; etc
             ))
           ("Org" ;; all org-related buffers
            (mode . org-mode))                 
           ("ERC"
            (mode . erc-mode))
           ("Jabber"
            (or  ;; jabber-related buffers
             (mode . jabber-chat-mode)
             (mode . jabber-mode)
             (mode . jabber-roster-mode)
             ;; etc.; all your mail related modes
             ))))))

(add-hook 'ibuffer-mode-hook
      (lambda ()
        (ibuffer-switch-to-saved-filter-groups "default")))

(global-set-key (kbd "C-x C-b") 'ibuffer)

This might also help, though it does not address your question directly: Buffer Menu+ . 尽管它不能直接解决您的问题: Buffer Menu + ,但这也可能有帮助。

  • You can use + and - to resize the Buffer and Size columns, giving more space to the other columns. 您可以使用+-来调整BufferSize列的Size ,为其他列留出更多空间。

  • You can toggle the display of columns Time and Mode , to give other columns more space. 您可以切换TimeMode列的显示,以给其他列更多的空间。 (You can also toggle the Time format, making it shorter without removing it.) (您还可以切换Time格式,使其更短而不删除。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM