Emacs for Mac OS X from Terminal

01 Feb 2012

Emacs for Mac OS X is a no nonsense build of GNU Emacs as a universal binary for OS X. I've found it easy to integrate into my everyday text editing needs bar one instance, editting text files from the command line.

Enabling this workflow involves two steps.

First, Emacs needs to run in an edit server or daemon mode. This can be done three ways:

At launch: command line argument

--daemon

During initialization: add to ~/.emacs

(server-start)

After running: extended command

M-x server-start   

The easiest for the .app package is to edit the init file.

Second, requests to edit files need to go through the emacsclient application. A default emacsclient is installed with OS X, but we need to access the emacsclient within the Emacs for Mac OS X package. A symlink could be created in the OS X package location, but what I found easiest is to add this alias to my ~/.profile.

alias ec="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n"

The -n option does not wait for the Emacs server instance to return.

Now all text editing can be handled from a running Emacs like this:

$> ec filename