Skip to content

Commit 5cd56ce

Browse files
committed
Turn do-connections into a function: map-connections
1 parent 6bc4195 commit 5cd56ce

File tree

4 files changed

+25
-30
lines changed

4 files changed

+25
-30
lines changed

cider-client.el

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,9 @@ from the file extension."
226226
(car cider-connections)))
227227

228228
(defun cider-other-connection (&optional connection)
229-
"Return the first connection of another type than `cider-current-connection', \
230-
in the same project, or nil.
231-
232-
If CONNECTION is provided act on that connection instead."
229+
"Return the first connection of another type than CONNECTION
230+
Only return connections in the same project or nil.
231+
CONNECTION defaults to `cider-current-connection'."
233232
(let* ((connection (or connection (cider-current-connection)))
234233
(connection-type (cider--connection-type connection))
235234
(other (if (equal connection-type "clj")
@@ -238,6 +237,17 @@ If CONNECTION is provided act on that connection instead."
238237
(unless (equal connection-type (cider--connection-type other))
239238
other)))
240239

240+
(defun cider-map-connections (function)
241+
"Call FUNCTION once for each appropriate connection.
242+
The function is called with one argument, the connection buffer.
243+
The appropriate connections are found by inspecting the current buffer. If
244+
the buffer is associated with a .cljc or .cljx file, BODY will be executed
245+
multiple times."
246+
(if-let ((is-cljc (cider--cljc-or-cljx-buffer-p))
247+
(other-connection (cider-other-connection)))
248+
(mapc function (list (cider-current-connection) other-connection))
249+
(funcall function (cider-current-connection))))
250+
241251

242252
;;; Connection Browser
243253
(defvar cider-connections-buffer-mode-map

cider-common.el

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -224,21 +224,5 @@ existing file ending with URL has been found."
224224
(16 t) ; empty empty
225225
(_ nil))))
226226

227-
(defmacro cider-do-connections (var &rest body)
228-
"For each appropriate connection, bind it to VAR, and execute BODY.
229-
230-
The appropriate connections are found by inspecting the current buffer. If
231-
the buffer is associated with a .cljc or .cljx file, BODY will be executed
232-
multiple times."
233-
(declare (indent 1)
234-
(debug (form body)))
235-
(let ((other-connection 'oh-my-god-the-linter-wont-let-me-use-gensym))
236-
`(if-let ((_ (cider--cljc-or-cljx-buffer-p))
237-
(,other-connection (cider-other-connection)))
238-
(dolist (,var (list (cider-current-connection) ,other-connection))
239-
,@body)
240-
(let ((,var (cider-current-connection)))
241-
,@body))))
242-
243227
(provide 'cider-common)
244228
;;; cider-common.el ends here

cider-interaction.el

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,12 +1373,13 @@ ClojureScript REPL exists for the project, it is evaluated in both REPLs."
13731373
(cider--quit-error-window)
13741374
(cider--cache-ns-form)
13751375
(let ((filename (buffer-file-name)))
1376-
(cider-do-connections connection
1377-
(cider-request:load-file
1378-
(cider-file-string filename)
1379-
(funcall cider-to-nrepl-filename-function (cider--server-filename filename))
1380-
(file-name-nondirectory filename)
1381-
connection))
1376+
(cider-map-connections
1377+
(lambda (connection)
1378+
(cider-request:load-file (cider-file-string filename)
1379+
(funcall cider-to-nrepl-filename-function
1380+
(cider--server-filename filename))
1381+
(file-name-nondirectory filename)
1382+
connection)))
13821383
(message "Loading %s..." filename))))
13831384

13841385
(defun cider-load-file (filename)

cider-repl.el

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -790,10 +790,10 @@ namespace to switch to."
790790
(cider-current-ns))))
791791
(when (or (not ns) (equal ns ""))
792792
(user-error "No namespace selected"))
793-
(cider-do-connections connection
794-
(cider-nrepl-request:eval (format "(in-ns '%s)" ns)
795-
(cider-repl-switch-ns-handler
796-
connection))))
793+
(cider-map-connections
794+
(lambda (connection)
795+
(cider-nrepl-request:eval (format "(in-ns '%s)" ns)
796+
(cider-repl-switch-ns-handler connection)))))
797797

798798

799799
;;;;; History

0 commit comments

Comments
 (0)