What is the correct workflow/pathway of usage of emacs/cider while developing a compojure/ring-based clojure application?
I feel that I can "attach" to my running compojure/ring-process, change its code, read/change its data, but I can't understand how do I do it right? What is the correct way?
What I do?
lein new compojure my-project
cd my-project
lein ring server-headless
The development server runs now. If I change files in the projects they will be automatically reloaded. That is good. But what I'd like to have is that I attach direct to the process and change its functions for example.
I understand that it is possible, but I can't understand how.
I don't know about correct but I'll throw in my 2 cents.
I start my ring project using immutant which starts a REPL at a specified port. I start cider with M-x cider
and connect to the previously specified port. From there I can modify things from the REPL.
I've also seen other people start jetty from inside the REPL though I've never tried this.
There are two main ways of doing what you want. None of them are specific to ring servers, or even to webservers, they'll apply to any Clojure Project.
Both of the methods below should give you a fully functional REPL, with complete control to redefine the functions in your running server, and full CIDER functionality (like being able to debug web-requests to the server).
As usually with CIDER, you can reload changed files with C-c C-k
, which will redefine any functions you've changed. There are plenty of other keys for more fine-tuned evaluations as well.
As documented on the manual this starts a process with your project and connects a REPL to it. This won't call any functions for you (CIDER doesn't do that), but you can easily start your webserver by calling the corresponding function in the REPL. If the function in question is the -main
function, you can do M-x cider-run
to call it (bind that to a key if you'd like).
Also as documented on the manual, you can start your webserver from the terminal like you normally would, and then call M-x cider-connect
to open a REPL in it. (This is what I used to do a while back).
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