cider-switch-to-repl-buffer should switch to relevant (not most recent) buffer

Created on 8 Sep 2017  路  3Comments  路  Source: clojure-emacs/cider

A few people (@magnars @dpsutton jumar?) were talking on Clojurians yesterday about an issue that I've noticed. I don't have all the details, but I borrowed from their descriptions, but will try to help report.

The documentation says "To switch to the relevant REPL buffer based on the Clojure namespace in the current Clojure buffer, use: C-c C-z." From cljs-mode, it should switch to the project's cljs-repl; from clojure-mode it should switch to the project's clj-repl.

Instead, it switches to the most recent REPL.

@dpsutton says it is related to: https://github.com/clojure-emacs/cider/commit/746e4d694104c0c3e0493d84b091a4fd2d54f626

To reproduce the problem:

  • Create a project with CLJ and CLJS.
  • Navigate to a file in that project, and run cider-jack-in-clojurescript.
  • Switch to the CLJ REPL buffer.
  • Navigate to a CLJS file buffer.
  • Hit C-c C-z (cider-switch-to-repl-buffer). It will switch to the CLJ REPL buffer, not the CLJS REPL buffer.

Leiningen 2.7.1

Emacs: 25.2.1

Arch/Antergos Linux

bug

Most helpful comment

Here is a PR #2085 that solve at least the CLJS case.
For me it is not clear where to switch when being in a CLJC file.

All 3 comments

My thinking is that it is the repl resolution that is the problem. In cider-current-connection, when there are more than one connection it just banks on the most recent connection, which seems wrong to me. This sounds like a resolution strategy that should be further down. I've had instances of cljs buffers loading in the clj repl, and clj files loading in other project repls.

  (cond
   ((not connections) nil)
   ;; if you're in a REPL buffer, it's the connection buffer
   ((and (derived-mode-p 'cider-repl-mode) (right-type-p (current-buffer) type)))
   ((eq cider-request-dispatch 'static) (car connections))
   ((= 1 (length connections)) (right-type-p (car connections) type))
   (t (let ((project-connections (cider-find-connection-buffer-for-project-directory
                                  nil :all-connections))
            (guessed-type (or type (cider-connection-type-for-buffer))))
        (or
         ;; cljc
         (and (equal guessed-type "multi")
              (most-recent-buf project-connections nil))
         ;; clj or cljs
         (and guessed-type
              (or (most-recent-buf project-connections guessed-type)
                  (most-recent-buf connections guessed-type)))
         ;; when type was not specified or guessed
         (most-recent-buf project-connections type)
         (most-recent-buf connections type)))))

The problem is directly with cider-switch-to-repl-buffer. BTW, same issue shows with cider-switch-to-last-clojure-buffer. Will have a look.

Here is a PR #2085 that solve at least the CLJS case.
For me it is not clear where to switch when being in a CLJC file.

Was this page helpful?
0 / 5 - 0 ratings