Skip to content

Commit 66cbda9

Browse files
bbatsovcap10morgan
authored andcommitted
Handle the case of being in a REPL buffer when invoking cider-current-connection
If we don't account for this, you might end up using the wrong connection, if there are several connections for your project.
1 parent 7f67cb4 commit 66cbda9

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

cider-client.el

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -204,25 +204,28 @@ current directory (see `cider-find-connection-buffer-for-project-directory').
204204
If there is ambiguity, it is resolved by matching TYPE with the REPL
205205
type (Clojure or ClojureScript). TYPE is a string, which when nil is derived
206206
from the file extension."
207-
(let ((connections (cider-connections)))
208-
(cond
209-
((eq cider-request-dispatch 'static) (car connections))
210-
((= 1 (length connections)) (car connections))
211-
(t (let ((project-connections
212-
(cider-find-connection-buffer-for-project-directory
213-
nil :all-connections)))
214-
(if (= 1 (length project-connections))
215-
;; Only one match, just return it.
216-
(car project-connections)
217-
;; OW, find one matching the language of the current buffer.
218-
(let ((type (or type cider-repl-type
219-
(if (derived-mode-p 'clojurescript-mode)
220-
"cljs" "clj"))))
221-
(or (seq-find (lambda (conn)
222-
(equal (cider--connection-type conn) type))
223-
project-connections)
224-
(car project-connections)
225-
(car connections)))))))))
207+
;; if you're in a REPL buffer, it's the connection buffer
208+
(if (derived-mode-p 'cider-repl-mode)
209+
(current-buffer)
210+
(let ((connections (cider-connections)))
211+
(cond
212+
((eq cider-request-dispatch 'static) (car connections))
213+
((= 1 (length connections)) (car connections))
214+
(t (let ((project-connections
215+
(cider-find-connection-buffer-for-project-directory
216+
nil :all-connections)))
217+
(if (= 1 (length project-connections))
218+
;; Only one match, just return it.
219+
(car project-connections)
220+
;; 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"))))
224+
(or (seq-find (lambda (conn)
225+
(equal (cider--connection-type conn) type))
226+
project-connections)
227+
(car project-connections)
228+
(car connections))))))))))
226229

227230
(defun cider-other-connection (&optional connection)
228231
"Return the first connection of another type than CONNECTION

0 commit comments

Comments
 (0)