diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | cider-client.el | 12 | ||||
-rw-r--r-- | test/cider-tests.el | 15 |
3 files changed, 25 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index d6d890fd..22bb1424 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and try to associate the created connection with this project automatically. ### Changes +* `cider-current-connection` considers major mode before `cider-repl-type`. * `cider-inspect` now operates by default on the last sexp. Its behavior can be altered via prefix arguments. * Requires Clojure(Script) 1.7 or newer. * Requires Java 7 or newer. diff --git a/cider-client.el b/cider-client.el index 6cbe4c32..57457036 100644 --- a/cider-client.el +++ b/cider-client.el @@ -197,6 +197,14 @@ such a link cannot be established automatically." (cider-ensure-connected) (kill-local-variable 'cider-connections)) +(defun cider-connection-type-for-buffer () + "Return the matching connection type (clj or cljs) for the current buffer." + (cond + ((derived-mode-p 'clojurescript-mode) "cljs") + ((derived-mode-p 'clojure-mode) "clj") + (cider-repl-type) + (t "clj"))) + (defun cider-current-connection (&optional type) "Return the REPL buffer relevant for the current Clojure source buffer. A REPL is relevant if its `nrepl-project-dir' is compatible with the @@ -218,9 +226,7 @@ from the file extension." ;; Only one match, just return it. (car project-connections) ;; OW, find one matching the language of the current buffer. - (let ((type (or type cider-repl-type - (if (derived-mode-p 'clojurescript-mode) - "cljs" "clj")))) + (let ((type (or type (cider-connection-type-for-buffer)))) (or (seq-find (lambda (conn) (equal (cider--connection-type conn) type)) project-connections) diff --git a/test/cider-tests.el b/test/cider-tests.el index 11755e54..ed75b733 100644 --- a/test/cider-tests.el +++ b/test/cider-tests.el @@ -254,6 +254,21 @@ (should (string= (cider--var-namespace "a-two/var") "a-two")) (should (string= (cider--var-namespace "a.two-three.b/var-c") "a.two-three.b"))) +(ert-deftest test-cider-connection-type-for-buffer () + (with-temp-buffer + (clojurescript-mode) + (should (string= (cider-connection-type-for-buffer) "cljs"))) + (with-temp-buffer + (clojure-mode) + (should (string= (cider-connection-type-for-buffer) "clj"))) + (with-temp-buffer + (let ((cider-repl-type nil)) + (should (string= (cider-connection-type-for-buffer) "clj"))) + (let ((cider-repl-type "clj")) + (should (string= (cider-connection-type-for-buffer) "clj"))) + (let ((cider-repl-type "cljs")) + (should (string= (cider-connection-type-for-buffer) "cljs"))))) + ;;; response handling (ert-deftest test-cider-dbind-response () |