@@ -627,7 +627,7 @@ function with the repl buffer set as current."
627627 cider-session-name ses-name
628628 nrepl-project-dir (plist-get params :project-dir )
629629 ; ; REPLs start with clj and then "upgrade" to a different type
630- cider-repl-type " clj "
630+ cider-repl-type ( plist-get params :repl-type )
631631 ; ; ran at the end of cider--connected-handler
632632 cider-repl-init-function (plist-get params :repl-init-function ))
633633 (cider-repl-reset-markers)
@@ -639,6 +639,17 @@ function with the repl buffer set as current."
639639
640640; ;; Current/other REPLs
641641
642+ (defun cider--no-repls-user-error (type )
643+ " Throw \" No REPL\" user error customized for TYPE."
644+ (let ((type (cond
645+ ((equal type " multi" )
646+ " clj or cljs" )
647+ ((listp type)
648+ (mapconcat #'identity type " or " ))
649+ (type))))
650+ (user-error " No %s REPLs in current session \" %s\" "
651+ type (car (sesman-current-session 'CIDER )))))
652+
642653(defun cider-current-repl (&optional type ensure )
643654 " Get the most recent REPL of TYPE from the current session.
644655TYPE is either \" clj\" , \" cljs\" or \" multi\" . When nil, infer the type
@@ -659,26 +670,30 @@ session."
659670 (member b repls))
660671 (buffer-list )))))
661672 (if (and ensure (null repl))
662- (user-error " No %s REPL in current session (%s)"
663- type (car (sesman-current-session 'CIDER )))
673+ (cider--no-repls-user-error type)
664674 repl))))
665675
666676(defun cider--match-repl-type (type buffer )
667677 " Return non-nil if TYPE matches BUFFER's REPL type."
668678 (let ((buffer-repl-type (cider-repl-type buffer)))
669679 (cond ((null buffer-repl-type) nil )
670680 ((or (null type) (equal type " multi" )) t )
681+ ((listp type) (member buffer-repl-type type))
671682 (t (string= type buffer-repl-type)))))
672683
673684(defun cider-repls (&optional type ensure )
674685 " Return cider REPLs of TYPE from the current session.
675- If TYPE is nil or \" multi\" , return all repls. If ENSURE is non-nil, throw
676- an error if no linked session exists."
686+ If TYPE is nil or \" multi\" , return all repls. If TYPE is a list of types,
687+ return only REPLs of type contained in the list. If ENSURE is non-nil,
688+ throw an error if no linked session exists."
677689 (let ((repls (cdr (if ensure
678690 (sesman-ensure-session 'CIDER )
679691 (sesman-current-session 'CIDER )))))
680- (seq-filter (lambda (b )
681- (cider--match-repl-type type b)) repls)))
692+ (or (seq-filter (lambda (b )
693+ (cider--match-repl-type type b))
694+ repls)
695+ (when ensure
696+ (cider--no-repls-user-error type)))))
682697
683698(defun cider-map-repls (which function )
684699 " Call FUNCTION once for each appropriate REPL as indicated by WHICH.
@@ -691,7 +706,8 @@ the following keywords:
691706 :clj-strict (:cljs-strict) - Map over clj (cljs) REPLs but signal a
692707 `user-error' in `clojurescript-mode' (`clojure-mode' ). Use this for
693708 commands only supported in Clojure (ClojureScript).
694- Error is signaled if no REPL buffer of specified type exists."
709+ Error is signaled if no REPL buffers of specified type exist in current
710+ session."
695711 (declare (indent 1 ))
696712 (let ((cur-type (cider-repl-type-for-buffer)))
697713 (cl-case which
@@ -702,7 +718,9 @@ Error is signaled if no REPL buffer of specified type exists."
702718 (let* ((type (cl-case which
703719 ((:clj :clj-strict ) " clj" )
704720 ((:cljs :cljs-strict ) " cljs" )
705- (:auto cur-type)))
721+ (:auto (if (equal cur-type " multi" )
722+ '(" clj" " cljs" )
723+ cur-type))))
706724 (repls (cider-repls type 'ensure )))
707725 (mapcar function repls))))
708726
0 commit comments