Clojure coding with emacs and cider

I am new to Clojure coding and have reviewed a number of articles to configure Emacs for development.
The setup itself works the way it was designed, but I started the server from a Cider session and completely killed Emacs when the code changed. Or I need to find a server process from a shell session and kill it from there. This is far from ideal.

clojure -getting-started / web.clj

(defn -main [& [port]]
  (let [port (Integer. (or port (env :port) 5000))]
    (jetty/run-jetty (site #'app) {:port port :join? false})))

Cider Session

clojure-getting-started.web> (defonce server (-main))

After starting the server, I will get the following error using the function (server):

1. Unhandled java.lang.ClassCastException
   org.eclipse.jetty.server.Server cannot be cast to clojure.lang.IFn


The error message makes sense, but how can I update my code base using only Emacs?
I suppose (and hope) that there is a better way than starting a shell session in Emacs and killing the process there ...

+4
3

, - , emacs. , , . , lein, . , , , . , i.e.

lein new compojure my-project

lein, dev.

src/my_project/handler.clj ring.middleware.reload, .

(ns my-project.handler
  (:require [compojure.core :refer :all]
            [compojure.route :as route]
            [ring.middleware.reload :refer [wrap-reload]]
            [ring.middleware.defaults :refer [wrap-defaults site-defaults]]))

(defroutes app-routes
  (GET "/" [] "Hello World")
  (route/not-found "Not Found"))

(def app
  (-> app-routes
      wrap-reload
      (wrap-defaults site-defaults)))

- . , - .

lein ring server

lein ring server-headless

, 3000. emacs . , project.clj. .

, , -. , repl.clj . , -

lein repl

repl, -

(start-server)

. emacs cider-jack-in cider-connect, , , , . , clojurescript, clojure + clojurescript. , .

, , . , /, .

+3

, :


(refresh) clojure.tools.namespace.repl:

Clojure, ns, .

https://github.com/clojure/tools.namespace#reloading-code-usage

user, REPL :

(ns user
  (:require [clojure.tools.namespace.repl :refer [refresh]]
            [clojure.repl :refer [doc source]]
            [clojure.pprint :refer [pprint pp]]
            [midje.repl :as midje]
            [clojure.stacktrace :as st]))

, <project root>/dev/user.clj, lein project.clj:

:profiles {:dev {:source-paths ["dev"]}}
0

Regarding ClassCastException - the server must be a 1 param function:

(defonce server (fn [request] (-main)))
0
source

All Articles