26

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?)

4

4 回答 4

24

这条建议会过滤掉具有以下扩展名的文件'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 的文档以了解那里可用的内容。

于 2009-11-13T21:36:49.413 回答
9

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

  • ido-ignore-buffers 获取要忽略的缓冲区列表C-x b
  • ido-ignore-directories 获取要忽略的目录列表C-x dC-x C-f
  • ido-ignore-files 获取要忽略的文件列表C-x C-f
于 2012-01-04T16:17:14.460 回答
3

默认情况下, Icicles会执行您所期望的操作。它始终尊重completion-ignored-extensions文件名完成,包括缓冲区*Completions*。您可以随时通过点击C-.迷你缓冲区来打开/关闭此忽略。

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

于 2011-09-03T23:43:23.560 回答
1

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

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

(load "dired-x")

您可以使用 'Mx customize-variable<RET>dired-omit-files' 将实际模式设置为忽略。然后,当您处于 dired 模式时,您可以使用 MO(字母,而不是数字)来打开和关闭“省略”。

于 2009-11-13T21:16:57.343 回答