I'm trying to setup my environment based on EMACS+CIDER for clojure development, btw I got stuck with functionality of hot-reloading I've seen in this video at 6:20-6:25 timing. http://www.parens-of-the-dead.com/e1.html
Actually, author is not using feature like RING/wrap-reload, but his code reloads in REPL after each buffer saving in emacs. I guess I have same libraries on local machine (cider, cider-nrepl, clj-refactor, clojure-mode), but my local installation is not working as shown, it requires calling (reset) function every time in REPL.
P.S. I can roughly get same behaviour by this code in EMACS, but I don't want to use hacks like that:
(defun my-clojure-reset ()
"Reload clojure once file were saved."
(when
(s-ends-with? "clj" (buffer-file-name))
(cider-interactive-eval "(do (ns user) (reset))")))
(add-hook 'after-save-hook 'my-clojure-reset)
Any suggestions how to implement code reloading on file saved event in EMACS+CIDER?
You can do this kind of behavior with the follow emacs-lisp in your start up file:
(add-hook 'cider-mode-hook
(lambda ()
(add-hook 'after-save-hook 'cider-load-buffer nil 'make-it-local)))
This adds a hook on only buffers running cider-mode (i.e. clojure files when you've done cider-jack-in) which after saving, will call cider-load-buffer, which will evaluate the contents of your file in the cider connection. The 'make-it-local value just makes it so this hook only gets applied to local buffers, otherwise this hook would load for all modes after you opened something in cider-mode the first time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With