I am using ido-mode to select files from Emacs. This works well for most cases, but for some cases I would like to modify the files that are shown in the completion buffer with ido-find-file.

In some folders I have a lot of *.bak files, and I would like to have the possiblity to remove them from the completion buffer by pressing the F1 key, for example. This is how far I got on this task:

(add-hook 'ido-minibuffer-setup-hook 'ido-my-keys)

(defun ido-my-keys ()
  (define-key ido-file-completion-map (kbd "<f1>") 'my-modify-files))

(defun my-modify-files ()
  (message-box "Here I would like to delete the .bak files from the minibuffer"))

ido-mode has built-in support for hiding files matching specific regexps. All you need to do is add \.bak to ido-ignore-files:

(add-to-list 'ido-ignore-files "\.bak")

After invoking ido-find-file, you can then hit C-a (ido-toggle-ignore) to toggle hiding of .bak files.

|improve this answer|||||
  • Perfect! It works like a charm :) – Håkon Hægland Nov 13 '14 at 10:05
  • 1
    @HåkonHægland Great! :) If you're interested, have a look at the documentation of ido-find-file (C-h f ido-find-file RET) for a full list of commands and options you can toggle while the Ido prompt is active. – itsjeyd Nov 13 '14 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.