neorepl 0.6 is out! In the 0.5 post I wrote that 0.6 would be about getting neorepl to more people, with Clojars, Homebrew, Windows and a documentation site. Then I started looking at what the REPL does when your code blows up, and, well, you can guess how that went. The site happened, and neorepl installs as a Clojure CLI tool now, but most of this release is about errors: what they mean, how to fix them, and a debugger for the ones that don’t give up easily. Hence the tagline, “Errors made easy (to fix)”.

From error to fix

Fixing errors in neorepl

Every Clojure programmer has stared at “Unable to resolve symbol” more times than they’d care to admit, and nine times out of ten the fix is a missing require or a typo. The REPL knows that much, so now it tells you. When code names something that isn’t there, neorepl marks the name in what you typed and lists what could fix it, numbered for ,fix:

user=> (join ", " ["a" "b"])
Syntax error compiling at (REPL:1:1).
Unable to resolve symbol: join in this context
  (join ", " ["a" "b"])
   ^^^^
  ,fix 1  (require '[clojure.set :refer [join]])
  ,fix 2  (require '[clojure.string :refer [join]])
user=> ,fix 2
nil
"a, b"

The requires and imports come from cider-nrepl’s resolve-missing (or babashka 1.13.230’s), and the fixes for typos come from completion. A fix only ever runs when you ask for it. I stole the idea from Smalltalk’s debugger, which offers to create the method you just called, and from Factor and MIT Scheme, which number their restarts, but I drew the line at fixing things behind your back.

The rest of the errors got some love too:

  • An ex-info’s data shows up as fields under its message, rather than as one long map you have to squint at.
  • A function called with the wrong number of arguments gets its arglists.
  • The commonest errors get a line on what they tend to mean. A NullPointerException from clojure.lang.Numbers is arithmetic getting nil, for instance.
  • You get the line of your own code the error came from, rather than the first of fifty frames of clojure.lang.
  • The first few errors point out ,pst and ,stacktrace, and the hints setting turns all of this off, if you’d rather figure things out the hard way.

Coding agents make even more typos than I do, so neorepl eval and the MCP eval tool follow such an error with the same fixes. With --format edn or json (and in the tool’s structured content) they come as suggestions, each with the code to evaluate for it.

A debugger, at last

Stepping through a function in neorepl

CIDER’s debugger has been one of my favourite CIDER features ever since Artur Malabarba wrote it, back in 2015, and it’s the first thing I missed in neorepl. Not anymore! ,break instruments a function with cider-nrepl’s debugger, so it stops at each step, and at each breakpoint you get CIDER’s keys: n for the next step, i and o to step in and out, c to go on, l for the locals, e to evaluate something with them, j to return a value of your choosing, p to inspect, q to quit and ? for everything else.

A few more ways in:

  • ,break-at FILE LINE stops at a line of a file, which also works for a method, a function inside a def or a line in the middle of a long function. ,breaks lists what stops, and ,unbreak and ,unbreak-at take it out.
  • #dbg and #break typed in front of a form work as they do in CIDER.
  • After an error, ,debug runs the input that failed again and stops right where it throws, with the locals, so you can poke around or j your way past it.
  • A breakpoint on a thread of its own, like an HTTP handler’s, waits with a note above the prompt until you get to it with ,stop.
  • When the REPL exits, everything it instrumented runs as normal again, so you don’t leave breakpoints behind that no one will ever answer.

All of this works with babashka 1.13.230 as well.

Bring your own editor

I doubt many of you write non-trivial amounts of code straight into a REPL, so here’s what all of this looks like next to an editor:

Neovim and neorepl, side by side

That’s Neovim, with neorepl in a :terminal split under the code, and the setup from doc/editors.md, which is a few dozen lines of Lua and no plugin. The editor and the REPL share a server, so whatever one of them evaluates, the other sees. The receipt in the REPL looks suspiciously round, so ,break format-cents and a few steps show (rem cents 10) coming back with 0. The fix in the buffer is one character, ,ee evaluates the function at the cursor (without even saving the file), and back in the REPL the receipt finally adds up.

The way I’d split the work between them:

  • The editor evaluates things and loads files, the REPL runs them, and when something’s off, the REPL is where you poke at it, with the inspector, the tests, the stack traces and now the debugger.
  • ,break-at FILE LINE is handy here, as you can put the line your cursor’s on in the editor straight into it.
  • Going the other way, ,edit NAME in the REPL opens a definition in your $EDITOR.

The doc has this split too, and the same setup for Emacs, where C-M-x and C-c C-r evaluate the form at point and the region from clojure-mode, no CIDER required, and for Helix. Any terminal next to the editor will do for the REPL, if you’d rather keep it out of the editor.

So, does it feel like CIDER yet?

When I announced neorepl, a lot of people didn’t understand why we needed one more terminal REPL for nREPL. Back then I said my vision was an alternative to REPLy with a CIDER-like experience in your terminal (and a good CLI for agents to lean on, if you’re into AI engineering these days). The first version of neorepl didn’t feel much like CIDER, but I hope you’ll agree that things are looking way better in this regard now. Here’s where neorepl stands on CIDER’s major features, and what each of them needs on the server:

  With cider-nrepl nREPL alone In ClojureScript
Completion, arglists as you type yes yes, with nREPL 0.8 or later yes
,doc, ,source, ,where yes yes yes
,apropos yes yes Clojure’s vars only
,macroexpand yes yes yes
Errors, ,pst, ,stacktrace yes yes the message, without JavaScript frames
,fix and what an error says past its message yes, requires and imports with 0.64 or later typos only no, ClojureScript only warns
,inspect yes no the value, read back as data
,test yes the namespaces you name yes
,retest yes no yes
,reload yes, and what changed the namespaces you name Clojure’s only
,autoreload yes no no
,break, ,break-at, ,debug yes no no
,trace, ,profile yes no no
,refs, ,deps yes no no
,ns and its browser yes yes yes
,spec yes yes Clojure’s specs only
,tap yes, 0.64 or later no no

Like CIDER, neorepl gets the most out of cider-nrepl, which jack-in adds for you, and the ClojureScript column assumes it’s there, through piggieback or shadow-cljs. babashka’s server, 1.13.230 or later, does everything in the first column but ,refs, ,deps, reloading what changed and ,tap. The README has the same table.

Making the neighbours better, round four

  • babashka’s CIDER ops now come from cider-nrepl’s own middleware, which gave bb 1.13.230 the debugger, resolve-missing, apropos, macroexpand, the profiler and quite a bit more. I did that one myself, so it’s my fault if something’s off there.
  • neorepl’s jack-in brings cider-nrepl 0.64.1, which fixed a couple of problems with reloading that neorepl used to work around.
  • I filed a couple of cider-nrepl issues the debugger and the tests turned up: a breakpoint waits forever once the client that started the debugger is gone, and tests compiled before the first test op report forms instead of values.
  • The nREPL fixes are still waiting for the next nREPL release, and the piggieback changes are still in review.

Smaller things

  • neorepl installs as a Clojure CLI tool, straight from git, with clojure -Ttools install-latest :lib io.github.nrepl/neorepl :as neorepl, and every command is a function of the tool, as in clojure -Tneorepl repl.
  • ,apropos, neorepl apropos and the namespace browser leave out the namespaces of nREPL, cider-nrepl and its libraries, which were mostly noise. --tooling and the tooling setting bring them back.
  • ,apropos fits what it lists to your terminal, and so does the profile summary.
  • Locations in where, refs, deps and check are relative to the directory you’re in, when they’re in it.
  • Ctrl-C stops code that refuses to stop on JDK 20 and later, in the servers neorepl server starts.
  • Each form you paste or evaluate with eval -f gets its own line and column, so errors in the second form no longer point somewhere above it.

neorepl also has a site now, where you can see all of the above in action, if you’d rather not take my word for it.

What’s next

Clojars, an uberjar and Homebrew are still at the top of my list, along with proper Windows support and the frames of ClojureScript errors (which have been “next” since 0.2, I know). After that comes 1.0, where the CLI’s exit codes, its edn and JSON output and the MCP tools become a contract I promise to keep.

Try it

$ bbin install io.github.nrepl/neorepl
$ cd my-project
$ neorepl

The CHANGELOG has everything I skipped here, and the README has the details. Please keep the issues and ideas coming!

That’s all I have for you today. With 0.6 out, I feel we’re pretty close to a “feature-complete” 1.0, and I hope we’ll get there in the months to come. Keep hacking!