As I start to add more packages and customizations to my emacs configuration, it would be a good idea to have a plan for organizing things to keep it manageable. Funnily enough, there is a package called use-package that seems like it will be useful in this endeavor, so let’s use it.
First, you can read more about use-package
at its Github repository, this reddit thread, or this blog post. The main advantages of use-package
for my purposes are:
- the
:ensure
keyword automatically installs packages (replaces myensure-package
function) - it helps centralize configuration related to each package
- it can defer executing code for packages which are only needed in certain modes
The last two are not such a concern yet, but will be useful in the future.
I have refactored the init.el
file from before. You can see the new contents below (with comments), or just download the raw file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
I got rid of ensure-package
and made some changes based on the Stack Overflow question here. It makes sense to me for updating packages to be manually invoked, so we can think of our process as: for a new system with no packages (and no package-archive-contents), we first fetch the list of packages, install use-package
, and use use-package
to install and configure our other packages; in normal use, our packages are already installed and use-package
configures them. When we want to add a package, just add (use-package <package> ...)
to our config file and let use-package
install it for us.
For upgrading packages, it may make sense to have a function to do everything necessary (I haven’t looking into what that would be) that I can invoke in one step. Alternatively, I could just nuke ~/.emacs.d/elpa/
— (not-so-)instant upgrade!