Skip to content

Commit 71a8d67

Browse files
authored
Introduce cider-start-server command (#3555)
1 parent 782ed73 commit 71a8d67

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## master (unreleased)
44

5+
### New Features
6+
7+
- Introduce `cider-start-nrepl-server` which does the same as `cider-jack-in` but without trying to connect to the started
8+
nREPL server.
9+
510
### Changes
611

712
- Bump the injected `cider-nrepl` to [0.42.1](https://github.com/clojure-emacs/cider-nrepl/blob/v0.42.1/CHANGELOG.md#0421-2023-10-31).

cider.el

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,12 +1302,15 @@ nil."
13021302
(define-key map (kbd "j s") #'cider-jack-in-cljs)
13031303
(define-key map (kbd "j m") #'cider-jack-in-clj&cljs)
13041304
(define-key map (kbd "j u") #'cider-jack-in-universal)
1305+
(define-key map (kbd "j n") #'cider-start-nrepl-server)
13051306
(define-key map (kbd "C-j j") #'cider-jack-in-clj)
13061307
(define-key map (kbd "C-j s") #'cider-jack-in-cljs)
1308+
(define-key map (kbd "C-j n") #'cider-start-nrepl-server)
13071309
(define-key map (kbd "C-j m") #'cider-jack-in-clj&cljs)
13081310
(define-key map (kbd "C-j C-j") #'cider-jack-in-clj)
13091311
(define-key map (kbd "C-j C-s") #'cider-jack-in-cljs)
13101312
(define-key map (kbd "C-j C-m") #'cider-jack-in-clj&cljs)
1313+
(define-key map (kbd "C-j C-n") #'cider-start-nrepl-server)
13111314
(define-key map (kbd "c j") #'cider-connect-clj)
13121315
(define-key map (kbd "c s") #'cider-connect-cljs)
13131316
(define-key map (kbd "c m") #'cider-connect-clj&cljs)
@@ -1326,24 +1329,49 @@ nil."
13261329
map)
13271330
"CIDER jack-in and connect keymap.")
13281331

1332+
(defun cider--start-nrepl-server (params &optional on-port-callback)
1333+
"Starts an nrepl server and passes the callback to it.
1334+
PARAMS is a plist optionally containing :project-dir and :jack-in-cmd.
1335+
ON-PORT-CALLBACK is a function of one argument (server buffer)
1336+
which is called by the process filter once the port of the connection has
1337+
been determined. Can be nil."
1338+
(nrepl-start-server-process
1339+
(plist-get params :project-dir)
1340+
(plist-get params :jack-in-cmd)
1341+
on-port-callback))
1342+
1343+
1344+
(defun cider--update-params (params)
1345+
"Completes the passed in PARAMS from user input.
1346+
Updates :project-dir, confirmation for existing session and :jack-in-cmd."
1347+
(thread-first
1348+
params
1349+
(cider--update-project-dir)
1350+
(cider--check-existing-session)
1351+
(cider--update-jack-in-cmd)))
1352+
13291353
;;;###autoload
13301354
(defun cider-jack-in-clj (params)
13311355
"Start an nREPL server for the current project and connect to it.
13321356
PARAMS is a plist optionally containing :project-dir and :jack-in-cmd.
13331357
With the prefix argument, allow editing of the jack in command; with a
13341358
double prefix prompt for all these parameters."
13351359
(interactive "P")
1336-
(let ((params (thread-first
1337-
params
1338-
(cider--update-project-dir)
1339-
(cider--check-existing-session)
1340-
(cider--update-jack-in-cmd))))
1341-
(nrepl-start-server-process
1342-
(plist-get params :project-dir)
1343-
(plist-get params :jack-in-cmd)
1360+
(let ((params (cider--update-params params)))
1361+
(cider--start-nrepl-server
1362+
params
13441363
(lambda (server-buffer)
13451364
(cider-connect-sibling-clj params server-buffer)))))
13461365

1366+
1367+
(defun cider-start-nrepl-server (params)
1368+
"Start an nREPL server for the current project, but don't connect to it.
1369+
PARAMS is a plist optionally containing :project-dir and :jack-in-cmd.
1370+
With the prefix argument, allow editing of the start server in command; with a
1371+
double prefix prompt for all these parameters."
1372+
(interactive "P")
1373+
(cider--start-nrepl-server (cider--update-params params)))
1374+
13471375
;;;###autoload
13481376
(defun cider-jack-in-cljs (params)
13491377
"Start an nREPL server for the current project and connect to it.

doc/modules/ROOT/pages/basics/up_and_running.adoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,18 @@ Here is an example Nbb Jack-In command, providing a custom `:jack-in-cmd`.
267267
(cider-jack-in-clj '(:jack-in-cmd "nbb nrepl-server")))
268268
----
269269

270+
==== Starting nREPL server without trying to connect to it ====
271+
272+
In some situations, it might be useful to only start a nREPL server process, without
273+
connecting to it. This can support complex setups
274+
for which CIDER cannot reliably detect to which server/port to connect, and
275+
would therefore fail.
276+
This assumes that the user will execute a `cider-connect` command manually afterwards,
277+
specifying host/port.
278+
279+
For this scenario, the `cider-start-nrepl-server` kbd:[j n] command is offered, which optionally
280+
takes the same parameters as `cider-jack-in`.
281+
270282

271283
== Connect to a Running nREPL Server
272284

0 commit comments

Comments
 (0)