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

3

8

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.

Cupellation answered 13/6, 2014 at 18:32 Comment(0)
R
2

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.

Ruminate answered 15/6, 2014 at 3:40 Comment(1)
To be a little bit more specific: when you have the REPL open in Emacs that is connected to your running headless jetty/ring application and you evaluate a function or re-evaluate an entire buffer or load a file, these evaluations will be directly visible in the running application.Seafood
A
2

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

Agentive answered 17/10, 2017 at 23:31 Comment(1)
This answer helped, for cider-connect make sure you run with a nrepl option. For ring you need this option :nrepl {:start? true :port 9000}Snobbish
B
0

A bit late to the party. But as I have just to deal with the same issue and found this unanswered question. The answer could be found at: lein ring server with nrepl doesn't honour cider-nrepl

Basically, use the plugin version 0.9.2 of lein-ring and add to the :ring configuration on project.clj :nrepl {:start? true} and it works

Bobbee answered 7/11, 2015 at 18:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.