Skip to content

Commit f65ea20

Browse files
committed
3834 Extend cider-map-repls to allow ensured op list
1 parent 16e1afc commit f65ea20

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

cider-connection.el

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,8 +1053,9 @@ throw an error if no linked session exists."
10531053
(defun cider-map-repls (which function)
10541054
"Call FUNCTION once for each appropriate REPL as indicated by WHICH.
10551055
The function is called with one argument, the REPL buffer. The appropriate
1056-
connections are found by inspecting the current buffer. WHICH is one of
1057-
the following keywords:
1056+
connections are found by inspecting the current buffer. WHICH is either one of
1057+
the following keywords or a list starting with one of them followed by names of
1058+
operations that the REPL is expected to support:
10581059
:auto - Act on the connections whose type matches the current buffer. In
10591060
`cljc' files, mapping happens over both types of REPLs.
10601061
:clj (:cljs) - Map over clj (cljs)) REPLs only.
@@ -1064,23 +1065,33 @@ the following keywords:
10641065
Error is signaled if no REPL buffers of specified type exist in current
10651066
session."
10661067
(declare (indent 1))
1067-
(let ((cur-type (cider-repl-type-for-buffer)))
1068-
(cl-case which
1068+
(let ((cur-type (cider-repl-type-for-buffer))
1069+
(which-key (or (car-safe which) which))
1070+
(ops-to-support (cdr-safe which)))
1071+
(cl-case which-key
10691072
(:clj-strict (when (eq cur-type 'cljs)
10701073
(user-error "Clojure-only operation requested in a ClojureScript buffer")))
10711074
(:cljs-strict (when (eq cur-type 'clj)
10721075
(user-error "ClojureScript-only operation requested in a Clojure buffer"))))
1073-
(let* ((type (cl-case which
1076+
(let* ((type (cl-case which-key
10741077
((:clj :clj-strict) 'clj)
10751078
((:cljs :cljs-strict) 'cljs)
10761079
(:auto (if (eq cur-type 'multi)
10771080
'(clj cljs)
10781081
cur-type))))
1079-
(ensure (cl-case which
1082+
(ensure (cl-case which-key
10801083
(:auto nil)
10811084
(t 'ensure)))
10821085
(repls (cider-repls type ensure)))
1083-
(mapcar function repls))))
1086+
(mapcar (lambda (repl)
1087+
(mapc (lambda (op)
1088+
(unless (nrepl-op-supported-p op repl)
1089+
(user-error "`%s' requires the nREPL op \"%s\" (provided by cider-nrepl)"
1090+
this-command op)))
1091+
ops-to-support)
1092+
(funcall function repl))
1093+
repls))))
1094+
10841095

10851096
;; REPLs double as connections in CIDER, so it's useful to be able to refer to
10861097
;; them as connections in certain contexts.

cider-ns.el

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,8 @@ refresh functions (defined in `cider-ns-refresh-before-fn' and
300300
(let ((clear? (member mode '(clear 16)))
301301
(all? (member mode '(refresh-all 4)))
302302
(inhibit-refresh-fns (member mode '(inhibit-fns -1))))
303-
(cider-map-repls :clj
303+
(cider-map-repls '(:clj "refresh" "cider.clj-reload/reload")
304304
(lambda (conn)
305-
(cider-ensure-op-supported "refresh" conn)
306-
(cider-ensure-op-supported "cider.clj-reload/reload" conn)
307305
(cider-ns-refresh--save-modified-buffers conn)
308306
;; Inside the lambda, so the buffer is not created if we error out.
309307
(let ((log-buffer (or (get-buffer cider-ns-refresh-log-buffer)

0 commit comments

Comments
 (0)