Easily installing third-party .el files

Last updated on .

There’s a remarkable amount of Emacs Lisp programs out there, and they do just about everything, from providing handy mail quoting utilities to providing an Emacs interface to IMDB and more! And while many such elisp hacks come bundled with Emacs, there are even more out there on the Internet, just waiting for you to try them out. The Emacs Lisp List and the EmacsWiki are both great resources for finding interesting and useful elisp.

So, you’ve gone and downloaded some elisp file (foo.el, say). Now, what do you do with it? Well, the community convetion on the matter is to toss .el files in, say, ~/elisp/ (an elisp directory in your home directory). Once you have such a directory you need to ensure that it’s present in Emacs’ load-path variable. This is typically done by adding something like this to your ~/.emacs file:

(add-to-list 'load-path "~/elisp")

Next, you’ll need to configure Emacs to load the new file. Most of the time, you should be able to add (require 'foo) to ~/.emacs (where foo means foo.el).

Simplify! Use install.el

That’s often all you have to do, but there are lots of exceptions. Fortunately, Stefan Monnier’s install.el handles the vast majority of elisp files you’ll run into, and is very easy to use itself. Install it by following my directions above. Now, whenever you’d like to install an elisp file, simply invoke the install-file command (via M-x install-file RET). That’s it!

Managing ~/elisp with Make

I never remember where I got all of these elisp files from, so I keep track of the download links in a Makefile in ~/elisp. Entries look like this:

	wget http://www.davep.org/emacs/boxquote.el

This way, I can always cd elisp ; make boxquote.el if I need to download boxquote.el.

Here’s a simple Make rule I have in ~/elisp/Makefile for byte-compiling Emacs Lisp files:

	emacs -q --no-site-file -batch \
		-eval "(add-to-list 'load-path \".\")" \
		-f batch-byte-compile $*.el

So, had I typed make boxquote.elc above, Make would have first downloaded boxquote.el and then byte-compiled it for me.