Reducing Emacs startup time while committing

Tue, Jan 22, 2013

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/"
export GIT_EDITOR="/Applications/"

to .zshrc or .bashrc.

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