cider-switch-to-repl-buffer switches to first found buffer

Created on 20 Feb 2018  路  11Comments  路  Source: clojure-emacs/cider

Is there a reason why cider-switch-to-repl-buffer switches to the first buffer it finds on the (cider-connections) instead of using (cider-current-connection)?

When I'm working on multiple Clojure projects simultaneously and I press C-c C-z CIDER often sends me to a wrong REPL buffer, different from the one associated with the code buffer (also shown in the lighter).

Expected behavior

C-c C-z should switch to the same REPL buffer that the code buffer is associated with.

Actual behavior

C-c C-z switches to the most "recent" REPL buffer (recent in quotes because my workflow often reorders buffer order).

CIDER 0.17.0-SNAPSHOT

Most helpful comment

@gavinmbell I've been using this patch onto the dispatch part.

https://github.com/dpsutton/cider/commit/535804eb227dc5b9db1143fe7864b809dbc4ea91

I might do a PR as I think its better than what we have now. At work we have three repls (server clj, webapp clj and cljs) open at all times. The last repl is often not what I want.

All 11 comments

Hmm, supposedly @vspinu recently fixed this. I'll have to dig the related PR.

It looks to me that it only adds the smarts for distinguishing CLJ/CLJS. But if you have to active CLJ connections it would just grab the most recent one.

FWIW, I've locally replaced C-c C-z with this:

    (defun cider-switch-to-repl-connection-buffer (&optional set-namespace)
      (interactive "P")
      (cider--switch-to-repl-buffer (cider-current-connection) set-namespace))

I guess this is an incorrect solution for the general case but I'd like to know how it can be made a correct one.

The "correct" solution would require cider-current-connections which is not there yet. Your solution would work if you keep one connection per project and will break with clj/cljs repls and (probably) with multiple connections per project. In any case this one will be automatically taken care by #2069.

Thanks for the heads up. I'll be waiting for #2069 then.

@alexander-yakushev i'm using this which does deal with clj cljs:

(defun cider-switch-to-repl-buffer (&optional set-namespace)
  (interactive "P")
  (let* ((type (cider-connection-type-for-buffer))
         (found (seq-find (lambda (b)
                            (or (equal type (cider-connection-type-for-buffer b))
                                (and (= type "multi")
                                     b)))
                          (cider-find-connection-buffer-for-project-directory nil :all-connections))))
    (if found
        (cider--switch-to-repl-buffer found set-namespace)
      (user-error "No REPL found for project."))))

you can use clojure-mode and clojurescript-mode to disambiguate cljc buffers if you ilke but it should return a stable choice of cljs/clj connection otherwise.

the important bit is that this relies on cider-find-connection-buffer-for-project-directory as these are the only repls that should be in consideration anyways.

Currently using: CIDER 0.18.0snapshot (package: 20180509.109)
As of this moment the initial desire of this issue has not been fulfilled. It is a highly desired feature for workflows across "projects". Is there any movement on this? :-/
What would you recommend one do with regards to having this functionality?

@vspinu told me he's going to work on the connection handling rewrite in this version. It's one of our top priorities right now. I'll give him some space and focus on things that would cause issues with revamping this.

Generally I'm ready to cut a new release the moment we've switched to the more generic connection management based on connection groups (or sessions depending on the terms you want to use). Ultimately we'll end up with just a single session per project, with multiple connections in this session and some simple means to select the right connection depending on what you're doing/where you are.

@gavinmbell I've been using this patch onto the dispatch part.

https://github.com/dpsutton/cider/commit/535804eb227dc5b9db1143fe7864b809dbc4ea91

I might do a PR as I think its better than what we have now. At work we have three repls (server clj, webapp clj and cljs) open at all times. The last repl is often not what I want.

I think @vspinu already fixed this in 0.18.

Was this page helpful?
0 / 5 - 0 ratings