不要在 Emacs 完成窗口中显示无趣的文件

发布于 2024-08-11 03:05:45 字数 600 浏览 9 评论 0 原文

当我执行 Cx Cf TAB 时,如何防止 Emacs 显示所有我不感兴趣的文件(例如 ~ 备份文件、.pyc 文件或 .orig 文件)?

它在一方面工作:如果我知道我要打开的文件以 foo 开头,并且我输入 foo TAB 那么迷你缓冲区会正确地自动完成一直到 foo .py。它正确地忽略了 foo~ 和 foo.pyc,因为 ~ 和 .pyc 都在 完成忽略扩展。如果我真的想通过输入自己的所有字母,它也可以正确地让我打开任一被忽略的文件。

但是,如果我只是按 TAB 来调出完成列表缓冲区,则该列表包含扩展名为 completion-ignored-extensions 的文件,这使得查找起来非常困难我在寻找什么。

显然,忽略无趣文件的代码已经存在并且正在运行。如何让完成列表缓冲区尊重完成忽略扩展

(顺便说一句,我可以让 dired 表现出类似的行为吗?)

How do I prevent Emacs from showing me all the files I'm not interested in (such as ~ backup files, .pyc files, or .orig files) when I: C-x C-f TAB ?

It is working in one respect: if I know the file I want to open begins with foo and I type foo TAB then the mini-buffer correctly autocompletes all the way to foo.py. It correctly ignored foo~ and foo.pyc, because both ~ and .pyc are in completion-ignored-extensions. It also correctly lets me open either ignored file if I really want to by typing in all the letters my self.

However, if I just hit TAB to to bring up the completion list buffer then that list includes files with extensions in completion-ignored-extensions, which makes it very difficult to find what I'm looking for.

Clearly the code to ignore uninteresting files is there and working. How do I get the completion list buffer to respect completion-ignored-extensions?

(by-the-by, can I make dired behave similarly?)

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

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

发布评论

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

评论(4

风为裳 2024-08-18 03:05:45

这条建议会过滤掉'completion-ignored-extensions中列出的扩展名的文件:

(defadvice completion--file-name-table (after 
                                        ignoring-backups-f-n-completion 
                                        activate)
  "Filter out results when they match `completion-ignored-extensions'."
  (let ((res ad-return-value))
(if (and (listp res)
     (stringp (car res))
     (cdr res))                 ; length > 1, don't ignore sole match
    (setq ad-return-value
              (completion-pcm--filename-try-filter res)))))

注意:这不会影响dired

对于 dired 问题,请将其添加到您的 .emacs 中

(eval-after-load "dired"
  '(require 'dired-x))

(add-hook 'dired-mode-hook
          (lambda ()
            (dired-omit-mode 1)))

阅读 dired-x 的文档 了解那里有什么可用的。

This piece of advice filters out files with extensions listed in 'completion-ignored-extensions:

(defadvice completion--file-name-table (after 
                                        ignoring-backups-f-n-completion 
                                        activate)
  "Filter out results when they match `completion-ignored-extensions'."
  (let ((res ad-return-value))
(if (and (listp res)
     (stringp (car res))
     (cdr res))                 ; length > 1, don't ignore sole match
    (setq ad-return-value
              (completion-pcm--filename-try-filter res)))))

Note: This doesn't affect dired.

For the dired issue, add this to your .emacs

(eval-after-load "dired"
  '(require 'dired-x))

(add-hook 'dired-mode-hook
          (lambda ()
            (dired-omit-mode 1)))

Read the documentation for dired-x to get an idea of what's available there.

柏拉图鍀咏恒 2024-08-18 03:05:45

我建议使用 ido-mode 来忽略文件;它默认随 Emacs 一起提供,并添加了许多其他有用的增强功能,您很快就会喜欢上这些功能。 这篇掌握 Emacs 博文中的“无知是福”部分介绍了如何忽略文件、目录和缓冲区:

  • ido-ignore-buffers 获取要在 Cx b 中忽略的缓冲区列表
  • ido-ignore-directories获取 Cx dCx Cf 中要忽略的目录列表
  • ido-ignore-files 获取 中要忽略的文件列表Cx Cf

I would recommend using ido-mode to ignore files; it comes with Emacs by default and adds many other useful enhancements that you'll quickly learn to love. The Ignorance is Bliss section from this Mastering Emacs blog post covers how to ignore files, directories, and buffers:

  • ido-ignore-buffers Takes a list of buffers to ignore in C-x b
  • ido-ignore-directories Takes a list of directories to ignore in C-x d and C-x C-f
  • ido-ignore-files Takes a list of files to ignore in C-x C-f
老街孤人 2024-08-18 03:05:45

Icicles 的作用默认情况下你期望的。它始终遵循 completion-ignored-extensions 进行文件名补全,包括缓冲区 *Completions*。您可以随时通过在迷你缓冲区中点击 C-. 来打开/关闭此忽略功能。

此外,如果您使用库 completion-ignored-build.el 由 Kevin Ryde 编写,然后 Icicles 自动利用该库对忽略的文件扩展名的动态调整。 (只需加载completion-ignored-build.el——不要启用其次要模式或建议。)

Icicles does what you expect by default. It always respects completion-ignored-extensions for file-name completion, including for buffer *Completions*. And you can toggle this ignoring on/off at anytime, by hitting C-. in the minibuffer.

In addition, if you use library completion-ignored-build.el by Kevin Ryde, then Icicles automatically takes advantage of that library's dynamic adjustment of ignored file extensions. (Just load completion-ignored-build.el -- do not enable its minor mode or advice.)

一百个冬季 2024-08-18 03:05:45

恐怕我不知道完成的答案。我认为这是设计使然 - 当您知道要查找的名称时,您可能不需要备份文件等。但当您不知道时,最好拥有所有文件的列表。

但是,对于 dired,您可以在启动时加载 'dired-x' 包(在 .emacs 中),这提供了 dired-omit-mode:

(load "dired-x")

您可以使用 'Mxcustomize-variabledired-omit-files'设置要忽略的实际模式。然后,当您处于拨号模式时,您可以使用 MO(字母,而不是数字)来打开和关闭“省略”。

I don't know of an answer for completion, I'm afraid. I think this is by design - when you know the name you're looking for, you probably don't want e.g. the backup file. But when you don't know, it's probably better to have a list of all of the files.

However, for dired, you can load the 'dired-x' package on startup (in your .emacs), and this provides dired-omit-mode:

(load "dired-x")

You can use 'M-x customize-variable<RET>dired-omit-files' to set the actual patterns to ignore. Then when you are in dired mode you can use M-O (the letter, not the number) to toggle 'omission' on and off.

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