We have an admin option to start (& stop) a repl server inside our
application so we can nrepl from Emacs into any live running instance
and evaluate code in that live context - great for debugging "only
happens on production" issues as well as making interactive
development and debugging locally much easier.

We use code like this:

(ns ...
  (:require ...
    [clojure.tools.nrepl.server :refer [start-server stop-server]]))

(def ^:private nrepl-server (atom nil))

(defn start-nrepl
  "If a nrepl port is defined for this environment, attempt to start a
   nrepl server on that port. Will throw an exception if it's already
   running on that port etc."
  ([]
     (start-nrepl (:nrepl-port @my-settings)))
  ([port]
     (reset! nrepl-server (start-server :port port))))

(defn stop-nrepl
  "Attempt to stop the currently active nrepl server."
  []
  (stop-server @nrepl-server))

On Mon, Jun 10, 2013 at 4:49 AM, Antonio Terreno
<antonio.terr...@gmail.com> wrote:
> Not sure how it's obvious or granted as I am pretty new to the clojure
> world but I am really loving having a repl namespace in our projects,
> compiling the repl file kicks in the (web) application in the same way
> it gets kicked in from the -main.
>
> Server goes up, any time we C-x X-s a file we also compile it and
> changes are picked up.
>
> As Jay said, anything special - it just works: something I missed in
> most of the IDEs I've used in the past.
>
> On Mon, Jun 10, 2013 at 12:32 PM, Jay Fields <j...@jayfields.com> wrote:
>> 2013/6/8 Jay Fields <j...@jayfields.com>
>>
>>>> My favorite recent addition - I can run my app from within emacs,
>>>> allowing me to change my app with a simple C-x C-e and see my changes
>>>> immediately in the running app (no restart, refresh or reload necessary).
>>>
>>>
>>> Would you mind to extend on that ?
>>>
>>> How is this done, exactly ?
>>
>>
>> Sure. I assume you have some top level function that you call to 'start'
>> your application. If you ever use 'lein run', then I'm probably talking
>> about the -main function in whatever namespace you specify as your main
>> namespace (e.g.
>> https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L130)
>>
>> Let's pretend your main namespace is my-main.
>>
>> First I start a new nrepl. M-x nrepl-jack-in
>> Then I open my-main in a new buffer. C-x C-f my_main.clj
>> (If there isn't one already) I put a comment at the bottom of the namespace.
>> c-tab
>> In the comment, I put (-main) and, after the parenthesis, I C-x C-e to
>> evaluate the previous form.
>>
>> At that point my app is running from within Emacs. Now I can go to any form
>> in the codebase and C-x C-e, which will evaluate the form in my running
>> nrepl, which is also running my app. Let's say I have some function that's
>> being called every minute and printing the time via println. I can go to
>> that function and change the format of the output, C-x C-e the entire
>> function, and the next println will be in my new format. There are a few
>> gotchas (it's problematic to redef a defmulti, once you've passed a f in as
>> a parameter you can't redef it), but for the 95% case I don't need to do
>> anything special - it just works.
>>
>> Cheers, Jay
>>
>> --
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with your
>> first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to