@@ -157,8 +157,10 @@ version from the CIDER package or library.")
157
157
:package-version '(cider . " 0.17.0" ))
158
158
159
159
(defcustom cider-clojure-cli-parameters
160
- " -e '(require (quote cider-nrepl.main)) (cider-nrepl.main/init [\" cider.nrepl/cider-middleware\" ])'"
161
- " Params passed to clojure to start an nREPL server via `cider-jack-in' ."
160
+ " -e '(require (quote cider-nrepl.main)) (cider-nrepl.main/init %s)'"
161
+ " Params passed to clojure to start an nREPL server via `cider-jack-in' .
162
+ This is evaluated using `format' , with the first argument being the Clojure
163
+ vector of middleware variables as a string."
162
164
:type 'string
163
165
:group 'cider
164
166
:safe #'stringp
@@ -346,7 +348,14 @@ Throws an error if PROJECT-TYPE is unknown. Known types are
346
348
(pcase project-type
347
349
(" lein" cider-lein-parameters)
348
350
(" boot" cider-boot-parameters)
349
- (" clojure-cli" cider-clojure-cli-parameters)
351
+ (" clojure-cli" (format cider-clojure-cli-parameters
352
+ (concat
353
+ " ["
354
+ (mapconcat
355
+ (apply-partially #'format " \" %s\" " )
356
+ (cider-jack-in-normalized-nrepl-middlewares)
357
+ " , " )
358
+ " ]" )))
350
359
(" shadow-cljs" cider-shadow-cljs-parameters)
351
360
(" gradle" cider-gradle-parameters)
352
361
(_ (user-error " Unsupported project type `%s' " project-type))))
@@ -385,17 +394,60 @@ specifying the artifact ID, and the second element the version number."
385
394
(string :tag " Version" ))))
386
395
387
396
(defvar cider-jack-in-lein-plugins nil
388
- " List of Leiningen plugins where elements are lists of artifact name and version." )
397
+ " List of Leiningen plugins to be injected at jack-in.
398
+ Each element is a list of artifact name and version, followed optionally by
399
+ keyword arguments. The only keyword argument currently accepted is
400
+ `:predicate' , which should be given a function that takes the list (name,
401
+ version, and keyword arguments) and returns non-nil to indicate that the
402
+ plugin should actually be injected. (This is useful primarily for packages
403
+ that extend CIDER, not for users. For example, a refactoring package might
404
+ want to inject some middleware only when within a project context.)" )
389
405
(put 'cider-jack-in-lein-plugins 'risky-local-variable t )
390
406
(cider-add-to-alist 'cider-jack-in-lein-plugins
391
407
" cider/cider-nrepl" (upcase cider-version))
392
408
409
+ (defun cider-jack-in-normalized-lein-plugins ()
410
+ " Return a normalized list of Leiningen plugins to be injected.
411
+ See `cider-jack-in-lein-plugins' for the format, except that the list
412
+ returned by this function does not include keyword arguments."
413
+ (thread-last cider-jack-in-lein-plugins
414
+ (seq-filter
415
+ (lambda (spec )
416
+ (if-let* ((pred (plist-get (seq-drop spec 2 ) :predicate )))
417
+ (funcall pred spec)
418
+ t )))
419
+ (mapcar
420
+ (lambda (spec )
421
+ (seq-take spec 2 )))))
422
+
393
423
(defvar cider-jack-in-nrepl-middlewares nil
394
424
" List of Clojure variable names.
395
- Each of these Clojure variables should hold a vector of nREPL middlewares." )
425
+ Each of these Clojure variables should hold a vector of nREPL middlewares.
426
+ Instead of a string, an element can be a list containing a string followed
427
+ by optional keyword arguments. The only keyword argument currently
428
+ accepted is `:predicate' , which should be given a function that takes the
429
+ list (string and keyword arguments) and returns non-nil to indicate that
430
+ the middlewares should actually be injected." )
396
431
(put 'cider-jack-in-nrepl-middlewares 'risky-local-variable t )
397
432
(add-to-list 'cider-jack-in-nrepl-middlewares " cider.nrepl/cider-middleware" )
398
433
434
+ (defun cider-jack-in-normalized-nrepl-middlewares ()
435
+ " Return a normalized list of middleware variable names.
436
+ See `cider-jack-in-nrepl-middlewares' for the format, except that the list
437
+ returned by this function only contains strings."
438
+ (thread-last cider-jack-in-nrepl-middlewares
439
+ (seq-filter
440
+ (lambda (spec )
441
+ (or (not (listp spec))
442
+ (if-let* ((pred (plist-get (cdr spec) :predicate )))
443
+ (funcall pred spec)
444
+ t ))))
445
+ (mapcar
446
+ (lambda (spec )
447
+ (if (listp spec)
448
+ (car spec)
449
+ spec)))))
450
+
399
451
(defun cider--list-as-boot-artifact (list )
400
452
" Return a boot artifact string described by the elements of LIST.
401
453
LIST should have the form (ARTIFACT-NAME ARTIFACT-VERSION). The returned
@@ -523,14 +575,14 @@ dependencies."
523
575
(cider-add-clojure-dependencies-maybe
524
576
cider-jack-in-dependencies)
525
577
cider-jack-in-dependencies-exclusions
526
- cider-jack-in-lein-plugins))
578
+ ( cider-jack-in-normalized- lein-plugins) ))
527
579
(" boot" (cider-boot-jack-in-dependencies
528
580
global-opts
529
581
params
530
582
(cider-add-clojure-dependencies-maybe
531
583
cider-jack-in-dependencies)
532
- cider-jack-in-lein-plugins
533
- cider-jack-in-nrepl-middlewares))
584
+ ( cider-jack-in-normalized- lein-plugins)
585
+ ( cider-jack-in-normalized- nrepl-middlewares) ))
534
586
(" clojure-cli" (cider-clojure-cli-jack-in-dependencies
535
587
global-opts
536
588
params
0 commit comments