bhauman / rebel-readline

Terminal readline library for Clojure dialects
Eclipse Public License 1.0
680 stars 37 forks source link

Auto Reload #169

Closed viebel closed 6 years ago

viebel commented 6 years ago

rebel-readline is awesome. Is there a way to auto reload a namespace every time a source file changes (without having to re-require the namespace)?

bhauman commented 6 years ago

You can create a function to do this for you in your user.clj file.

Use hawk to watch the directory that you want: https://github.com/wkf/hawk Extra Credit: handle load time exceptions and format the errors nicely and print them out.

Extra Extra Credit: make a library out of it

bhauman commented 6 years ago

keep in mind the exception formats are going to change in the next release of Clojure

bhauman commented 6 years ago

Also look at tools.namespace https://github.com/clojure/tools.namespace

viebel commented 6 years ago

Thanks for the tip @bhauman.

I ended up writing this piece of code in my user.clj:

(hawk/watch! [{:paths ["src/calculator"]
               :handler (fn [ctx e]
                          (future
                            (repl/refresh)))}])
  1. For some reason, I get an exception if I call (repl/refresh) not inside a future.
    java.lang.IllegalStateException: Can't change/establish root binding of: *ns* with set
  2. Would it make sense to try having a user.clj that is common to all my clojure projects or should I simply replicate it to each one of my clojure projects?