Endless Parentheses

Concise ramblings on Emacs productivity.

Cider-debug, a visual, interactive, debugger for Clojure

Over the last couple of weeks, I’ve been working on a Clojure debugger for Cider that is strongly inspired by Edebug. Stepping trough code of any form and injecting values into running code are the features available in this first release.

This little project started shortly after I my first practical delve into Clojure. I was impressed at how well Cider integrated Clojure into Emacs, it almost felt like writing Elisp! When Bozhidar mentioned that they were in need of a debugger, I figured that would be as a good a chance as any to practice some Clojure. Since my praise for Edebug is no secret around here, it should come as no surprise that I’d model cider-debug after it (albeit, a bit more limited).

I should also mention the clj-debugger plugin, which we don’t use anymore but was a great help while writing this feature.

Usage

First, if you’re still using cider 0.8, you’ll need to upgrade to the latest stable version cider 0.9, which is available on Melpa. Additionally, ensure your “~/.lein/profiles.clj” file is consistent with that.

{:user {:plugins [[cider/cider-nrepl "0.9.0"]]}}

Once that is done, using cider-debug could hardly be more straightforward. Just instrument an expression with C-u C-M-x, and you’ll be taken through the code step-by-step. There, you can move on with n, quit with q, or inject values with i. Note that if you instrument a defn the debugger will not start immediately, instead, you’ll be taken to the debugger each time the function is executed.

This sort of thing is easier to explain with a gif.

cider-debug.gif

We’d very much appreciate the feedback of any Clojurists out there. File an issue if you spot something, or just share your thoughts with us on Twitter or Gitter.

Update <2015-06-16 Tue>

That screen-cast above is a little outdated now. Since it was recorded, the debugger has acquired even more features:

  • listing local variables,
  • evaluating code in the current lexical scope,
  • injecting values into the code,
  • a move-out command similar to Edebug.

I’ll make another post eventually, but it’s perfectly intuitive and easy to use. So give it a try yourself if you use cider.

Tags: programming, debugging, clojure, emacs

Say thanks on Gratipay
comments powered by Disqus