September 11, 2015

Emacs Cider and Boot

I wrote my first boot task yesterday. I'm hoping it helps a little to manage all the different pieces needed to work together in order to use Emacs as a clojure development environment.

The underlying pain is that in order have nrepl and cider both happily working together, the clojure packages and the elisp packages should be using the same versions.

Cider dependencies can be added to each individual clojure project. But it's really not very good practice because it can mess up developers who don't use emacs.

The solution is to configure the cider related dependencies (cider-repl and clj-refactor) inside a "profile.clj" that exists in your home directory.

That works pretty well, but I always forget about the profile.clj(!), and then, whenever I update cider, I spend a bunch of time tracking down how it's all set up.

I'd rather not have to think about it!

So, to help make this a little easier, I wrote my first boot task called boot-cider. It tries to figure out which versions of the cider and clj-refactor elisp packages are installed, and then does the work of configuring your nRepl environment to match. Here's how to use it:

 (merge-env!
  :dependencies '[[upgradingdave/boot-dave "0.1.0"]])
 	
 (require '[upgradingdave.boot-cider :refer [cider]])

Then, you can do this from the command line:

boot cider repl

Note that you have to run cider before the repl boot task to give cider a chance to wire everything up.

It's also convenient to create a nice shortcut task like this.

(deftask cider-repl [] (comp (cider) (repl)))

And there ya go! Boot and cider and nrepl all happy together ... except for when they aren't, but that's for the next blog post ;-)

Tags: clojure boot-clj tech