Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct way to use emacs/cider while developing a compojure/ring-based application?

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.

like image 614
Igor Chubin Avatar asked Jun 13 '14 18:06

Igor Chubin


2 Answers

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.

like image 180
deadghost Avatar answered Oct 26 '22 06:10

deadghost


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.


M-x cider-jack-in (or C-c M-j)

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).


M-x cider-connect

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).

like image 2
Malabarba Avatar answered Oct 26 '22 04:10

Malabarba