Skip to content

Commit

Permalink
[Fix #1127] Make it possible to associate a buffer with a connection
Browse files Browse the repository at this point in the history
  • Loading branch information
bbatsov committed Aug 13, 2015
1 parent 895f455 commit 2de89b4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### New features

* [#1127](https://github.com/clojure-emacs/cider/issues/1127): Make it possible to associate a buffer with a connection (via `cider-assoc-buffer-with-connection`).
* [#1217](https://github.com/clojure-emacs/cider/issues/1217): Add new command `cider-assoc-project-with-connection` to associate a project directory with a connection.
* [#1248](https://github.com/clojure-emacs/cider/pull/1248): Add <kbd>TAB</kbd> and <kbd>RET</kbd> keys to the test-report buffer.
* [#1245](https://github.com/clojure-emacs/cider/pull/1245): New variable, `cider-ovelays-use-font-lock` controls whether results overlay should be font-locked or just use a single face.
Expand Down
39 changes: 32 additions & 7 deletions cider-interaction.el
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ should be extracted from the buffer's ns form.")
(defvar-local cider-repl-type nil
"The type of this REPL buffer, usually either \"clj\" or \"cljs\".")

(defvar-local cider-buffer-connection nil
"A connection associated with a specific buffer.
If this is set to a non-nil value it will take precedence over both
the project associated with a connection and the default connection.")

(defun cider-ensure-op-supported (op)
"Check for support of middleware op OP.
Signal an error if it is not supported."
Expand Down Expand Up @@ -482,18 +488,37 @@ such a link cannot be established automatically."
(with-current-buffer conn-buf
(setq nrepl-project-dir project-dir)))))

(defun cider-assoc-buffer-with-connection ()
"Associate the current buffer with a connection.
Useful for connections created using `cider-connect', as for them
such a link cannot be established automatically."
(interactive)
(cider-ensure-connected)
(let ((conn (completing-read "Connection: " (nrepl-connection-buffers))))
(when conn
(setq-local cider-buffer-connection conn))))

(defun cider-clear-buffer-local-connection ()
"Remove association between the current buffer and a connection."
(interactive)
(cider-ensure-connected)
(setq-local cider-buffer-connection nil))

(defun cider-find-relevant-connection ()
"Try to find the matching REPL buffer for the current Clojure source buffer.
If succesful, return the new connection buffer."
(interactive "P")
(cider-ensure-connected)
(let* ((project-directory (clojure-project-dir (cider-current-dir)))
(connection-buffer
(or
(and (= 1 (length nrepl-connection-list)) (car nrepl-connection-list))
(and project-directory
(cider-find-connection-buffer-for-project-directory project-directory)))))
connection-buffer))
(if cider-buffer-connection
cider-buffer-connection
(let* ((project-directory (clojure-project-dir (cider-current-dir)))
(connection-buffer
(or
(and (= 1 (length nrepl-connection-list)) (car nrepl-connection-list))
(and project-directory
(cider-find-connection-buffer-for-project-directory project-directory)))))
connection-buffer)))

(defun cider-switch-to-relevant-repl-buffer (&optional arg)
"Select the REPL buffer, when possible in an existing window.
Expand Down

0 comments on commit 2de89b4

Please sign in to comment.