Emacs As An External Editor On Mac OS X

by rob on August 20, 2009

in Programming

For many years, Emacs has had client-server support so that you can leave it running all the time while allowing external applications to open files in it as needed. But that doesn’t work with GUI applications on the Mac, since they generally don’t know how to call an editor using the shell. Instead, most Mac apps that support external text editors use the ODB Editor Suite created by Bare Bones Software, which extends the normal Mac “open file” event with the ability for the editor to tell the calling app when it’s done.

Support for the ODB protocol isn’t built into Emacs, but it’s basically the same as using emacsclient from the shell. So without further ado, here is “EditorClient”, a small shim application which acts like an ODB editor but actually opens files in Emacs. All it does is intercept the “open file” event and call emacsclient. When you’re done editing the file (C-x # or server-edit in Emacs) it responds to the ODB client application which can then update its contents. If you use a non-Mac port of Emacs for some reason, you can probably also associate files with it in the Finder to make for easier double-click editing. (The Mac ports of Emacs can do that themselves; they just don’t have the special handling for ODB events.)

This is really sort of a quick and dirty hack; it’s only for Leopard and the emacsclient call is hard-coded to use the one in the /Applications/Emacs.app bundle. I’ll try to improve it later, but I’m posting it now in case anyone else out there is looking for something like this.

Download it here: [drain file 19 url] ([drain file 19 size])

Leave a Comment

Previous post:

Next post: