Modern Emacs package management with Cask and Pallet

I recently decided to retrain myself as a terminal Emacs user (I'm nostalgic for the '80s and my old glorious green and black terminal :P).

Emacs package management has looked pretty awkward for a long time, but it's better now: Pallet and Cask are a pretty good way to manage your .emacs package dependencies, if you pay some attention when setting them up.

But if you just install them without thinking about it, a mess may occur (happened to me ^^;).

So this is a guide to transition to Cask and pallet, while avoiding messing up your emacs configuration.

I have tried this on OS X, but it will likely work on most UNIX versions.

The procedure is slightly different, depending on which of these two cases is yours:

  • start from scratch with a clean emacs install
  • commit the packages you already have installed with package.el

Pre-requisites

  • emacs >= 24
  • python >= 2.6

Start from scratch

Cask

You'll need to install Cask first, there are a few options:

  • homebrew (Mac OS X)
  • just curl it
  • clone the repo
Homebrew
  1. $ brew update
  2. $ brew install cask

It will put cask.el somewhere, likely at /usr/local/share/emacs/site-lisp/cask/cask.el

Curl
$ curl -fsSL https://raw.githubusercontent.com/cask/cask/master/go | python

Remember where it put your cask.

Clone the repo

git clone https://github.com/cask/cask.git

Remember where you put the cask dir on your filesystem.

Setup Cask

Add cask to your PATH. Homebrew will do that for you, you'll have to do it by hand if you installed in an arbitrary directory without homebrew.

Add this to .emacs:

(require 'cask "<path to>/cask.el")
(cask-initialize)
Pallet

Now you need to install Pallet with Cask.
To do that:

$ emacs ~/.emacs.d/Cask

Running emacs will create a ~/.emacs.d/ directory, if it's not there already.

In the Cask file put:

(source melpa)

(depends-on "pallet")

You can also put more sources in:

(source melpa-stable)
(source gnu)

Now use the terminal at ~/.emacs.d/:

$ cask install

This will bootstrap cask and pallet. It will create a ~/.emacs.d/.cask/ directory containing all the packages you will install.

Now you can add:

(require 'pallet)
(pallet-mode t)

to your .emacs.

Restart your emacs, and from now on pallet-mode will be active: any time you install a package with M-x package-list-packages and similar, pallet will write it down in your Cask file and the files fill go under the .cask/ directory.

Save your packages to Cask

You have a working emacs configuration, and want to switch to Cask and pallet to maintain it.

Please follow all the steps, or it may end up borking your packages.

Install pallet

You need to install pallet first, through your package.el:

M-x package-install RET pallet RET

or also

M-x package-list-packages

find pallet, press i over it, and then x.

Setup pallet

Once installed:

M-x pallet-init

This will create ~/.emacs.d/Cask which should contain a list of the packages you have already installed.

M-x pallet-install

will copy your elpa dir to your .cask dir.

Remove package.el

Now you can get rid your ~/.emacs.d/elpa/ directory and any lines in your .emacs or init.el that setup sources for package.el or initialised it.

Setup pallet-mode

Add to your .emacs or equivalent:

(require 'cask "<path-to-cask>/cask.el")
(cask-initialize)
(require 'pallet)
(pallet-mode t)

you can also get rid of any package.el code in your .emacs, Cask+pallet will handle that now.

Gotchas

Pallet-mode will save any packages you install to your cask file. If it's not enabled you'll lose those packages, they won't be included in any M-x pallet-update or other pallet commands you'll do later.

Check if pallet-mode is active with M-x pallet-mode. That will switch it on and off, so remember to turn it back on if you switched it off.

Conclusion

Hopefully this worked for you, and you can enjoy the convenience of Cask+pallet, while avoiding having to reconstruct your dependency list.