Fork me on GitHub
#nrepl
<
2021-09-25
>
Luis Santos18:09:21

Hi everyone, I'm currently using nrepl with cider and would like to run a clojure function every time a s-exp is evaluated. I'm working on a cljfx project and I'm trying to get my scene reloaded every time a function is re-evaluated. Does anyone knows where to start? Do I need to build a middleware or is there any to add a hook to my user.clj? Thanks

dominicm20:09:09

@luis559 a hook is what you're after I think!

Luis Santos20:09:17

Thanks @U09LZR36F. What hook should I use? Is it an emacs/cider hook or a nrepl client hook or cider-nrepl client hook? Sorry I'm new to the clojure ecosystem and I have to confess I don't know how all the pieces work.

dominicm21:09:17

Sorry, I was not 100% when I sent this. A middleware is what I meant to say facepalm

dominicm21:09:32

A good example to start from is probably https://github.com/RickMoynihan/nrebl.middleware which does something similar to what you want - running a function after evaluation.

dominicm21:09:36

Hmm, actually that doesn't work how I expected. Lemme see if I can find you a better example.

dominicm21:09:47

https://github.com/vvvvalvalval/scope-capture-nrepl is a pretty close example, but not quite what you're trying to do either. This middleware wraps eval/load-file so that when you call them, the code is wrapped by the library. But instead you just want to call the handler, then run your result, something like:

(let [result (apply handler args)]
  (reload-cljfx!)
  result)

Luis Santos09:09:40

Thanks @U09LZR36F. This sounds a great start point. I will have a look. thanks3