Locating a bad expression in Emacs and Clojure
I sometimes make the mistake of modifying many functions in a module before I attempt executing or compiling the entire file again and am met with an error like:
Can't have more than 1 variadic overload [Thrown class java.lang.Exception]
Finding the source of this in a large file full of functions can be difficult.
There is a trick you can use in Emacs to make this simpler though. By using a simple keyboard macro you can step through all of the expressions in a buffer and evaluate each one in turn until you find the expression with the error in it.
The steps are as follows:
- Jump to the top of your buffer:
- Start recording a macro by typing:
- Move forward a single sexpression by typing:
- Evaluate that expression by typing:
- End the macro by typing:
If it was in the first expression then you’re done. If it’s not, then check the next one by typing
C-x e, to continue checking you can then keep pressing just
e until you’ve found the offending code.