From 3713ebb030f66785869085640c8e498cb6901441 Mon Sep 17 00:00:00 2001 From: Dan Sutton Date: Thu, 12 Jan 2017 11:59:37 -0600 Subject: [PATCH 1/5] Derive clojure interaction mode from clojurec mode From the scratch buffer, we derive from clojure mode, which makes the eval architecture default to clj connections over cljs connections. Deriving from the -c mode allows us to dispatch a little easier to the first of (possibly) many connections. --- cider-scratch.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cider-scratch.el b/cider-scratch.el index e4e3150d9..b537441b9 100644 --- a/cider-scratch.el +++ b/cider-scratch.el @@ -66,7 +66,7 @@ (or (get-buffer cider-scratch-buffer-name) (cider-create-scratch-buffer))) -(define-derived-mode cider-clojure-interaction-mode clojure-mode "Clojure Interaction" +(define-derived-mode cider-clojure-interaction-mode clojurec-mode "Clojure Interaction" "Major mode for typing and evaluating Clojure forms. Like clojure-mode except that \\[cider-eval-print-last-sexp] evals the Lisp expression before point, and prints its value into the buffer, advancing point. From eaf16d8ce14cb62da9fcf62702a56570a22bee9a Mon Sep 17 00:00:00 2001 From: Dan Sutton Date: Thu, 12 Jan 2017 12:08:38 -0600 Subject: [PATCH 2/5] For connection type of cljc, return the first connection --- cider-client.el | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cider-client.el b/cider-client.el index 3b1fbed82..9651ca931 100644 --- a/cider-client.el +++ b/cider-client.el @@ -224,6 +224,8 @@ such a link cannot be established automatically." (defun cider-connection-type-for-buffer () "Return the matching connection type (clj or cljs) for the current buffer." (cond + ;; cljc mode must be first as it derives from clj mode + ((derived-mode-p 'clojurec-mode) "cljc") ((derived-mode-p 'clojurescript-mode) "cljs") ((derived-mode-p 'clojure-mode) "clj") (cider-repl-type) @@ -272,7 +274,12 @@ at all." (guessed-type (or type (cider-connection-type-for-buffer)))) ;; So we have multiple connections. Look for the connection type we ;; want, prioritizing the current project. - (or (seq-find (lambda (conn) + + ;; when cljc buffer, use the first connection (you can rotate this + ;; to set priority + (or (when (string= "cljc" guessed-type) + (car connections)) + (seq-find (lambda (conn) (equal (cider--connection-type conn) guessed-type)) project-connections) (seq-find (lambda (conn) From 941206415c22eec6400c8c938130b4aa58c14294 Mon Sep 17 00:00:00 2001 From: Dan Sutton Date: Thu, 12 Jan 2017 12:09:09 -0600 Subject: [PATCH 3/5] Rotate connection order per buffer to toggle connection Since now cljc buffer connections are determined by order, we can rotate the order to change which connection we are using. --- cider-client.el | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cider-client.el b/cider-client.el index 9651ca931..efe379f24 100644 --- a/cider-client.el +++ b/cider-client.el @@ -210,10 +210,9 @@ such a link cannot be established automatically." "Toggles the current buffer's connection between Clojure and ClojureScript." (interactive) (cider-ensure-connected) - (let ((other-conn (cider-other-connection))) - (if other-conn - (setq-local cider-connections (list other-conn)) - (user-error "No other connection available")))) + (when-let ((conns (cider-connections))) + (setq-local cider-connections (append (rest conns) (list (car conns)))) + (message "Repl type default set to: %s" (cider--connection-type (car (cider-connections)))))) (defun cider-clear-buffer-local-connection () "Remove association between the current buffer and a connection." From bbdbf913062f552b801b80c719247d8f62b30586 Mon Sep 17 00:00:00 2001 From: Dan Sutton Date: Thu, 12 Jan 2017 14:54:36 -0600 Subject: [PATCH 4/5] Add to bugs fixed --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dac67f4dd..70df09628 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ * [#1875](https://github.com/clojure-emacs/cider/issues/1875): Ensure cljc buffers can load buffer into both clj and cljs repls. * [#1897](https://github.com/clojure-emacs/cider/issues/1897): Bind TAB in stacktrace buffers in the terminal. * [#1895](https://github.com/clojure-emacs/cider/issues/1895): Connect to the same host:port after `cider-restart` if the connection was established with `cider-connect`. +* [#1913](https://github.com/clojure-emacs/cider/issues/1913): Fix bug in `cider-toggle-buffer-connection` to not delete connections. ## 0.14.0 (2016-10-13) From 6788bacba15c46bfaa4dd5359a9b752ecf475183 Mon Sep 17 00:00:00 2001 From: Dan Sutton Date: Fri, 13 Jan 2017 07:40:16 -0600 Subject: [PATCH 5/5] Use cdr instead of rest --- cider-client.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cider-client.el b/cider-client.el index efe379f24..2325f759b 100644 --- a/cider-client.el +++ b/cider-client.el @@ -211,7 +211,7 @@ such a link cannot be established automatically." (interactive) (cider-ensure-connected) (when-let ((conns (cider-connections))) - (setq-local cider-connections (append (rest conns) (list (car conns)))) + (setq-local cider-connections (append (cdr conns) (list (car conns)))) (message "Repl type default set to: %s" (cider--connection-type (car (cider-connections)))))) (defun cider-clear-buffer-local-connection ()