I have dozens of files from various corners of the Internet in my ~/.emacs.d/lisp/
directory. I’ve tried to keep the important ones up to date, but I’ve never done a very good job of it. The ones that are old and outdated are the lucky ones. Most of them are so old that I don’t even use them anymore.
Emacs now has a rather nice package manager called ELPA, and I started using it over the summer. Converting my existing configuration files has been a bit painful, and the apparent gains from the effort have been pretty small. I’ve only converted a very small number of my configuration files because of this.
My problem with ELPA
My Emacs configuration is pretty well organized. I’ve been using my-site-start to help manage my configuration since 2009. It is very simple, and it works a lot like the SysV init system. It automatically executes all the files in my ~/.emacs.d/site-start.d
directory. I try to keep all the configuration for each individual package in its own file. That makes it easy to quickly remove configurations that I don’t need.
Most of these files are very simple and quite similar. They usually have a require
statement at the top followed by one or more setq
. Some contain key binding assignments, but I mostly keep those to a single file.
1 2 3 4 |
|
I assumed that I would be able to reinstall my existing packages using ELPA, and my existing configuration files would just continue to work. The reality wasn’t quite that simple. My understanding might not be entirely accurate here, but it shouldn’t be too far from reality.
The packages installed by ELPA aren’t available until after Emacs is completely finished starting up. This means that all of those require
statements become errors. That isn’t a problem on its own, but this also means that any call to functions within these packages also becomes an error. At this point, that call to the global-git-gutter-mode
function will fail.
I was able to work around this by setting package-enable-at-startup
to nil
. This seemed like a bit of a kludge. I’m pretty sure this means that I now have to require
every package I install.
John Wiegley’s use-package
I found John Wiegley’s use-package last week, and I am very pleased with it. It manages to solve all my issues with ELPA, and it sure looks like it is going to lead me towards a much cleaner Emacs configuration.
1 2 3 4 5 6 |
|
I’ve started my journey the lazy way. I replaced all my require
calls with use-package calls. Then I just wrapped up my existing code and stuffed it into the use-package’s :init
section. This was just enough to eliminate my reliance on setting package-enable-at-startup
to nil
.
I’ve only just scratched the surface of use-package. It also has options for the configuration of key bindings and for populating your auto-mode-alist
.
I have a feeling that I’m going to be slowly rewriting all of my Emacs Lisp files over the next few weeks!