@@ -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
@@ -984,30 +1015,35 @@ The supplied string will be wrapped in a do form if needed."
984
1015
(def config (edn/read-string (slurp (io/file \" build.edn\" ))))
985
1016
(apply cider.piggieback/cljs-repl (krell.repl/repl-env) (mapcat identity config))"
986
1017
cider-check-krell-requirements)
1018
+ ; ; native cljs repl, no form required.
1019
+ (nbb)
987
1020
(custom cider-custom-cljs-repl-init-form nil ))
988
1021
" A list of supported ClojureScript REPLs.
989
1022
990
- For each one we have its name, the form we need to evaluate in a Clojure
991
- REPL to start the ClojureScript REPL and functions to verify their requirements.
1023
+ For each one we have its name, and then, if the repl is not a native
1024
+ ClojureScript REPL, the form we need to evaluate in a Clojure REPL to
1025
+ switch to the ClojureScript REPL and functions to verify their
1026
+ requirements.
992
1027
993
- The form should be either a string or a function producing a string." )
1028
+ The form, if any, should be either a string or a function producing a
1029
+ string." )
994
1030
995
- (defun cider-register-cljs-repl-type (type init-form &optional requirements-fn )
1031
+ (defun cider-register-cljs-repl-type (type &optional init-form requirements-fn )
996
1032
" Register a new ClojureScript REPL type.
997
1033
998
1034
Types are defined by the following:
999
1035
1000
1036
- TYPE - symbol identifier that will be used to refer to the REPL type
1001
- - INIT-FORM - string or function (symbol) producing string
1037
+ - INIT-FORM - (optional) string or function (symbol) producing string
1002
1038
- REQUIREMENTS-FN - function to check whether the REPL can be started.
1003
1039
This param is optional.
1004
1040
1005
1041
All this function does is modifying `cider-cljs-repl-types' .
1006
1042
It's intended to be used in your Emacs config."
1007
1043
(unless (symbolp type)
1008
1044
(user-error " The REPL type must be a symbol" ))
1009
- (unless (or (stringp init-form) (symbolp init-form))
1010
- (user-error " The init form must be a string or a symbol referring to a function" ))
1045
+ (unless (or (null init-form) ( stringp init-form) (symbolp init-form))
1046
+ (user-error " The init form must be a string or a symbol referring to a function or nil " ))
1011
1047
(unless (or (null requirements-fn) (symbolp requirements-fn))
1012
1048
(user-error " The requirements-fn must be a symbol referring to a function" ))
1013
1049
(add-to-list 'cider-cljs-repl-types (list type init-form requirements-fn)))
@@ -1027,6 +1063,7 @@ you're working on."
1027
1063
(const :tag " Shadow" shadow )
1028
1064
(const :tag " Shadow w/o Server" shadow-select)
1029
1065
(const :tag " Krell" krell)
1066
+ (const :tag " Nbb" nbb)
1030
1067
(const :tag " Custom" custom))
1031
1068
:safe #'symbolp
1032
1069
:package-version '(cider . " 0.17.0" ))
@@ -1045,15 +1082,16 @@ DEFAULT is the default ClojureScript REPL to offer in completion."
1045
1082
(or default (car cider--select-cljs-repl-history))))))
1046
1083
1047
1084
(defun cider-cljs-repl-form (repl-type )
1048
- " Get the cljs REPL form for REPL-TYPE."
1049
- (if-let* ((repl-form (cadr (seq-find
1050
- (lambda (entry )
1051
- (eq (car entry) repl-type))
1052
- cider-cljs-repl-types))))
1053
- ; ; repl-form can be either a string or a function producing a string
1054
- (if (symbolp repl-form)
1055
- (funcall repl-form)
1056
- repl-form)
1085
+ " Get the cljs REPL form for REPL-TYPE, if any."
1086
+ (if-let* ((repl-type-info (seq-find
1087
+ (lambda (entry )
1088
+ (eq (car entry) repl-type))
1089
+ cider-cljs-repl-types)))
1090
+ (when-let ((repl-form (cadr repl-type-info)))
1091
+ ; ; repl-form can be either a string or a function producing a string
1092
+ (if (symbolp repl-form)
1093
+ (funcall repl-form)
1094
+ repl-form))
1057
1095
(user-error " No ClojureScript REPL type %s found. Please make sure that `cider-cljs-repl-types' has an entry for it" repl-type)))
1058
1096
1059
1097
(defun cider-verify-cljs-repl-requirements (&optional repl-type )
@@ -1248,8 +1286,7 @@ server buffer, in which case a new session for that server is created."
1248
1286
(append other-params)
1249
1287
(cider--update-cljs-type)
1250
1288
(cider--update-cljs-init-function)
1251
- (plist-put :session-name ses-name)
1252
- (plist-put :repl-type 'pending-cljs )))))
1289
+ (plist-put :session-name ses-name)))))
1253
1290
1254
1291
;;;### autoload
1255
1292
(defun cider-connect-clj (&optional params )
@@ -1282,8 +1319,7 @@ parameters regardless of their supplied or default values."
1282
1319
(cider--check-existing-session)
1283
1320
(cider--update-cljs-type)
1284
1321
(cider--update-cljs-init-function)
1285
- (plist-put :session-name nil )
1286
- (plist-put :repl-type 'pending-cljs ))))
1322
+ (plist-put :session-name nil ))))
1287
1323
1288
1324
;;;### autoload
1289
1325
(defun cider-connect-clj&cljs (params &optional soft-cljs-start )
@@ -1455,27 +1491,39 @@ non-nil, don't start if ClojureScript requirements are not met."
1455
1491
(plist-put :port (cdr endpoint)))))))
1456
1492
1457
1493
(defun cider--update-cljs-init-function (params )
1458
- " Update PARAMS :repl-init-function for cljs connections."
1494
+ " Update repl type and any init PARAMS for cljs connections.
1495
+
1496
+ The updated params are:
1497
+
1498
+ :cljs-type 'cljs if it is a cljs REPL, or 'pending-cljs when the init form
1499
+ is required to be sent to the REPL to switch over to cljs.
1500
+
1501
+ :repl-init-form The form that can switch the REPL over to cljs.
1502
+
1503
+ :repl-init-function The fn that switches the REPL over to cljs."
1459
1504
(with-current-buffer (or (plist-get params :--context-buffer )
1460
1505
(current-buffer ))
1461
1506
(let* ((cljs-type (plist-get params :cljs-repl-type ))
1462
1507
(repl-init-form (cider-cljs-repl-form cljs-type)))
1463
- (thread-first
1464
- params
1465
- (plist-put :repl-init-function
1466
- (lambda ()
1467
- (cider--check-cljs cljs-type)
1468
- ; ; FIXME: ideally this should be done in the state handler
1469
- (setq-local cider-cljs-repl-type cljs-type)
1470
- (cider-nrepl-send-request
1471
- (list " op" " eval"
1472
- " ns" (cider-current-ns)
1473
- " code" repl-init-form)
1474
- (cider-repl-handler (current-buffer )))
1475
- (when (and (buffer-live-p nrepl-server-buffer)
1476
- cider-offer-to-open-cljs-app-in-browser)
1477
- (cider--offer-to-open-app-in-browser nrepl-server-buffer))))
1478
- (plist-put :repl-init-form repl-init-form)))))
1508
+ (if (null repl-init-form)
1509
+ (plist-put params :repl-type 'cljs )
1510
+ (thread-first
1511
+ params
1512
+ (plist-put :repl-init-function
1513
+ (lambda ()
1514
+ (cider--check-cljs cljs-type)
1515
+ ; ; FIXME: ideally this should be done in the state handler
1516
+ (setq-local cider-cljs-repl-type cljs-type)
1517
+ (cider-nrepl-send-request
1518
+ (list " op" " eval"
1519
+ " ns" (cider-current-ns)
1520
+ " code" repl-init-form)
1521
+ (cider-repl-handler (current-buffer )))
1522
+ (when (and (buffer-live-p nrepl-server-buffer)
1523
+ cider-offer-to-open-cljs-app-in-browser)
1524
+ (cider--offer-to-open-app-in-browser nrepl-server-buffer))))
1525
+ (plist-put :repl-init-form repl-init-form)
1526
+ (plist-put :repl-type 'pending-cljs ))))))
1479
1527
1480
1528
(defun cider--check-existing-session (params )
1481
1529
" Ask for confirmation if a session with similar PARAMS already exists.
@@ -1655,7 +1703,8 @@ PROJECT-DIR defaults to current project."
1655
1703
(babashka . " bb.edn" )
1656
1704
(shadow-cljs . " shadow-cljs.edn" )
1657
1705
(gradle . " build.gradle" )
1658
- (gradle . " build.gradle.kts" ))))
1706
+ (gradle . " build.gradle.kts" )
1707
+ (nbb . " package.json" ))))
1659
1708
(delq nil
1660
1709
(mapcar (lambda (candidate )
1661
1710
(when (file-exists-p (cdr candidate))
0 commit comments