I use Emacs as my primary text editor and I use it to edit commit messages for Git. I almost never use the -m option with git commit. Since I have a fairly customised Emacs configuration based around Sam Aaron’s Emacs Live, this means that for every commit, there is a visible delay for Emacs to start up for the commit message. I was looking for ways to reduce this and figured out that running Emacs in daemon mode and using emacsclient as the GIT_EDITOR would solve this.

Running an Emacs daemon at start up on Mac OS X

The recommended way of running an application at start up on Mac OS X is to use launchd. Launchd configurations are written as XML files created in ~/Library/LaunchAgents or /Library/LaunchAgents depending on whether the app needs to be run for the current user or for all users. Here is the plist file for Emacs at ~/Library/LaunchAgents/gnu.emacs.daemon.plist, taken from EmacsWiki:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
<plist version="1.0">
    <string>Gnu Emacs Daemon</string>
    <string>YOUR USER NAME</string>

This is loaded by running

sudo launchctl load -w ~/Library/LaunchAgents/gnu.emacs.daemon.plist

Using Emacs client as the editor

This is done by adding

export EDITOR="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient"
export GIT_EDITOR="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient"

to .zshrc or .bashrc.

This setup significantly reduces the Emacs startup time while committing changes.

If you have questions or comments about this blog post, you can get in touch with me on Twitter @sdqali.

If you liked this post, you'll also like...