I see with lein it’s possible with :injections like here. I found
thesetwo posts where people get effectively the same set up with deps.edn, with clojure’s basic repl. I’m using conjure on vim which uses nrepl. Nrepl’s documentation explains how to do this with leiningen (:init key in :repl-options in project.clj), but I can’t figure how to set this up without lein (I’m on an old computer where clj starts much faster than lein). Anyone know how to set this up? Or just general tips or tools for debugging clojure are also welcome
One option is you can put the requires in your user namespace, which is loaded when the repl is started and store the referred vars in vars in the user namespace.
(require [debux.core :as debux])
(def dbg debug/dbg)
user/dbg ;; refers to debug.core/dbg
There may be other (better?) ways to do this as well, but this works.
Or just general tips or tools for debugging clojure are also welcome
I like to use inline defs when debugging, as you can easily save values from the running code for experimentation at your leisure in the repl. Using inline defs with the same name as local bindings can be very helpful. See more info here: Inline def: an effective* debugging technique for Clojure.
thanks! I didn’t know about user.clj. For convenience I’d like to not have to make a separate dev/user.clj with that in every project but just have it present anytime I run nrepl. I found these instructions: How are `user.clj` files loaded? - #3 by jlesquembre
and made it work by putting in ~/.clojure/deps.edn:
It doesn’t work with just (def dbg debux.core/dbg) as it’s a macro and gives a compiler error about not being able to take the value of a macro. with this clj on startup says: WARNING: Use of :paths external to the project has been deprecated, please remove: /home/user/.clojure
So it seems making a global user.clj is not encouraged or this isn’t the way to do it.
I’m actually not really worried about getting this working properly anymore cause I switched now to emacs for clojure coding at least, cider is just more mature than what vim has at the moment. And it’s debugger and inspector and stuff takes care of most of the use for those helper macros. I was pleasantly surprised it just took like a day to set up and get somewhat comfortable with doom emacs, it’s closer to vim than any other “vim mode” outside of vim I’ve seen.
Inline def is a nice simple debugging technique for clojure! If you do it a lot def’ing large numbers of local variables maybe you’d like that scope capture library, it’s basically a macro for automating the inline defs, you just put spy at some point and it saves all the local variables at that point, and then can do defsc to def them all, which i bound a key to to make it more convenient
Glad you found something that works for you! I’m familiar with scope-capture but haven’t tried it. There’s also snitch. “It is inline-defs on steroids.” I should try one or both of those at some point.