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:

boxquote.el:
	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:

.el.elc:
	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.

Comments

  1. SonOfLilit

    Those are some great ideas that you're sharing, especially the use of a Makefile.

    Thanks :)

    SonOfLilit, 17 March 2008

  2. berat

    I compiled this file with my matlab.el how can i work matlab.el

    berat, 23 November 2009

  3. Using a Makefile to keep track of .el files and automatically download/byte compile them is genius. Thanks for sharing.

    mattc, 13 December 2009

  4. Laurent

    Excellent post, thank you very much!

    Laurent, 15 September 2010

  5. Very clever. Thank you very much!

    Jesús Gómez, 29 October 2010

Add a comment

Posting...