Fork me on GitHub

Is there a way to bind a key combo to send a piece of code to the REPL? I am developing a pedestal web service and it’s becoming a bit tiresome to navigate to the Rich comment block where my (restart-server) call is every time I make some changes… :S




Thank you very much! Works perfect.


@U4P4NREBY it should not be necessary to call (restart-server) in pedestal. This is our dev-server:

(defn- route-fn
  "Use the deref of the namespace to get hot-reloaded namespaces."
    (deref #'tech.matterindustries.titan.ion.api-gateway.service-handler/routes)))

(def interceptors
  (-> service-handler/service
    ; Get ion provider out of there
    (dissoc ::http/chain-provider)
    ; hot-reloaded-fn ftw!
    (assoc ::http/routes route-fn)
      {::http/type  :jetty
       ::http/port  7001
       ::http/join? false})


Now everytime the route is hit, whatever code that was eval’ed in the REPL will get executed


@U9E8C7QRJ Interesting. Can you explain a little how it works? I am currently working with something like

(defn start []
  (http/start (http/create-server service-map)))
but I don’t see any servers started in your snippet so I’m unsure what to do with it…?


@U4P4NREBY interceptors is the service-map in your start The important line that you need in your service map while developing, would be (assoc ::http/routes route-fn) . That route-fn dynamically expands the routes on every call - so point it to your routes


Ah, I see. So #'tech.matterindustries.titan.ion.api-gateway.service-handler/routes is just a regular var that you’re deref’ing?


Yes, the app routing table


Ok. Thanks! I think I'm just not familiar with the syntax here. Never deref'ed a var before. Anyway, I guess it wouldn't work without the deref since yo made it this way. I'm just not sure why.


I don’t know if this would be a cursive feature or nrepl feature, but how could I specify a snippet of code I want to run every time I reload a namespace while connected to REPL?

Jakub Holý (HolyJak)20:10:38

Set an environment variable / system property when starting REPL, have top-level expression wrapped in (if my-env-var-is-set...)?


I should have said reload any namespace instead of a namespace