Mac OS X for Emacs Users
Tuesday, June 20, 2006
A common
definition of "productivity" is "The rate at which goods or
services are produced". For programmers, this usually comes down to
"lines of code" (LoC); however, there are also those who feel that LoC is
not a good (or fair) measure of productivity since this can vary
greatly depending on the problem domain, the programming language
used, and a variety of other factors. There have
been a number of recent posts (see
here and
here) about how LoC productivity can vary so much. Now, some of this
is due to the individual (some
hackers are just much better than others); however, some
contributors to
productivity are either environmental or learned. So, how
does one increase productivity? This is a really huge topic and I
don't plan to attempt to address it in any depth, so, in this post, I'm going to focus on
just one small area: what I've done to optimize my own Mac OS X development
environment.
First off, let me say that my name is Bill Clementson and I'm an Emacs
addict. ;-) There, I've said
it. For the rest of you Emacs addicts (uhm, I mean, users) out there, I've written a number
of other posts that describe how you can survive being an Emacs addict (see
here,
here,
here,
here,
here,
here) as well as how you can optimize your physical environment for Emacs use. The rest of this post describes how I've been able to exploit this addiction to
improve my productivity on Mac OS X. VI users or non-Mac users will probably want to stop reading at this
point (although there might be some useful information for non-Emacs
Mac OS X
users too). Others
have written about how to improve your productivity generically within
Emacs as well as specific tips for when you're
writing Lisp code in Emacs. I won't touch on those topics in this post. Instead, what I'll be discussing is
how I've attempted to optimize my Mac OS X environment for keyboard
usage in general and Emacs-style keyboard usage in particular.
Let me begin with a primary premise:
Anything that makes me move my hands from the keyboard reduces my productivity as a programmer.And a secondary premise:
Being able to use standard Emacs key bindings improves my productivity as a programmer.Notice that both of these premises were qualified with "as a programmer". I don't have any objection to using a mouse (or alternative pointing device) when I'm not developing code; however, when I am developing code, I want to keep my hands on my keyboard all of the time. Although writing code (in Emacs) is a core activity for me, I use other programs as well during the development process (sending emails to other developers, searching for things both locally and on the Internet, testing programs, etc), so it is important to be able to do everything from the keyboard. The Mac OS X graphical user interface is nice; however, it is not optimized for keyboard usage. Linux users have alternative Window Managers (among others, there are ratpoison, ion, and StumpWM) that they can use if they prefer a keyboard-optimized graphical UI; but, unless you want to run everything under X-Windows, you don't really have that option under OS X. So, here are the things that I've done to optimize my Mac OS X environment for keyboard usage (Note: these changes work for me. They may not work for you or may cause problems - YMMV, caveat emptor and remember to make backups frequently!):
- Quicksilver application launcher: The standard place to put applications that you frequently use is the Dock. However, a lot of people (myself included) dislike the dock. There are alternatives though and my personal favorite is Quicksilver, an application launcher that allows you to quickly launch (and manipulate) anything using just the keyboard. However, as with many powerful utilities, it is really hard to describe what makes Quicksilver so neat. Fortunately, there are a number of good reviews, online videos, and tutorials that do a good job of illustrating how using Quicksilver really changes the way that you interact with your Mac. Since switching to Quicksilver, I just hide my Dock and launch everything from the keyboard. Incidentally, I also use Spotlight for local searches (I only index key directories with Quicksilver and use Spotlight for broader searches. Although Spotlight may look similar to Quicksivler initially, Quicksilver is much more powerful. But, Spotlight is much quicker at just searching for things, so I use them both. I bind Quicksilver to Cmd-SPC and Spotlight to Cmd-Shift-SPC). In addition to using Quicksilver, there are a number of other things that you can do if you want more of a "full screen" view in your apps; however, I've found that just the change to Quicksilver has been enough to radically change how I work on my Mac. Definitely recommended!
- Emacs key bindings in text widgets: There is an
excellent article that describes the Cocoa Text System. Apple has
already made a lot of the standard key bindings under OS X
conformant with Emacs standards (for example, "C-f" moves forward
1 character, "C-d" deletes 1 character); however, it is possible
to customize the key bindings even further so that even more
functionality uses Emacs-like bindings. Basically, to do this, all
you have to do is create an override key binding file in
~/Library/KeyBindings/DefaultKeyBinding.dict with the custom
bindings (if the ~/Library/KeyBindings/ directory doesn't exist,
just create it). The full instructions are
here. Luckily, you don't have to create these from scratch. There
are several different ones available.
This one adds numerous Emacs bindings using Option/Alt as meta,
while
this one does the same but with Esc as meta. This will add
the following additional Emacs-style bindings:
Ctrl shortcuts C-l Recenter C-/ Undo C-_ Undo C-Spc Set mark C-@ Set mark C-w Delete to mark
Incremental search (once the Incremental Search IM is installed) C-s Incremental search C-r Reverse incremental search C-g Abort
Meta shortcuts M-f Move forward word M-b Move backward word M-< Move to beginning of document M-> Move to end of document M-v Page Up M-/ Complete M-c Capitalize M-u Uppercase M-l Lowercase M-d Delete word forward M-C-h Delete word backward M-Bksp Delete word backward M-t Transpose words M-@ Mark word M-h Mark paragraph
C-x shortcuts C-x u Undo C-x k Close C-x C-f Open (find file) C-x C-x Swap with mark C-x C-m Select to mark C-x C-s Save C-x C-w Save as - Incremental Search in text widgets: The standard for
search in Emacs is incremental search. However, in OS X, you
normally have to type in the complete search term and press enter
after evoking find with "Cmd-f". Fortunately (as described in the
above article), it is possible to add your own text input
managers. So, by installing the one from
here (unpack the zip file and move the directory "IncrementalSearchInputManager" into the directory ~/Library/InputManagers/
[Create that directory if it's not already there]), you can add an
incremental search input manager. Once you've installed it, add the
following bindings to the
~/Library/KeyBindings/DefaultKeyBinding.dict file that you created
in the previous step (just uncomment the statements that are already
in the file if you downloaded one of the two I referenced above
instead of creating your own set of bindings):
{ /* Ctrl-S and Ctrl-R for incremental search */Then, whenever you're anywhere in a text widget in OS X, you can press "C-s" or "C-r" to do a forward/backward incremental search and "C-g" to abort the search just like in Emacs!
"^s" = "ISIM_incrementalSearch:"; "^r" = "ISIM_reverseIncrementalSearch:"; "^$g" = "abort:"; } - Use Conkeror with Firefox: I've previously (see here and here) posted about using the Conkeror Firefox extension in order to make maximum use of the keyboard when browsing the web. I won't say anything more about Conkeror here; however, I do recommend Conkeror for anyone who wants to use Firefox without a mouse.
- Emacs bindings in Firefox: Not everybody likes Conkeror
(or, you may like Conkeror but alternate between using plain Firefox
and Conkeror/Firefox),
but it is still possible to "tweak" Firefox to make it more
conformant with Emacs key bindings. Unfortunately, Firefox doesn't
make use of the system-wide Cocoa key bindings, so the changes in the
previous steps won't affect the Firefox key bindings. However, it is
possible to separately modify them. The exact method for doing this
changed in Firefox version 1.0.5, so the following will only apply
to later versions of Firefox (Note: These steps are taken from
this web page):
- Download the platformHTMLBindings.xml file into ~/Desktop.
- Edit them if you want to change any of the bindings
- cd /Applications/Firefox.app/Contents/MacOS/chrome
- cp toolkit.jar toolkit.jar.orig (i.e., create a backup copy for safety)
- unzip toolkit.jar
- cp ~/Desktop/platformHTMLBindings.xml content/global/platformHTMLBindings.xml
- jar 0cvf toolkit.jar content (it's a zero, but you're copying/pasting this, right?)
- Restart Firefox
Update-2009-08-17: In order to use the Incremental Search input manager mentioned above in Leopard, one needs to follow the instructions here.

