Skip to content

Commit

Permalink
Refactor cider-switch-to-repl-buffer and cider-repl-switch-to-other
Browse files Browse the repository at this point in the history
  - cider-switch-to-repl-buffer uses cider-current-repl instead of implementing
    its own lookup

  - cider-repl-switch-to-other throws a "no other REPL" error if no other REPL
    exists instead of switching to an arbitrary buffer
  • Loading branch information
vspinu committed Jun 29, 2018
1 parent 7f091fe commit ce38db0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
28 changes: 7 additions & 21 deletions cider-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,14 @@ that of the namespace in the Clojure source buffer."
(goto-char (point-max))))

(defun cider-switch-to-repl-buffer (&optional set-namespace)
"Select the REPL buffer, when possible in an existing window.
The buffer chosen is based on the file open in the current buffer. If
multiple cider sessions are associated with current connection the most
recent is used. With a prefix arg SET-NAMESPACE sets the namespace in the
REPL buffer to that of the namespace in the Clojure source buffer
Hint: You can use `display-buffer-reuse-frames' and
`special-display-buffer-names' to customize the frame in which
the buffer should appear."
"Switch to current REPL buffer, when possible in an existing window.
The type of the REPL is inferred from the mode of current buffer. With a
prefix arg SET-NAMESPACE sets the namespace in the REPL buffer to that of
the namespace in the Clojure source buffer"
(interactive "P")
(if-let* ((repls (cider-repls)))
(let* ((type (cider-repl-type-for-buffer))
(a-repl)
(the-repl (seq-find (lambda (buf)
(when (member buf repls)
(unless a-repl
(setq a-repl buf))
(equal type (cider-repl-type-for-buffer buf))))
(buffer-list))))
(let ((repl (or the-repl a-repl)))
(cider--switch-to-repl-buffer repl set-namespace)))
(user-error "No linked REPL")))
(cider--switch-to-repl-buffer
(cider-current-repl nil 'ensure)
set-namespace))

(declare-function cider-load-buffer "cider-eval")

Expand Down
10 changes: 6 additions & 4 deletions cider-repl.el
Original file line number Diff line number Diff line change
Expand Up @@ -1027,10 +1027,12 @@ text property `cider-old-input'."
"Switch between the Clojure and ClojureScript REPLs for the current project."
(interactive)
;; FIXME: implement cycling as session can hold more than two REPLs
(if-let* ((this-repl (cider-current-repl))
(other-repls (seq-remove (lambda (r) (eq r this-repl)) (cider-repls))))
(switch-to-buffer (car other-repls))
(message "There's no other REPL for the current project")))
(let* ((this-repl (cider-current-repl nil 'ensure))
(other-repl (car (seq-remove (lambda (r) (eq r this-repl)) (cider-repls nil t)))))
(if other-repl
(switch-to-buffer other-repl)
(user-error "No other REPL in current session (%s)"
(car (sesman-current-session 'CIDER))))))

(defvar cider-repl-clear-buffer-hook)

Expand Down

0 comments on commit ce38db0

Please sign in to comment.