Skip to content

Commit 3d5d73c

Browse files
committed
Improve lookup in cider-switch-to-last-clojure-buffer
1 parent 4a41360 commit 3d5d73c

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
### Bugs Fixed
1818

19+
* `cider-switch-to-last-clojure-buffer` now switches to a Clojure buffer even when previously remembered buffer no longer exists.
1920
* [#2084](https://github.com/clojure-emacs/cider/issues/2084): Select correct REPL type (clj or cljs) in cider-switch-to-repl-buffer conditional on the current buffer.
2021
* [#2088](https://github.com/clojure-emacs/cider/issues/2088): Fix functions defined with `def` being font-locked as vars instead of functions.
2122
* [#1651](https://github.com/clojure-emacs/cider/issues/1651), [cider-nrepl#445](https://github.com/clojure-emacs/cider-nrepl/pull/455): Fix `cider-expected-ns` returns `nil` on boot projects.

cider-mode.el

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,25 @@ the same as `cider-switch-to-repl-buffer',
167167
so that it is very convenient to jump between a
168168
Clojure buffer and the REPL buffer."
169169
(interactive)
170-
(if (and (derived-mode-p 'cider-repl-mode)
171-
(buffer-live-p cider-last-clojure-buffer))
172-
(if cider-repl-display-in-current-window
173-
(pop-to-buffer-same-window cider-last-clojure-buffer)
174-
(pop-to-buffer cider-last-clojure-buffer))
175-
(message "Don't know the original Clojure buffer")))
170+
(if (derived-mode-p 'cider-repl-mode)
171+
(let* ((a-buf nil)
172+
(the-buf (if (buffer-live-p cider-last-clojure-buffer)
173+
cider-last-clojure-buffer
174+
(let ((repl-type (cider-connection-type-for-buffer)))
175+
(seq-find (lambda (b)
176+
(unless (with-current-buffer b (derived-mode-p 'cider-repl-mode))
177+
(when-let ((type (cider-connection-type-for-buffer b)))
178+
(unless a-buf
179+
(setq a-buf b))
180+
(or (equal type "multi")
181+
(equal type repl-type)))))
182+
(buffer-list))))))
183+
(if-let ((buf (or the-buf a-buf)))
184+
(if cider-repl-display-in-current-window
185+
(pop-to-buffer-same-window buf)
186+
(pop-to-buffer buf))
187+
(user-error "No Clojure buffer found")))
188+
(user-error "Not in a CIDER REPL buffer")))
176189

177190
(defun cider-find-and-clear-repl-output (&optional clear-repl)
178191
"Find the current REPL buffer and clear it.

0 commit comments

Comments
 (0)