Tuesday, October 14, 2008

Introducing fuzzy-find-in-project: TextMate-style file browsing in Emacs

Moved here

I've been trying off and on to learn to use Emacs over the last few months, but I always found myself coming back to TextMate for one reason: the "Command-T" Find File in Project command. I tried a few of the plugins for Emacs that were supposed to replicate the functionality, but none of them had the performance to quickly search through thousands of files. I had just about given up when I saw Jamis Buck's post about porting an enhanced version of TextMate's functionality to a rubygem, which he could wrap with a vim plugin. A few days later, I wrote my own wrapper to the gem for Emacs as a way of learning Emacs-Lisp, and posted it to GitHub: fuzzy-find-in-project. It works pretty much like Jamis' vim plugin, and has been pretty fast as far as I can tell (at least, much faster than the pure Elisp plugins I tried). Here's how it works:
Run the command
Narrowing down the possibilities
Selecting the next match
Opening the matched file
You can modify the project directory with the function:
(fuzzy-find-project-root "~/path/to/project")
Check it out!

6 comments:

codemac said...

Have you checked out ido.el? I'm pretty sure it'll be blazingly fast, and a slightly better UI as well. It's cool that you took the time to implement this on your own though.

Justin Weiss said...

Actually, I was using a combination of ido and find-file-in-project.el to get real work done while I was writing this. I found that it works great for up to about 1000 files, then degrades really fast afterward (at least, if you use fuzzy matching.) I think it's because ido-mode was matching on the whole path, while the rubygem allows you to specify what should match on the path and what should match on the filename.

rejeep said...

Rinari (http://github.com/technomancy/rinari/tree/master) has that functionality with ido-mode. Don't know about performance though. Fast enough for me! The function name is "rinari-find-file-in-project".

Justin Weiss said...

Rinari's find-file-in-project is actually really good -- my only issue with it was how it dealt with duplicate file names. I jump between Rails projects pretty regularly, and Rinari uniquifies file names by appending the parent directory's name to the file name. Works great in most cases, but not so much for things like application_helper.rb in a rails project (which will always be under a directory named "helpers") :-)

It might be even better to append the closest unique path component to the file name -- I think that's what Netbeans' "find file in project" does. But Netbeans, of course, has other issues.... :-)

Remco van 't Veer said...

I love the navigation in emacs-rails. Together with iswitch-menu I don't miss TextMate for a second.

Unknown said...
This comment has been removed by a blog administrator.