Emacs Initialization, Organization, and Configuration

A quality developer is constantly on the lookout for a quality tool. With a bit of poetic license on a phrase coined by Sackman, Erikson, and Grant:

There are order-of-magnitude differences among programming tools.

Although there are a number of tools in my belt, Emacs is my primary swiss army knife / operating system. I use Emacs for editing Python, Javascript, Lisp, Scala, Java, HTML, CSS, Markdown, and LaTeX. I use it for managing git repositories. It’s my psychologist and my blog editor.

Much like a gearhead can spend weeks, months, and years assembling and kitting their dream car, the Emacs user will spend countless hours extending and optimizing their configuration file. Truth be told it is a cathartic process akin to cleaning the garage.

I was introduced to Emacs by Michael Haimes. Back in those days my customization files were a tangled mess of Christmas lights and headphone wires. I toyed with a number of folder structures and even sat down with Kyle Wild of Keen IO to compare his workflows using vim before ultimately landing on a layout proposed by magnars of Emacsrocks fame.

You can find my entire .emacs.d folder on Github. It works on Mac OS, Windows, and Linux (without any external dependencies) making it a snap to put the entire folder into Dropbox to share it across machines.

Here are a few of my favorite bits of Elisp, lovingly collected and refined over decades.

init.el

The init.el file is where the magic begins. Tracing through this file is a good place to start when investigating Emacs configurations.

I like to start Emacs once when my computer starts and keep it running until the computer shuts down. This seriously reduces the amount of load time experienced when opening files. You can do the same by starting the Emacs server and then adding

alias emacs='emacsclient'

to your shell configuration file. There is also a handy bit to ensure that all your .el files are compiled to .elc when quitting the program which will make startup faster on the next load.

MELPA

MELPA, the Emacs Lisp Package Archive, is one of the best places to find packages and keep them up to date. You can make sure all your packages are running the latest version with this snippet.

My favorite packages (in alphabetical order) are:

  • ace-jump - move to any position in the buffer with 3 key presses.
  • browse-on-github - open any file from Emacs on Github.
  • change-inner - gives access to vim’s ci code for replacing words “within quotes” or (within parens).
  • expand-region - expand the current region by semantic units.
  • edit-server - adds an “edit in Emacs” button to text boxes in the browser.
  • find-file-in-project - find file using autocomplete on file name (very similar to Github’s ’t’ feature and highly configurable for different file types)
  • flycheck - my go-to library for linting and checking Python (using pylint), Javascript (using JSlint), and more.
  • gist - post snippets from Emacs right to Github gitsts.
  • js2-mode - Javascript editing major mode. See my custom indentation using Espresso.
  • magit - manage git repositories right from Emacs. Works great with git-commit-mode, gitconfig-mode, and gitignore-mode.
  • malabar - A replacement for many of the useful features for Java editing in Eclipse (auto-compilation, jump-to-definition, refactoring, etc.)

Happy hacking!