Smex is a replacement for execute-extended-command that uses ido to choose which commands to execute. If you don’t already use ido, you should. I’ll write more about it in a future post, but it makes buffer and file switching much nicer. It allows for fuzzy matching, history, file searching, and more. To enable it, add the following to your .emacs file:
(require ‘ido) ;interactive do
(setq ido-enable-flex-matching t) ;enable fuzzy matching in ido-mode
(ido-mode t) ;use ido for buffer/file switching
(ido-everywhere t) ;enable ido everywhere
Smex, as I mentioned before, uses ido to select a command. This lets you use all your ido customizations to select commands, such as fuzzy matching. This is incredibly useful, and something I had wished for before. It also doubles as an additional apropos, since once you have a function selected you can use “C-h f” to view that function’s documentation.
Smex does have its downsides, though. One of these is the behaviour of the spacebar. In execute-extended-command, spacebar will complete the next unique word in the currently selected command. In ido, it displays all the possible remaining completions in a buffer. Switching from these behaviours is quite annoying, and I would be much happier if the spacebar acted more like it did previously - I’ll probably hack up some elisp and post it later today. Smex also does not automatically update it’s cache unless emacs has been idle for 6- seconds, and so recently defined commands will not be available to use. This, however, is easily fixed by modifying smex-auto-update.
Another thing I noticed was that “C-a” does not move to the beginning of the minibuffer. I’ve had a few occasions where I was to start appending to the beginning of a command, but had to use backwards-work to get there. In ido, “C-a” toggles whether you are ignoring certain filetypes, which is irrelevant for smex.
To install smex, first install it from: http://github.com/nonsequitur/smex/.
Add the following to your .emacs file:
(require ’smex)
(smex-initialize)
(smex-auto-update)
(global-set-key (kbd “M-x”) ’smex)
After this, Smex should be set up on your system.
Tags: emacs