Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Don't show uninteresting files in Emacs completion window

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

like image 434
emacsulike Avatar asked Nov 13 '09 20:11

emacsulike


2 Answers

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.

like image 147
Trey Jackson Avatar answered Sep 21 '22 05:09

Trey Jackson


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
like image 26
aculich Avatar answered Sep 18 '22 05:09

aculich