summaryrefslogtreecommitdiff
path: root/cider-client.el
diff options
context:
space:
mode:
authorBozhidar Batsov <bozhidar@batsov.com>2015-10-17 14:59:35 +0300
committerBozhidar Batsov <bozhidar@batsov.com>2015-10-17 14:59:35 +0300
commit9f91f3bb0ae832d0021c0e149f1532489cc79f60 (patch)
tree4f8152f8de4cf6d095ca38d74dc43b22390572ca /cider-client.el
parentd2abe0ff3208d0d3a7e2c78ee0a987068bd541c3 (diff)
[Fix #1300] Make it possible to quickly replicate an existing nREPL connection
Diffstat (limited to 'cider-client.el')
-rw-r--r--cider-client.el39
1 files changed, 37 insertions, 2 deletions
diff --git a/cider-client.el b/cider-client.el
index 19b6c712..4380be98 100644
--- a/cider-client.el
+++ b/cider-client.el
@@ -139,6 +139,10 @@ connections are returned, instead of just the most recent."
cider-connections
(car cider-connections)))))
+(defun cider-read-connection (prompt)
+ "Completing read for connections using PROMPT."
+ (get-buffer (completing-read prompt (mapcar #'buffer-name (cider-connections)))))
+
(defun cider-assoc-project-with-connection (&optional project connection)
"Associate a Clojure PROJECT with an nREPL CONNECTION.
@@ -146,7 +150,7 @@ Useful for connections created using `cider-connect', as for them
such a link cannot be established automatically."
(interactive)
(cider-ensure-connected)
- (let ((conn-buf (or connection (completing-read "Connection: " (mapcar #'buffer-name (cider-connections)))))
+ (let ((conn-buf (or connection (cider-read-connection "Connection: ")))
(project-dir (or project (read-directory-name "Project directory: " nil (clojure-project-dir) nil (clojure-project-dir)))))
(when conn-buf
(with-current-buffer conn-buf
@@ -159,7 +163,7 @@ 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: " (cider-connections))))
+ (let ((conn (cider-read-connection "Connection: ")))
(when conn
(setq-local cider-connections (list conn)))))
@@ -752,6 +756,26 @@ endpoint and Clojure version."
(cider--clojure-version)
(cider--nrepl-version))))
+(defun cider--connection-properties (conn-buffer)
+ "Extract the essential properties of CONN-BUFFER."
+ (with-current-buffer conn-buffer
+ (list
+ :host (car nrepl-endpoint)
+ :port (cadr nrepl-endpoint)
+ :project-dir nrepl-project-dir)))
+
+(defun cider--connection-host (conn-buffer)
+ "Get CONN-BUFFER's host."
+ (plist-get (cider--connection-properties conn-buffer) :host))
+
+(defun cider--connection-port (conn-buffer)
+ "Get CONN-BUFFER's port."
+ (plist-get (cider--connection-properties conn-buffer) :port))
+
+(defun cider--connection-project-dir (conn-buffer)
+ "Get CONN-BUFFER's project dir."
+ (plist-get (cider--connection-properties conn-buffer) :project-dir))
+
(defun cider-display-connection-info (&optional show-default)
"Display information about the current connection.
@@ -774,6 +798,17 @@ default connection."
(message "Default nREPL connection: %s"
(cider--connection-info (car cider-connections))))
+(defun cider-replicate-connection (&optional conn)
+ "Establish a new connection based on an existing connection.
+The new connection will use the same host and port.
+If CONN is not provided the user will be prompted to select a connection."
+ (interactive)
+ (let* ((conn (or conn (cider-read-connection "Select connection to replicate: ")))
+ (host (cider--connection-host conn))
+ (port (cider--connection-port conn))
+ (project-dir (cider--connection-project-dir conn)))
+ (cider-connect host port project-dir)))
+
(define-obsolete-function-alias 'cider-rotate-connection 'cider-rotate-default-connection "0.10")
(defun cider-extract-designation-from-current-repl-buffer ()
"Extract the designation from the cider repl buffer name."