When using Emacs I’m often switching buffers or opening files, so I’m always on the lookout for ways to make those operations more pleasant.
A while ago I tried Anything.el. Anything is like Quicksilver for Emacs. It’s powerful but I found it confusing to set up. Emacs-Fu had a blog post about configuring anything.el, and I used that for my setup.
For the most part, I use it instead of
When I saw that Helm was the successor to Anything, I decided to switch to Helm and simplify my setup. I was pleasantly surprised by how easy Helm was to set up compared to Anything. Here’s my setup, binding Alt+T (inspired by Textmate) to invoke
(require 'helm-files) (setq helm-idle-delay 0.1) (setq helm-input-idle-delay 0.1) (setq helm-c-locate-command "locate-with-mdfind %.0s %s") (loop for ext in '("\\.swf$" "\\.elc$" "\\.pyc$") do (add-to-list 'helm-c-boring-file-regexp-list ext)) (define-key global-map [(alt t)] 'helm-for-files))
This uses the default
helm-for-files setup, which lists, in order:
- ffap (find file at point)
- buffers (names of all open buffers)
- recentf (recently opened files)
- bookmarks (which I don’t use)
- files-in-current-dir (like find-file)
- locate (files in other directories)
However, I don’t want
locate for all files on my disk; I want my home directory, minus a few subdirectories that contain files I never open. For this, I use a shell script to filter the results. On a Mac, use
mdfind -name instead of
locate; it’s updated in real time instead of nightly.
#!/bin/bash mdfind -onlyin $HOME -name "$@" \ | grep -v "$HOME/Library/" \ | grep -v "$HOME/Pictures/" \ | grep -v "$HOME/Music/" mdfind -onlyin $HOME/.emacs.d -name "$@"
(Note: if you want to use mdfind to search contents and not only filenames, take a look at
- Ideally, I don’t want to have to think about whether I’ve already opened a file or not. In practice I do treat switching buffers and opening files differently. I use Alt+J and Alt+K for switching buffers in the same directory (see this blog post). I sometimes use
ido-find-file(bound to Alt+O) for opening a file in the same directory, but I’m increasingly using
helm-for-fileseven in the same directory.
mdfindis so fast with an SSD, I reduced the initial delay from 300ms to 100ms. That made it feel much better. You may need to experiment with the delay setting.
- The same file can be in the buffers list, the recent files list, the current directory list, and the locate list. I’d like to see each file only once. I’m sure helm can filter these out but I don’t know how.
- It'd be nice to not have it print out the full path every time, but I haven't figured out how to do that.
There are so many amazing things Helm can do; I’m only using it for this one feature, and it’s been great.