Skip to content

Commit 4079e70

Browse files
fajpunkcap10morgan
authored andcommitted
Check major mode first when choosing connection
`cider-repl-type` does not initially get set differently for the two repls created by `cider-jack-in-clojurescript`. If the major mode of the current buffer is definitely Clojure or ClojureScript, use the matching REPL connection for that type, if there is one open. If the major mode is not either of those modes, only then determine the appropriate connection by looking at `cider-repl-type`. Thanks to @rfkm for the suggestion for the change (003adaa#commitcomment-15082109)!
1 parent 0f0bb06 commit 4079e70

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
# Changelog
22

3-
## 0.10.1 / (unreleased)
3+
## 0.10.2 / (unreleased)
4+
5+
### Changes
6+
7+
* `cider-current-connection` actually, really considers major mode before `cider-repl-type`.
8+
9+
## 0.10.1 / 2015-01-05
410

511
### Changes
612

713
* Suppress eldoc when the current sexp seems to be too large.
814
* [#1500](https://github.com/clojure-emacs/cider/pull/1500): Improve the performance of REPL buffers by using text properties instead of overlays for ANSI coloring.
15+
* `cider-current-connection` considers major mode before `cider-repl-type`.
916

1017
### Bugs fixed
1118

cider-client.el

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ such a link cannot be established automatically."
197197
(cider-ensure-connected)
198198
(kill-local-variable 'cider-connections))
199199

200+
(defun cider-connection-type-for-buffer ()
201+
"Return the matching connection type (clj or cljs) for the current buffer."
202+
(cond
203+
((derived-mode-p 'clojurescript-mode) "cljs")
204+
((derived-mode-p 'clojure-mode) "clj")
205+
(cider-repl-type)
206+
(t "clj")))
207+
200208
(defun cider-current-connection (&optional type)
201209
"Return the REPL buffer relevant for the current Clojure source buffer.
202210
A REPL is relevant if its `nrepl-project-dir' is compatible with the
@@ -218,9 +226,7 @@ from the file extension."
218226
;; Only one match, just return it.
219227
(car project-connections)
220228
;; OW, find one matching the language of the current buffer.
221-
(let ((type (or type cider-repl-type
222-
(if (derived-mode-p 'clojurescript-mode)
223-
"cljs" "clj"))))
229+
(let ((type (or type (cider-connection-type-for-buffer))))
224230
(or (seq-find (lambda (conn)
225231
(equal (cider--connection-type conn) type))
226232
project-connections)

test/cider-tests.el

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,21 @@
254254
(should (string= (cider--var-namespace "a-two/var") "a-two"))
255255
(should (string= (cider--var-namespace "a.two-three.b/var-c") "a.two-three.b")))
256256

257+
(ert-deftest test-cider-connection-type-for-buffer ()
258+
(with-temp-buffer
259+
(clojurescript-mode)
260+
(should (string= (cider-connection-type-for-buffer) "cljs")))
261+
(with-temp-buffer
262+
(clojure-mode)
263+
(should (string= (cider-connection-type-for-buffer) "clj")))
264+
(with-temp-buffer
265+
(let ((cider-repl-type nil))
266+
(should (string= (cider-connection-type-for-buffer) "clj")))
267+
(let ((cider-repl-type "clj"))
268+
(should (string= (cider-connection-type-for-buffer) "clj")))
269+
(let ((cider-repl-type "cljs"))
270+
(should (string= (cider-connection-type-for-buffer) "cljs")))))
271+
257272

258273
;;; response handling
259274
(ert-deftest test-cider-dbind-response ()

0 commit comments

Comments
 (0)