@@ -230,6 +230,27 @@ By default we favor the project-specific shadow-cljs over the system-wide."
230
230
:safe #'stringp
231
231
:package-version '(cider . " 1.2.0" ))
232
232
233
+ (defcustom cider-nbb-command
234
+ " nbb"
235
+ " The command used to execute nbb."
236
+ :type 'string
237
+ :safe #'stringp
238
+ :package-version '(cider . " 1.2.0" ))
239
+
240
+ (defcustom cider-nbb-global-options
241
+ nil
242
+ " Command line options used to execute nbb."
243
+ :type 'string
244
+ :safe #'stringp
245
+ :package-version '(cider . " 1.2.0" ))
246
+
247
+ (defcustom cider-nbb-parameters
248
+ " nrepl-server"
249
+ " Params passed to nbb to start an nREPL server via `cider-jack-in' ."
250
+ :type 'string
251
+ :safe #'stringp
252
+ :package-version '(cider . " 1.2.0" ))
253
+
233
254
(defcustom cider-jack-in-default (if (executable-find " clojure" ) 'clojure-cli 'lein )
234
255
" The default tool to use when doing `cider-jack-in' outside a project.
235
256
This value will only be consulted when no identifying file types, i.e.
@@ -243,7 +264,8 @@ to Leiningen."
243
264
(const clojure-cli)
244
265
(const shadow-cljs)
245
266
(const gradle)
246
- (const babashka))
267
+ (const babashka)
268
+ (const nbb))
247
269
:safe #'symbolp
248
270
:package-version '(cider . " 0.9.0" ))
249
271
@@ -262,6 +284,7 @@ command when there is no ambiguity."
262
284
(const shadow-cljs)
263
285
(const gradle)
264
286
(const babashka)
287
+ (const nbb)
265
288
(const :tag " Always ask" nil ))
266
289
:safe #'symbolp
267
290
:package-version '(cider . " 0.13.0" ))
@@ -337,6 +360,7 @@ Sub-match 1 must be the project path.")
337
360
('babashka cider-babashka-command)
338
361
('shadow-cljs cider-shadow-cljs-command)
339
362
('gradle cider-gradle-command)
363
+ ('nbb cider-nbb-command)
340
364
(_ (user-error " Unsupported project type `%S' " project-type))))
341
365
342
366
(defun cider-jack-in-resolve-command (project-type )
@@ -357,6 +381,7 @@ Throws an error if PROJECT-TYPE is unknown."
357
381
; ; relative path like "./gradlew" use locate file instead of checking
358
382
; ; the exec-path
359
383
('gradle (cider--resolve-project-command cider-gradle-command))
384
+ ('nbb (cider--resolve-command cider-nbb-command))
360
385
(_ (user-error " Unsupported project type `%S' " project-type))))
361
386
362
387
(defun cider-jack-in-global-options (project-type )
@@ -368,6 +393,7 @@ Throws an error if PROJECT-TYPE is unknown."
368
393
('babashka cider-babashka-global-options)
369
394
('shadow-cljs cider-shadow-cljs-global-options)
370
395
('gradle cider-gradle-global-options)
396
+ ('nbb cider-nbb-global-options)
371
397
(_ (user-error " Unsupported project type `%S' " project-type))))
372
398
373
399
(defun cider-jack-in-params (project-type )
@@ -383,6 +409,7 @@ Throws an error if PROJECT-TYPE is unknown."
383
409
('babashka cider-babashka-parameters)
384
410
('shadow-cljs cider-shadow-cljs-parameters)
385
411
('gradle cider-gradle-parameters)
412
+ ('nbb cider-nbb-parameters)
386
413
(_ (user-error " Unsupported project type `%S' " project-type))))
387
414
388
415
@@ -766,6 +793,10 @@ dependencies."
766
793
(cider-add-clojure-dependencies-maybe
767
794
cider-jack-in-dependencies)
768
795
(cider-jack-in-normalized-nrepl-middlewares)))
796
+ ('nbb (concat
797
+ global-opts
798
+ (unless (seq-empty-p global-opts) " " )
799
+ params))
769
800
(_ (error " Unsupported project type `%S' " project-type))))
770
801
771
802
@@ -993,30 +1024,35 @@ The supplied string will be wrapped in a do form if needed."
993
1024
(def config (edn/read-string (slurp (io/file \" build.edn\" ))))
994
1025
(apply cider.piggieback/cljs-repl (krell.repl/repl-env) (mapcat identity config))"
995
1026
cider-check-krell-requirements)
1027
+ ; ; native cljs repl, no form required.
1028
+ (nbb)
996
1029
(custom cider-custom-cljs-repl-init-form nil ))
997
1030
" A list of supported ClojureScript REPLs.
998
1031
999
- For each one we have its name, the form we need to evaluate in a Clojure
1000
- REPL to start the ClojureScript REPL and functions to verify their requirements.
1032
+ For each one we have its name, and then, if the repl is not a native
1033
+ ClojureScript REPL, the form we need to evaluate in a Clojure REPL to
1034
+ switch to the ClojureScript REPL and functions to verify their
1035
+ requirements.
1001
1036
1002
- The form should be either a string or a function producing a string." )
1037
+ The form, if any, should be either a string or a function producing a
1038
+ string." )
1003
1039
1004
- (defun cider-register-cljs-repl-type (type init-form &optional requirements-fn )
1040
+ (defun cider-register-cljs-repl-type (type &optional init-form requirements-fn )
1005
1041
" Register a new ClojureScript REPL type.
1006
1042
1007
1043
Types are defined by the following:
1008
1044
1009
1045
- TYPE - symbol identifier that will be used to refer to the REPL type
1010
- - INIT-FORM - string or function (symbol) producing string
1046
+ - INIT-FORM - (optional) string or function (symbol) producing string
1011
1047
- REQUIREMENTS-FN - function to check whether the REPL can be started.
1012
1048
This param is optional.
1013
1049
1014
1050
All this function does is modifying `cider-cljs-repl-types' .
1015
1051
It's intended to be used in your Emacs config."
1016
1052
(unless (symbolp type)
1017
1053
(user-error " The REPL type must be a symbol" ))
1018
- (unless (or (stringp init-form) (symbolp init-form))
1019
- (user-error " The init form must be a string or a symbol referring to a function" ))
1054
+ (unless (or (null init-form) ( stringp init-form) (symbolp init-form))
1055
+ (user-error " The init form must be a string or a symbol referring to a function or nil " ))
1020
1056
(unless (or (null requirements-fn) (symbolp requirements-fn))
1021
1057
(user-error " The requirements-fn must be a symbol referring to a function" ))
1022
1058
(add-to-list 'cider-cljs-repl-types (list type init-form requirements-fn)))
@@ -1036,6 +1072,7 @@ you're working on."
1036
1072
(const :tag " Shadow" shadow )
1037
1073
(const :tag " Shadow w/o Server" shadow-select)
1038
1074
(const :tag " Krell" krell)
1075
+ (const :tag " Nbb" nbb)
1039
1076
(const :tag " Custom" custom))
1040
1077
:safe #'symbolp
1041
1078
:package-version '(cider . " 0.17.0" ))
@@ -1054,15 +1091,16 @@ DEFAULT is the default ClojureScript REPL to offer in completion."
1054
1091
(or default (car cider--select-cljs-repl-history))))))
1055
1092
1056
1093
(defun cider-cljs-repl-form (repl-type )
1057
- " Get the cljs REPL form for REPL-TYPE."
1058
- (if-let* ((repl-form (cadr (seq-find
1059
- (lambda (entry )
1060
- (eq (car entry) repl-type))
1061
- cider-cljs-repl-types))))
1062
- ; ; repl-form can be either a string or a function producing a string
1063
- (if (symbolp repl-form)
1064
- (funcall repl-form)
1065
- repl-form)
1094
+ " Get the cljs REPL form for REPL-TYPE, if any."
1095
+ (if-let* ((repl-type-info (seq-find
1096
+ (lambda (entry )
1097
+ (eq (car entry) repl-type))
1098
+ cider-cljs-repl-types)))
1099
+ (when-let ((repl-form (cadr repl-type-info)))
1100
+ ; ; repl-form can be either a string or a function producing a string
1101
+ (if (symbolp repl-form)
1102
+ (funcall repl-form)
1103
+ repl-form))
1066
1104
(user-error " No ClojureScript REPL type %s found. Please make sure that `cider-cljs-repl-types' has an entry for it" repl-type)))
1067
1105
1068
1106
(defun cider-verify-cljs-repl-requirements (&optional repl-type )
@@ -1258,7 +1296,6 @@ server buffer, in which case a new session for that server is created."
1258
1296
(cider--update-cljs-type)
1259
1297
(cider--update-cljs-init-function)
1260
1298
(plist-put :session-name ses-name)
1261
- (plist-put :repl-type 'cljs )
1262
1299
(plist-put :cider-repl-cljs-upgrade-pending t )))))
1263
1300
1264
1301
;;;### autoload
@@ -1293,7 +1330,6 @@ parameters regardless of their supplied or default values."
1293
1330
(cider--update-cljs-type)
1294
1331
(cider--update-cljs-init-function)
1295
1332
(plist-put :session-name nil )
1296
- (plist-put :repl-type 'cljs )
1297
1333
(plist-put :cider-repl-cljs-upgrade-pending t ))))
1298
1334
1299
1335
;;;### autoload
@@ -1466,27 +1502,39 @@ non-nil, don't start if ClojureScript requirements are not met."
1466
1502
(plist-put :port (cdr endpoint)))))))
1467
1503
1468
1504
(defun cider--update-cljs-init-function (params )
1469
- " Update PARAMS :repl-init-function for cljs connections."
1505
+ " Update repl type and any init PARAMS for cljs connections.
1506
+
1507
+ The updated params are:
1508
+
1509
+ :cljs-type 'cljs if it is a cljs REPL, or 'pending-cljs when the init form
1510
+ is required to be sent to the REPL to switch over to cljs.
1511
+
1512
+ :repl-init-form The form that can switch the REPL over to cljs.
1513
+
1514
+ :repl-init-function The fn that switches the REPL over to cljs."
1470
1515
(with-current-buffer (or (plist-get params :--context-buffer )
1471
1516
(current-buffer ))
1472
1517
(let* ((cljs-type (plist-get params :cljs-repl-type ))
1473
1518
(repl-init-form (cider-cljs-repl-form cljs-type)))
1474
- (thread-first
1475
- params
1476
- (plist-put :repl-init-function
1477
- (lambda ()
1478
- (cider--check-cljs cljs-type)
1479
- ; ; FIXME: ideally this should be done in the state handler
1480
- (setq-local cider-cljs-repl-type cljs-type)
1481
- (cider-nrepl-send-request
1482
- (list " op" " eval"
1483
- " ns" (cider-current-ns)
1484
- " code" repl-init-form)
1485
- (cider-repl-handler (current-buffer )))
1486
- (when (and (buffer-live-p nrepl-server-buffer)
1487
- cider-offer-to-open-cljs-app-in-browser)
1488
- (cider--offer-to-open-app-in-browser nrepl-server-buffer))))
1489
- (plist-put :repl-init-form repl-init-form)))))
1519
+ (if (null repl-init-form)
1520
+ (plist-put params :repl-type 'cljs )
1521
+ (thread-first
1522
+ params
1523
+ (plist-put :repl-init-function
1524
+ (lambda ()
1525
+ (cider--check-cljs cljs-type)
1526
+ ; ; FIXME: ideally this should be done in the state handler
1527
+ (setq-local cider-cljs-repl-type cljs-type)
1528
+ (cider-nrepl-send-request
1529
+ (list " op" " eval"
1530
+ " ns" (cider-current-ns)
1531
+ " code" repl-init-form)
1532
+ (cider-repl-handler (current-buffer )))
1533
+ (when (and (buffer-live-p nrepl-server-buffer)
1534
+ cider-offer-to-open-cljs-app-in-browser)
1535
+ (cider--offer-to-open-app-in-browser nrepl-server-buffer))))
1536
+ (plist-put :repl-init-form repl-init-form)
1537
+ (plist-put :repl-type 'pending-cljs ))))))
1490
1538
1491
1539
(defun cider--check-existing-session (params )
1492
1540
" Ask for confirmation if a session with similar PARAMS already exists.
@@ -1666,7 +1714,8 @@ PROJECT-DIR defaults to current project."
1666
1714
(babashka . " bb.edn" )
1667
1715
(shadow-cljs . " shadow-cljs.edn" )
1668
1716
(gradle . " build.gradle" )
1669
- (gradle . " build.gradle.kts" ))))
1717
+ (gradle . " build.gradle.kts" )
1718
+ (nbb . " package.json" ))))
1670
1719
(delq nil
1671
1720
(mapcar (lambda (candidate )
1672
1721
(when (file-exists-p (cdr candidate))
0 commit comments