M-x Kelsin

Using IDO for bookmarks and recent files

Date
Thursday, April 22, 2010 at 2:36 pm
Tags
emacs programming

I love Ido mode in emacs. The fuzzy searching works exactly how I want. It automatically works for finding files and switching buffers which is great. Today I finally got it working for bookmarks and recent files.

For bookmarks I found a section on emacs wiki about how to make ido goto a bookmark directory when browsing for files. This isn't quite what I wanted. I wanted to use ido to complete bookmark names to go right to the bookmarks. After finding some example code I came up with this:

(defun bookmark-ido-find-file ()
  "Find a bookmark using Ido."
  (interactive)
  (let ((bm (ido-completing-read "Choose bookmark: "
                                 (bookmark-all-names)
                                 nil t)))
    (when bm
      (bookmark-jump bm))))

Reallyl simple, just bookmark-jump to a bookmark name using bookmark-all-names to pass the names to ido-completing-read.

The next step was to be able to complete on recently seen files. I came up with the following. It's probably not the cleanest or fastest code, but it gets the job done. It lets me complete on the filename (not directories at all) for all recently seen files. I don't know how this behaves when you have files that are named the same, but at the moment this works great.

(defun recentf-ido-find-file ()
  "Find a recent file using Ido."
  (interactive)
  (let* ((files (mapcar '(lambda (file)
                           (cons (file-name-nondirectory file) file))
                        recentf-list))
         (file (cdr (assoc (ido-completing-read "Choose recent file: "
                                                (mapcar 'car files)
                                                nil t)
                           files))))
    (when file
      (find-file file))))

Tags

apple bash blog boston bug calendar code computer concert debian emacs email firefox food games git google haskell heroku htmlize intel-i810 iphone irssi keyboard linux music mutt os-x php plugins programming ps3 recording review rpg ruby ruby-on-rails server sinatra sync ubuntu ups wedding widgets wordpress work wow xbox360 xmobar xmonad xorg zendrum

RSS
Valid XHTML 1.0 Strict