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: EditorClient.zip (20.98 KB)

{ 2 comments… read them below or add one }

Bar April 28, 2010 at 3:06 pm

Hey, this is a great idea. Did you ever end up improving it? Will it work on Snow Leopard? I don’t see any download links, so I’m guessing it turned out to be a less-than-great idea.

Ivan Andrus June 5, 2010 at 1:54 pm

Thanks! This is great. I wanted to do something like this a while ago, but I don’t know enough about apple events.

@Bar: The code can be found at http://github.com/robtillotson/EditorClient

Leave a Comment

Previous post:

Next post: