Skip to content

Commit ece9bdb

Browse files
committed
[Fix #1299] Eval in both REPLs for cljc and cljx
This changes the load file request to dispatch to `cider-other-connection` in addition to `cider-current-connection`, when the file is a cljc or cljx file.
1 parent 2ff5097 commit ece9bdb

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
### Changes
4949

50+
* [#1299]https://github.com/clojure-emacs/cider/issues/1299 <kbd>C-c C-k</kbd> and <kbd> C-c C-l</kbd> now dispatch to both the Clojure and ClojureScript REPL (in the same project) when called from a cljc or cljx file.
5051
* [#1397](https://github.com/clojure-emacs/cider/issues/1297) <kbd>C-c M-n</kbd> now changes the ns of both the Clojure and ClojureScript REPL (in the same project) when called from a cljc or cljx file.
5152
* [#1348](https://github.com/clojure-emacs/cider/issues/1348): Drop the dash dependency.
5253
* The usage of the default connection has been reduced significantly. Now evaluations & related commands will be routed via the connection matching the current project automatically unless there's some ambiguity when determining the connection (like multiple or no matching connections). Simply put you'll no longer have to mess around much with connecting-setting commands (e.g. `nrepl-connection-browser`, `cider-rotate-default-connection`).

cider-client.el

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,16 @@ Signal an error if it is not supported."
417417
(unless (cider-nrepl-op-supported-p op)
418418
(error "Can't find nREPL middleware providing op \"%s\". Please, install (or update) cider-nrepl %s and restart CIDER" op (upcase cider-version))))
419419

420-
(defun cider-nrepl-send-request (request callback)
420+
(defun cider-nrepl-send-request (request callback &optional connection)
421421
"Send REQUEST and register response handler CALLBACK.
422422
REQUEST is a pair list of the form (\"op\" \"operation\" \"par1-name\"
423423
\"par1\" ... ).
424+
425+
If CONNECTION is provided dispatch to that connection instead of
426+
the current connection.
427+
424428
Return the id of the sent message."
425-
(nrepl-send-request request callback (cider-current-connection)))
429+
(nrepl-send-request request callback (or connection (cider-current-connection))))
426430

427431
(defun cider-nrepl-send-sync-request (request &optional abort-on-input)
428432
"Send REQUEST to the nREPL server synchronously.
@@ -591,17 +595,21 @@ thing at point."
591595
;;; Requests
592596

593597
(declare-function cider-load-file-handler "cider-interaction")
594-
(defun cider-request:load-file (file-contents file-path file-name &optional callback)
598+
(defun cider-request:load-file (file-contents file-path file-name &optional connection callback)
595599
"Perform the nREPL \"load-file\" op.
596600
FILE-CONTENTS, FILE-PATH and FILE-NAME are details of the file to be
597-
loaded. If CALLBACK is nil, use `cider-load-file-handler'."
601+
loaded.
602+
603+
If CONNECTION is nil, use `cider-current-connection'
604+
If CALLBACK is nil, use `cider-load-file-handler'."
598605
(cider-nrepl-send-request (list "op" "load-file"
599606
"session" (cider-current-session)
600607
"file" file-contents
601608
"file-path" file-path
602609
"file-name" file-name)
603610
(or callback
604-
(cider-load-file-handler (current-buffer)))))
611+
(cider-load-file-handler (current-buffer)))
612+
connection))
605613

606614

607615
;;; Sync Requests

cider-interaction.el

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,10 @@ unloaded."
13431343
(substring-no-properties (buffer-string))))
13441344

13451345
(defun cider-load-file (filename)
1346-
"Load (eval) the Clojure file FILENAME in nREPL."
1346+
"Load (eval) the Clojure file FILENAME in nREPL.
1347+
1348+
If the file is a cljc or cljx file, and both a Clojure and ClojureScript
1349+
REPL exists for the project, it is evaluated in both REPLs."
13471350
(interactive (list
13481351
(read-file-name "Load file: " nil nil nil
13491352
(when (buffer-file-name)
@@ -1356,10 +1359,18 @@ unloaded."
13561359
(cider--clear-compilation-highlights)))
13571360
(cider--quit-error-window)
13581361
(cider--cache-ns-form)
1359-
(cider-request:load-file
1360-
(cider-file-string filename)
1361-
(funcall cider-to-nrepl-filename-function (cider--server-filename filename))
1362-
(file-name-nondirectory filename))
1362+
(if-let ((_ (cider--cljc-or-cljx-file-p filename))
1363+
(other-connection (cider-other-connection)))
1364+
(dolist (connection (list (cider-current-connection) other-connection))
1365+
(cider-request:load-file
1366+
(cider-file-string filename)
1367+
(funcall cider-to-nrepl-filename-function (cider--server-filename filename))
1368+
(file-name-nondirectory filename)
1369+
connection))
1370+
(cider-request:load-file
1371+
(cider-file-string filename)
1372+
(funcall cider-to-nrepl-filename-function (cider--server-filename filename))
1373+
(file-name-nondirectory filename)))
13631374
(message "Loading %s..." filename))
13641375

13651376
(defun cider-load-buffer (&optional buffer)

cider-util.el

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ If BUFFER is provided act on that buffer instead."
8787
(with-current-buffer (or buffer (current-buffer))
8888
(or (derived-mode-p 'clojurec-mode) (derived-mode-p 'clojurex-mode))))
8989

90+
(defun cider--cljc-or-cljx-file-p (file-name)
91+
"Return true if FILE-NAME is for a cljc or cljx file."
92+
(string-match "\\.clj\\(x\\|c\\)\\'" file-name))
93+
9094

9195
;;; Thing at point
9296
(defun cider-defun-at-point ()

0 commit comments

Comments
 (0)