summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--cider-client.el190
-rw-r--r--cider-debug.el2
-rw-r--r--cider-interaction.el42
-rw-r--r--cider-mode.el2
-rw-r--r--cider-repl.el2
-rw-r--r--cider-selector.el4
-rw-r--r--cider-util.el6
-rw-r--r--cider.el2
-rw-r--r--nrepl-client.el214
-rw-r--r--test/cider-selector-tests.el6
-rw-r--r--test/cider-tests.el80
12 files changed, 275 insertions, 277 deletions
diff --git a/README.md b/README.md
index 213ebcf7..02448f2f 100644
--- a/README.md
+++ b/README.md
@@ -1098,7 +1098,7 @@ against the default connection.
You can display the default nREPL connection using <kbd>C-c M-d</kbd>
and rotate the default connection using <kbd>C-c M-r</kbd>. Another
option for setting the default connection is to execute the command
-<kbd>M-x nrepl-make-connection-default</kbd> in the appropriate
+<kbd>M-x cider-make-connection-default</kbd> in the appropriate
REPL buffer.
To switch to the relevant REPL buffer based on the Clojure namespace
diff --git a/cider-client.el b/cider-client.el
index f2a74439..d704a38a 100644
--- a/cider-client.el
+++ b/cider-client.el
@@ -27,6 +27,192 @@
(require 'nrepl-client)
+;;; Connection Buffer Management
+
+(defvar cider-connections nil
+ "A list of connections.")
+
+(defun cider-default-connection (&optional no-error)
+ "The default (fallback) connection to use for nREPL interaction.
+When NO-ERROR is non-nil, don't throw an error when no connection has been
+found."
+ (or nrepl-connection-buffer
+ (car (cider-connections))
+ (unless no-error
+ (error "No nREPL connection buffer"))))
+
+(define-obsolete-function-alias 'nrepl-current-connection-buffer 'cider-default-connection "0.10")
+
+(defun cider-connections ()
+ "Return the list of connection buffers."
+ (setq cider-connections
+ (-remove (lambda (buffer)
+ (not (buffer-live-p (get-buffer buffer))))
+ cider-connections)))
+
+(defun cider-repl-buffers ()
+ "Return the list of REPL buffers.
+Purge the dead buffers from the `cider-connections' beforehand."
+ (-filter
+ (lambda (buffer)
+ (with-current-buffer buffer (derived-mode-p 'cider-repl-mode)))
+ (buffer-list)))
+
+(defun cider-make-connection-default (connection-buffer)
+ "Make the nREPL CONNECTION-BUFFER the default connection.
+Moves CONNECTION-BUFFER to the front of `cider-connections'."
+ (interactive (list nrepl-connection-buffer))
+ (if connection-buffer
+ ;; maintain the connection list in most recently used order
+ (let ((buf-name (buffer-name (get-buffer connection-buffer))))
+ (setq cider-connections
+ (cons buf-name (delq buf-name cider-connections)))
+ (cider--connections-refresh))
+ (user-error "Not in a REPL buffer")))
+
+(defun cider--close-connection-buffer (conn-buffer)
+ "Close CONN-BUFFER, removing it from `cider-connections'.
+Also close associated REPL and server buffers."
+ (let ((buffer (get-buffer conn-buffer)))
+ (setq cider-connections
+ (delq (buffer-name buffer) cider-connections))
+ (when (buffer-live-p buffer)
+ (dolist (buf `(,@(or (nrepl--get-sibling-buffers buffer)
+ (list buffer))
+ ,(buffer-local-value 'nrepl-tunnel-buffer buffer)
+ ,(buffer-local-value 'nrepl-server-buffer buffer)))
+ (when buf
+ (cider--close-buffer buf))))))
+
+
+;;; Connection Browser
+(defvar cider-connections-buffer-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map "d" #'cider-connections-make-default)
+ (define-key map "g" #'cider-connection-browser)
+ (define-key map (kbd "C-k") #'cider-connections-close-connection)
+ (define-key map (kbd "RET") #'cider-connections-goto-connection)
+ map))
+
+(define-derived-mode cider-connections-buffer-mode cider-popup-buffer-mode
+ "CIDER Connections"
+ "CIDER Connections Buffer Mode.
+\\{cider-connections-buffer-mode-map}
+\\{cider-popup-buffer-mode-map}"
+ (setq-local truncate-lines t))
+
+(defvar cider--connection-ewoc)
+(defconst cider--connection-browser-buffer-name "*cider connections*")
+
+(defun cider-connection-browser ()
+ "Open a browser buffer for nREPL connections."
+ (interactive)
+ (let ((buffer (get-buffer cider--connection-browser-buffer-name)))
+ (if buffer
+ (progn
+ (cider--connections-refresh-buffer buffer)
+ (unless (get-buffer-window buffer)
+ (select-window (display-buffer buffer))))
+ (cider--setup-connection-browser))))
+
+(define-obsolete-function-alias 'nrepl-connection-browser 'cider-connection-browser "0.10")
+
+(defun cider--connections-refresh ()
+ "Refresh the connections buffer, if the buffer exists.
+The connections buffer is determined by
+`cider--connection-browser-buffer-name'"
+ (let ((buffer (get-buffer cider--connection-browser-buffer-name)))
+ (when buffer
+ (cider--connections-refresh-buffer buffer))))
+
+(defun cider--connections-refresh-buffer (buffer)
+ "Refresh the connections BUFFER."
+ (cider--update-connections-display
+ (buffer-local-value 'cider--connection-ewoc buffer)
+ cider-connections))
+
+(defun cider--setup-connection-browser ()
+ "Create a browser buffer for nREPL connections."
+ (with-current-buffer (get-buffer-create cider--connection-browser-buffer-name)
+ (let ((ewoc (ewoc-create
+ 'cider--connection-pp
+ " Host Port Project\n")))
+ (setq-local cider--connection-ewoc ewoc)
+ (cider--update-connections-display ewoc cider-connections)
+ (setq buffer-read-only t)
+ (cider-connections-buffer-mode)
+ (display-buffer (current-buffer)))))
+
+(defun cider--connection-pp (connection)
+ "Print an nREPL CONNECTION to the current buffer."
+ (let* ((buffer-read-only nil)
+ (buffer (get-buffer connection))
+ (endpoint (buffer-local-value 'nrepl-endpoint buffer)))
+ (insert
+ (format "%s %-16s %5s %s%s"
+ (if (equal connection (car cider-connections)) "*" " ")
+ (car endpoint)
+ (prin1-to-string (cadr endpoint))
+ (or (cider--project-name
+ (buffer-local-value 'nrepl-project-dir buffer))
+ "")
+ (with-current-buffer buffer
+ (if nrepl-sibling-buffer-alist
+ (concat " " nrepl-repl-type)
+ ""))))))
+
+(defun cider--update-connections-display (ewoc connections)
+ "Update the connections EWOC to show CONNECTIONS."
+ (ewoc-filter ewoc (lambda (n) (member n connections)))
+ (let ((existing))
+ (ewoc-map (lambda (n) (setq existing (cons n existing))) ewoc)
+ (let ((added (-difference connections existing)))
+ (mapc (apply-partially 'ewoc-enter-last ewoc) added)
+ (save-excursion (ewoc-refresh ewoc)))))
+
+(defun cider--ewoc-apply-at-point (f)
+ "Apply function F to the ewoc node at point.
+F is a function of two arguments, the ewoc and the data at point."
+ (let* ((ewoc cider--connection-ewoc)
+ (node (and ewoc (ewoc-locate ewoc))))
+ (when node
+ (funcall f ewoc (ewoc-data node)))))
+
+(defun cider-connections-make-default ()
+ "Make default the connection at point in the connection browser."
+ (interactive)
+ (save-excursion
+ (cider--ewoc-apply-at-point #'cider--connections-make-default)))
+
+(defun cider--connections-make-default (ewoc data)
+ "Make the connection in EWOC specified by DATA default.
+Refreshes EWOC."
+ (interactive)
+ (cider-make-connection-default data)
+ (ewoc-refresh ewoc))
+
+(defun cider-connections-close-connection ()
+ "Close connection at point in the connection browser."
+ (interactive)
+ (cider--ewoc-apply-at-point #'cider--connections-close-connection))
+
+(defun cider--connections-close-connection (ewoc data)
+ "Close the connection in EWOC specified by DATA."
+ (nrepl-close (get-buffer data))
+ (cider--update-connections-display ewoc cider-connections))
+
+(defun cider-connections-goto-connection ()
+ "Goto connection at point in the connection browser."
+ (interactive)
+ (cider--ewoc-apply-at-point #'cider--connections-goto-connection))
+
+(defun cider--connections-goto-connection (_ewoc data)
+ "Goto the REPL for the connection in _EWOC specified by DATA."
+ (let ((buffer (buffer-local-value 'nrepl-repl-buffer (get-buffer data))))
+ (when buffer
+ (select-window (display-buffer buffer)))))
+
+
;;; Words of inspiration
(defun cider-user-first-name ()
"Find the current user's first name."
@@ -104,13 +290,13 @@ NS specifies the namespace in which to evaluate the request."
(defun cider-current-repl-buffer ()
"The current REPL buffer.
Return the REPL buffer given by using `cider-find-relevant-connection' and
-falling back to `nrepl-default-connection-buffer'.
+falling back to `cider-default-connection'.
If current buffer is a file buffer, and if the REPL has siblings, instead
return the sibling that corresponds to the current file extension. This
allows for evaluation to be properly directed to clj or cljs REPLs depending
on where they come from."
(-when-let (repl-buf (or (cider-find-relevant-connection)
- (nrepl-default-connection-buffer 'no-error)))
+ (cider-default-connection 'no-error)))
;; Take the extension of current file, or nil if there is none.
(let ((ext (file-name-extension (or (buffer-file-name) ""))))
;; Go to the "globally" active REPL buffer.
diff --git a/cider-debug.el b/cider-debug.el
index 62044882..b44195f9 100644
--- a/cider-debug.el
+++ b/cider-debug.el
@@ -329,7 +329,7 @@ In order to work properly, this mode must be activated by
;; cider-nrepl has a chance to send the next message, and so that the user
;; doesn't accidentally hit `n' between two messages (thus editing the code).
(-when-let (proc (unless nrepl-ongoing-sync-request
- (get-buffer-process (nrepl-default-connection-buffer))))
+ (get-buffer-process (cider-default-connection))))
;; This is for the `:done' sent in reply to the debug-input we provided.
(when (accept-process-output proc 0.2)
;; This is for actually waiting for the next message.
diff --git a/cider-interaction.el b/cider-interaction.el
index fc8d8fb7..eb181a77 100644
--- a/cider-interaction.el
+++ b/cider-interaction.el
@@ -304,7 +304,7 @@ Signal an error if it is not supported."
;;; Connection info
(defun cider--java-version ()
"Retrieve the underlying connection's Java version."
- (with-current-buffer (nrepl-default-connection-buffer)
+ (with-current-buffer (cider-default-connection)
(when nrepl-versions
(-> nrepl-versions
(nrepl-dict-get "java")
@@ -312,7 +312,7 @@ Signal an error if it is not supported."
(defun cider--clojure-version ()
"Retrieve the underlying connection's Clojure version."
- (with-current-buffer (nrepl-default-connection-buffer)
+ (with-current-buffer (cider-default-connection)
(when nrepl-versions
(-> nrepl-versions
(nrepl-dict-get "clojure")
@@ -320,7 +320,7 @@ Signal an error if it is not supported."
(defun cider--nrepl-version ()
"Retrieve the underlying connection's nREPL version."
- (with-current-buffer (nrepl-default-connection-buffer)
+ (with-current-buffer (cider-default-connection)
(when nrepl-versions
(-> nrepl-versions
(nrepl-dict-get "nrepl")
@@ -373,7 +373,7 @@ endpoint and Clojure version."
(if nrepl-sibling-buffer-alist
(upcase (concat cider-repl-type " "))
"")
- (or (nrepl--project-name nrepl-project-dir) "<no project>")
+ (or (cider--project-name nrepl-project-dir) "<no project>")
(car nrepl-endpoint)
(cadr nrepl-endpoint)
(cider--java-version)
@@ -387,7 +387,7 @@ With a prefix argument SHOW-DEFAULT it will display info about the
default connection."
(interactive "P")
(message (cider--connection-info (if show-default
- (nrepl-default-connection-buffer)
+ (cider-default-connection)
(cider-current-repl-buffer)))))
(define-obsolete-function-alias 'cider-display-current-connection-info 'cider-display-connection-info "0.10")
@@ -396,10 +396,10 @@ default connection."
"Rotate and display the default nREPL connection."
(interactive)
(cider-ensure-connected)
- (setq nrepl-connection-list
- (append (cdr nrepl-connection-list)
- (list (car nrepl-connection-list))))
- (message "Default nREPL connection:" (cider--connection-info (car nrepl-connection-list))))
+ (setq cider-connections
+ (append (cdr cider-connections)
+ (list (car cider-connections))))
+ (message "Default nREPL connection:" (cider--connection-info (car cider-connections))))
(define-obsolete-function-alias 'cider-rotate-connection 'cider-rotate-default-connection "0.10")
@@ -426,8 +426,8 @@ Buffer names changed are cider-repl and nrepl-server."
(rename-buffer new-repl-buffer-name)
(setq-local nrepl-repl-buffer new-repl-buffer-name)
(setq-local nrepl-connection-buffer new-repl-buffer-name)
- (setq nrepl-connection-list
- (cons new-repl-buffer-name (cdr nrepl-connection-list)))
+ (setq cider-connections
+ (cons new-repl-buffer-name (cdr cider-connections)))
(when nrepl-server-buffer
(let ((new-server-buffer-name (nrepl-format-buffer-name-template
nrepl-server-buffer-name-template designation)))
@@ -495,7 +495,7 @@ the buffer should appear.
With a prefix argument SET-NAMESPACE, sets the namespace in the REPL buffer to
that of the namespace in the Clojure source buffer."
(interactive "P")
- (cider--switch-to-repl-buffer (nrepl-default-connection-buffer) set-namespace))
+ (cider--switch-to-repl-buffer (cider-default-connection) set-namespace))
(define-obsolete-function-alias 'cider-switch-to-current-repl-buffer 'cider-switch-to-default-repl-buffer "0.10")
@@ -512,7 +512,7 @@ is ambiguity, therefore nil is returned."
(not
(with-current-buffer (get-buffer conn)
nrepl-project-dir)))
- nrepl-connection-list)
+ cider-connections)
(let ((matching-connections
(-filter
(lambda (conn)
@@ -521,7 +521,7 @@ is ambiguity, therefore nil is returned."
(when conn-proj-dir
(equal (file-truename project-directory)
(file-truename conn-proj-dir)))))
- nrepl-connection-list)))
+ cider-connections)))
(when (= 1 (length matching-connections))
(car matching-connections)))))
@@ -532,7 +532,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: " (nrepl-connection-buffers))))
+ (let ((conn-buf (or connection (completing-read "Connection: " (cider-connections))))
(project-dir (or project (read-directory-name "Project: " nil (clojure-project-dir)))))
(when conn-buf
(with-current-buffer conn-buf
@@ -545,7 +545,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: " (nrepl-connection-buffers))))
+ (let ((conn (completing-read "Connection: " (cider-connections))))
(when conn
(setq-local cider-buffer-connection conn))))
@@ -565,7 +565,7 @@ If succesful, return the new connection buffer."
(let* ((project-directory (clojure-project-dir (cider-current-dir)))
(connection-buffer
(or
- (and (= 1 (length nrepl-connection-list)) (car nrepl-connection-list))
+ (and (= 1 (length cider-connections)) (car cider-connections))
(and project-directory
(cider-find-connection-buffer-for-project-directory project-directory)))))
connection-buffer)))
@@ -588,7 +588,7 @@ of the namespace in the Clojure source buffer."
(let ((connection-buffer (cider-find-relevant-connection)))
(if connection-buffer
(cider--switch-to-repl-buffer connection-buffer set-namespace)
- (cider--switch-to-repl-buffer (nrepl-default-connection-buffer) set-namespace)
+ (cider--switch-to-repl-buffer (cider-default-connection) set-namespace)
(message "Could not determine relevant nREPL connection, using: %s"
(cider--connection-info (cider-current-repl-buffer))))))
@@ -1972,7 +1972,7 @@ If invoked with a prefix ARG eval the expression after inserting it."
(defun cider-connected-p ()
"Return t if CIDER is currently connected, nil otherwise."
- (nrepl-default-connection-buffer 'no-error))
+ (cider-default-connection 'no-error))
(defun cider-ensure-connected ()
"Ensure there is a cider connection present, otherwise
@@ -2380,7 +2380,7 @@ and all ancillary CIDER buffers."
(when (y-or-n-p "Are you sure you want to quit the current CIDER connection? ")
(if quit-all
(progn
- (dolist (connection nrepl-connection-list)
+ (dolist (connection cider-connections)
(cider--quit-connection connection))
(message "All active nREPL connections were closed"))
(cider--quit-connection (cider-current-repl-buffer)))
@@ -2406,7 +2406,7 @@ and all ancillary CIDER buffers."
If RESTART-ALL is t, then restarts all connections."
(interactive "P")
(if restart-all
- (dolist (conn nrepl-connection-list)
+ (dolist (conn cider-connections)
(cider--restart-connection conn))
(cider--restart-connection (cider-current-repl-buffer))))
diff --git a/cider-mode.el b/cider-mode.el
index f9d621e8..1f049f5c 100644
--- a/cider-mode.el
+++ b/cider-mode.el
@@ -51,7 +51,7 @@ Info contains project name and host:port endpoint."
(concat cider-repl-type ":"))
(when cider-mode-line-show-connection
(format "%s@%s:%s"
- (or (nrepl--project-name nrepl-project-dir) "<no project>")
+ (or (cider--project-name nrepl-project-dir) "<no project>")
(pcase (car nrepl-endpoint)
("localhost" "")
(x x))
diff --git a/cider-repl.el b/cider-repl.el
index 7bea4eee..422d89cb 100644
--- a/cider-repl.el
+++ b/cider-repl.el
@@ -160,7 +160,7 @@ Currently its only purpose is to facilitate `cider-repl-clear-buffer'.")
(defun cider-repl-buffer-name (&optional project-dir host port)
"Generate a REPL buffer name based on current connection buffer.
PROJECT-DIR, HOST and PORT are as in `nrepl-make-buffer-name'."
- (with-current-buffer (or (nrepl-default-connection-buffer 'no-error)
+ (with-current-buffer (or (cider-default-connection 'no-error)
(current-buffer))
(nrepl-make-buffer-name nrepl-repl-buffer-name-template project-dir host port)))
diff --git a/cider-selector.el b/cider-selector.el
index 451e856a..6c886d25 100644
--- a/cider-selector.el
+++ b/cider-selector.el
@@ -138,8 +138,8 @@ is chosen. The returned buffer is selected with
(def-cider-selector-method ?n
"Connections browser buffer."
- (nrepl-connection-browser)
- nrepl--connection-browser-buffer-name)
+ (cider-connection-browser)
+ cider--connection-browser-buffer-name)
(def-cider-selector-method ?m
"*nrepl-messages* buffer."
diff --git a/cider-util.el b/cider-util.el
index 73363c7f..b637e29e 100644
--- a/cider-util.el
+++ b/cider-util.el
@@ -182,6 +182,12 @@ to."
(browse-url (concat "https://github.com/clojure-emacs/cider#"
section-id)))))
+(defun cider--project-name (dir)
+ "Extracts a project name from DIR, possibly nil.
+The project name is the final component of DIR if not nil."
+ (when dir
+ (file-name-nondirectory (directory-file-name dir))))
+
(provide 'cider-util)
;;; cider-util.el ends here
diff --git a/cider.el b/cider.el
index fdd126eb..0d72ac28 100644
--- a/cider.el
+++ b/cider.el
@@ -274,7 +274,7 @@ Create REPL buffer and start an nREPL client connection."
(y-or-n-p "Do you want to associate the new connection with a local project? "))
(cider-assoc-project-with-connection
nil
- (nrepl-default-connection-buffer))))))
+ (cider-default-connection))))))
(defun cider-current-host ()
"Retrieve the current host."
diff --git a/nrepl-client.el b/nrepl-client.el
index 0e7c6fc5..715534d2 100644
--- a/nrepl-client.el
+++ b/nrepl-client.el
@@ -205,7 +205,7 @@ it is not. The name will also include the connection port if
If optional DUP-OK is non-nil, the returned buffer is not \"uniquified\" by
`generate-new-buffer-name'."
- (let* ((project-name (nrepl--project-name (or project-dir nrepl-project-dir)))
+ (let* ((project-name (cider--project-name (or project-dir nrepl-project-dir)))
(nrepl-proj-port (or port (cadr nrepl-endpoint)))
(name (nrepl-format-buffer-name-template
buffer-name-template
@@ -254,7 +254,7 @@ Bind the value of the provided KEYS and execute BODY."
(defun nrepl-op-supported-p (op)
"Return t iff the given operation OP is supported by nREPL server."
- (with-current-buffer (nrepl-default-connection-buffer)
+ (with-current-buffer (cider-default-connection)
(and nrepl-ops (nrepl-dict-get nrepl-ops op))))
(defun nrepl-local-host-p (host)
@@ -269,7 +269,7 @@ and has no process, return it. If the process is alive, ask the user for
confirmation and return 'new/nil for y/n answer respectively. If other
REPL buffers with dead process exist, ask the user if any of those should
be reused."
- (let* ((repl-buffs (-map #'buffer-name (nrepl-repl-buffers)))
+ (let* ((repl-buffs (-map #'buffer-name (cider-repl-buffers)))
(exact-buff (-first (lambda (buff)
(with-current-buffer buff
(or (and endpoint (equal endpoint nrepl-endpoint))
@@ -795,7 +795,7 @@ process."
nrepl-pending-requests (make-hash-table :test 'equal)
nrepl-completed-requests (make-hash-table :test 'equal)))
- (nrepl-make-connection-default client-buf)
+ (cider-make-connection-default client-buf)
(with-current-buffer client-buf
(nrepl--init-client-sessions client-proc)
(nrepl--init-capabilities client-buf))
@@ -837,10 +837,10 @@ values of *1, *2, etc."
(defun nrepl-close (connection-buffer)
"Close the nREPL connection for CONNECTION-BUFFER."
- (interactive (list (nrepl-default-connection-buffer)))
- (nrepl--close-connection-buffer connection-buffer)
+ (interactive (list (cider-default-connection)))
+ (cider--close-connection-buffer connection-buffer)
(run-hooks 'nrepl-disconnected-hook)
- (nrepl--connections-refresh))
+ (cider--connections-refresh))
;;; Client: Response Handling
@@ -935,7 +935,7 @@ Handles only stdout and stderr responses."
(defun nrepl-next-request-id ()
"Return the next request id."
- (with-current-buffer (nrepl-default-connection-buffer)
+ (with-current-buffer (cider-default-connection)
(number-to-string (cl-incf nrepl-request-counter))))
(defun nrepl-send-request (request callback)
@@ -947,7 +947,7 @@ REQUEST is a pair list of the form (\"op\" \"operation\" \"par1-name\"
(request (cons 'dict (lax-plist-put request "id" id)))
(message (nrepl-bencode request)))
(nrepl-log-message (cons '---> (cdr request)))
- (with-current-buffer (nrepl-default-connection-buffer)
+ (with-current-buffer (cider-default-connection)
(puthash id callback nrepl-pending-requests)
(process-send-string nil message))))
@@ -993,7 +993,7 @@ sign of user input, so as not to hang the interface."
(-when-let (id (nrepl-dict-get response "id"))
;; FIXME: This should go away eventually when we get rid of
;; pending-request hash table
- (with-current-buffer (nrepl-default-connection-buffer)
+ (with-current-buffer (cider-default-connection)
(remhash id nrepl-pending-requests)))
response)))
@@ -1254,12 +1254,6 @@ The default buffer name is *nrepl-messages*."
(nrepl-messages-mode)
buffer))))
-
-;;; Connection Buffer Management
-
-(defvar nrepl-connection-list nil
- "A list of connections.")
-
(defun nrepl-create-client-buffer-default (endpoint)
"Create an nREPL client process buffer.
ENDPOINT is a plist returned by `nrepl-connect'."
@@ -1272,194 +1266,6 @@ ENDPOINT is a plist returned by `nrepl-connect'."
(setq-local kill-buffer-query-functions nil))
buffer))
-(defun nrepl-default-connection-buffer (&optional no-error)
- "The default (fallback) connection to use for nREPL interaction.
-When NO-ERROR is non-nil, don't throw an error when no connection has been
-found."
- (or nrepl-connection-buffer
- (car (nrepl-connection-buffers))
- (unless no-error
- (error "No nREPL connection buffer"))))
-
-(define-obsolete-function-alias 'nrepl-current-connection-buffer 'nrepl-default-connection-buffer "0.10")
-
-(defun nrepl-connection-buffers ()
- "Return the list of connection buffers."
- (setq nrepl-connection-list
- (-remove (lambda (buffer)
- (not (buffer-live-p (get-buffer buffer))))
- nrepl-connection-list)))
-
-(defun nrepl-repl-buffers ()
- "Return the list of REPL buffers.
-Purge the dead buffers from the `nrepl-connection-list' beforehand."
- (-filter
- (lambda (buffer)
- (with-current-buffer buffer (derived-mode-p 'cider-repl-mode)))
- (buffer-list)))
-
-(defun nrepl-make-connection-default (connection-buffer)
- "Make the nREPL CONNECTION-BUFFER the default connection.
-Moves CONNECTION-BUFFER to the front of `nrepl-connection-list'."
- (interactive (list nrepl-connection-buffer))
- (if connection-buffer
- ;; maintain the connection list in most recently used order
- (let ((buf-name (buffer-name (get-buffer connection-buffer))))
- (setq nrepl-connection-list
- (cons buf-name (delq buf-name nrepl-connection-list)))
- (nrepl--connections-refresh))
- (user-error "Not in a REPL buffer")))
-
-(defun nrepl--close-connection-buffer (conn-buffer)
- "Close CONN-BUFFER, removing it from `nrepl-connection-list'.
-Also close associated REPL and server buffers."
- (let ((buffer (get-buffer conn-buffer)))
- (setq nrepl-connection-list
- (delq (buffer-name buffer) nrepl-connection-list))
- (when (buffer-live-p buffer)
- (dolist (buf `(,@(or (nrepl--get-sibling-buffers buffer)
- (list buffer))
- ,(buffer-local-value 'nrepl-tunnel-buffer buffer)
- ,(buffer-local-value 'nrepl-server-buffer buffer)))
- (when buf
- (cider--close-buffer buf))))))
-
-
-;;; Connection Browser
-
-;; FIXME: Naming conventions are pretty messy here. Some
-;; interactive commands are named with "--". nrepl--project-name` is pretty
-;; often used across cider, so it's not very internal.
-(defvar nrepl-connections-buffer-mode-map
- (let ((map (make-sparse-keymap)))
- (define-key map "d" #'nrepl-connections-make-default)
- (define-key map "g" #'nrepl-connection-browser)
- (define-key map (kbd "C-k") #'nrepl-connections-close-connection)
- (define-key map (kbd "RET") #'nrepl-connections-goto-connection)
- map))
-
-(define-derived-mode nrepl-connections-buffer-mode cider-popup-buffer-mode
- "nREPL-Connections"
- "nREPL Connections Buffer Mode.
-\\{nrepl-connections-buffer-mode-map}
-\\{cider-popup-buffer-mode-map}"
- (setq-local truncate-lines t))
-
-(defvar nrepl--connection-ewoc)
-(defconst nrepl--connection-browser-buffer-name "*nrepl-connections*")
-
-(defun nrepl-connection-browser ()
- "Open a browser buffer for nREPL connections."
- (interactive)
- (let ((buffer (get-buffer nrepl--connection-browser-buffer-name)))
- (if buffer
- (progn
- (nrepl--connections-refresh-buffer buffer)
- (unless (get-buffer-window buffer)
- (select-window (display-buffer buffer))))
- (nrepl--setup-connection-browser))))
-
-(defun nrepl--connections-refresh ()
- "Refresh the connections buffer, if the buffer exists.
-The connections buffer is determined by
-`nrepl--connection-browser-buffer-name'"
- (let ((buffer (get-buffer nrepl--connection-browser-buffer-name)))
- (when buffer
- (nrepl--connections-refresh-buffer buffer))))
-
-(defun nrepl--connections-refresh-buffer (buffer)
- "Refresh the connections BUFFER."
- (nrepl--update-connections-display
- (buffer-local-value 'nrepl--connection-ewoc buffer)
- nrepl-connection-list))
-
-(defun nrepl--setup-connection-browser ()
- "Create a browser buffer for nREPL connections."
- (with-current-buffer (get-buffer-create nrepl--connection-browser-buffer-name)
- (let ((ewoc (ewoc-create
- 'nrepl--connection-pp
- " Host Port Project\n")))
- (setq-local nrepl--connection-ewoc ewoc)
- (nrepl--update-connections-display ewoc nrepl-connection-list)
- (setq buffer-read-only t)
- (nrepl-connections-buffer-mode)
- (display-buffer (current-buffer)))))
-
-(defun nrepl--connection-pp (connection)
- "Print an nREPL CONNECTION to the current buffer."
- (let* ((buffer-read-only nil)
- (buffer (get-buffer connection))
- (endpoint (buffer-local-value 'nrepl-endpoint buffer)))
- (insert
- (format "%s %-16s %5s %s%s"
- (if (equal connection (car nrepl-connection-list)) "*" " ")
- (car endpoint)
- (prin1-to-string (cadr endpoint))
- (or (nrepl--project-name
- (buffer-local-value 'nrepl-project-dir buffer))
- "")
- (with-current-buffer buffer
- (if nrepl-sibling-buffer-alist
- (concat " " cider-repl-type)
- ""))))))
-
-(defun nrepl--project-name (dir)
- "Extracts a project name from DIR, possibly nil.
-The project name is the final component of DIR if not nil."
- (when dir
- (file-name-nondirectory (directory-file-name dir))))
-
-(defun nrepl--update-connections-display (ewoc connections)
- "Update the connections EWOC to show CONNECTIONS."
- (ewoc-filter ewoc (lambda (n) (member n connections)))
- (let ((existing))
- (ewoc-map (lambda (n) (setq existing (cons n existing))) ewoc)
- (let ((added (-difference connections existing)))
- (mapc (apply-partially 'ewoc-enter-last ewoc) added)
- (save-excursion (ewoc-refresh ewoc)))))
-
-(defun nrepl--ewoc-apply-at-point (f)
- "Apply function F to the ewoc node at point.
-F is a function of two arguments, the ewoc and the data at point."
- (let* ((ewoc nrepl--connection-ewoc)
- (node (and ewoc (ewoc-locate ewoc))))
- (when node
- (funcall f ewoc (ewoc-data node)))))
-
-(defun nrepl-connections-make-default ()
- "Make default the connection at point in the connection browser."
- (interactive)
- (save-excursion
- (nrepl--ewoc-apply-at-point #'nrepl--connections-make-default)))
-
-(defun nrepl--connections-make-default (ewoc data)
- "Make the connection in EWOC specified by DATA default.
-Refreshes EWOC."
- (interactive)
- (nrepl-make-connection-default data)
- (ewoc-refresh ewoc))
-
-(defun nrepl-connections-close-connection ()
- "Close connection at point in the connection browser."
- (interactive)
- (nrepl--ewoc-apply-at-point #'nrepl--connections-close-connection))
-
-(defun nrepl--connections-close-connection (ewoc data)
- "Close the connection in EWOC specified by DATA."
- (nrepl-close (get-buffer data))
- (nrepl--update-connections-display ewoc nrepl-connection-list))
-
-(defun nrepl-connections-goto-connection ()
- "Goto connection at point in the connection browser."
- (interactive)
- (nrepl--ewoc-apply-at-point #'nrepl--connections-goto-connection))
-
-(defun nrepl--connections-goto-connection (_ewoc data)
- "Goto the REPL for the connection in _EWOC specified by DATA."
- (let ((buffer (buffer-local-value 'nrepl-repl-buffer (get-buffer data))))
- (when buffer
- (select-window (display-buffer buffer)))))
-
(provide 'nrepl-client)
;;; nrepl-client.el ends here
diff --git a/test/cider-selector-tests.el b/test/cider-selector-tests.el
index ebc4ef35..61046faa 100644
--- a/test/cider-selector-tests.el
+++ b/test/cider-selector-tests.el
@@ -10,12 +10,12 @@
(with-temp-buffer
(let ((b1 (current-buffer)))
(setq-local cider-endpoint '("123.123.123.123" 4006))
- (let ((nrepl-connection-list (list (buffer-name b1))))
- (nrepl-connection-browser)
+ (let ((cider-connections (list (buffer-name b1))))
+ (cider-connection-browser)
(with-temp-buffer ;; switch to another buffer
(cider-invoke-selector-method-by-key ?n)
(should (equal (current-buffer)
- (get-buffer nrepl--connection-browser-buffer-name))))))))
+ (get-buffer cider--connection-browser-buffer-name))))))))
(ert-deftest test-cider-selector-c ()
(with-temp-buffer
diff --git a/test/cider-tests.el b/test/cider-tests.el
index 7c72b672..5a4105e2 100644
--- a/test/cider-tests.el
+++ b/test/cider-tests.el
@@ -164,52 +164,52 @@
,@body
(mapc 'kill-buffer (list ,@buffer-names))))))
-(ert-deftest test-nrepl-make-connection-default ()
- (let ((connections (nrepl-connection-buffers)))
+(ert-deftest test-cider-make-connection-default ()
+ (let ((connections (cider-connections)))
(cider-test-with-buffers
(a b)
(should (get-buffer a))
(should (get-buffer b))
;; Add one connection
- (nrepl-make-connection-default a)
+ (cider-make-connection-default a)
(should (equal (append (list (buffer-name a)) connections)
- (nrepl-connection-buffers)))
- (should (equal (buffer-name a) (nrepl-default-connection-buffer)))
+ (cider-connections)))
+ (should (equal (buffer-name a) (cider-default-connection)))
;; Add second connection
- (nrepl-make-connection-default b)
+ (cider-make-connection-default b)
(should (equal (append (list (buffer-name b) (buffer-name a)) connections)
- (nrepl-connection-buffers)))
- (should (equal (buffer-name b) (nrepl-default-connection-buffer))))))
+ (cider-connections)))
+ (should (equal (buffer-name b) (cider-default-connection))))))
-(ert-deftest test-nrepl-connection-buffers ()
- (let ((connections (nrepl-connection-buffers)))
+(ert-deftest test-cider-connections ()
+ (let ((connections (cider-connections)))
(cider-test-with-buffers
(a b)
- (nrepl-make-connection-default a)
- (nrepl-make-connection-default b)
+ (cider-make-connection-default a)
+ (cider-make-connection-default b)
;; killing a buffer should see it purged from the connection list
(kill-buffer a)
(should (equal (append (list (buffer-name b)) connections)
- (nrepl-connection-buffers)))
- (should (equal (buffer-name b) (nrepl-default-connection-buffer))))))
+ (cider-connections)))
+ (should (equal (buffer-name b) (cider-default-connection))))))
(ert-deftest test-cider-rotate-connecton-buffer ()
(noflet ((nrepl--connection-info (connection-buffer-name)))
(cider-test-with-buffers
(a b c)
- (let ((nrepl-connection-list
+ (let ((cider-connections
(list (buffer-name a) (buffer-name b) (buffer-name c)))
(nrepl-connection-buffer nil))
(noflet ((cider--java-version () "")
(cider--clojure-version () "")
(cider--nrepl-version () ""))
- (should (equal (buffer-name a) (nrepl-default-connection-buffer)))
+ (should (equal (buffer-name a) (cider-default-connection)))
(cider-rotate-default-connection)
- (should (equal (buffer-name b) (nrepl-default-connection-buffer)))
+ (should (equal (buffer-name b) (cider-default-connection)))
(cider-rotate-default-connection)
- (should (equal (buffer-name c) (nrepl-default-connection-buffer)))
+ (should (equal (buffer-name c) (cider-default-connection)))
(cider-rotate-default-connection)
- (should (equal (buffer-name a) (nrepl-default-connection-buffer))))))))
+ (should (equal (buffer-name a) (cider-default-connection))))))))
(ert-deftest test-cider--connection-info ()
(with-temp-buffer
@@ -231,17 +231,17 @@
"<no project>@localhost:4005 (Java 1.7, Clojure 1.5.1, nREPL 0.2.1)")))))
(ert-deftest test-nrepl-close ()
- (let ((connections (nrepl-connection-buffers)))
+ (let ((connections (cider-connections)))
(cider-test-with-buffers
(a b)
- (nrepl-make-connection-default a)
- (nrepl-make-connection-default b)
+ (cider-make-connection-default a)
+ (cider-make-connection-default b)
;; closing a buffer should see it removed from the connection list
(nrepl-close a)
(should (not (buffer-live-p a)))
(should (equal (append (list (buffer-name b)) connections)
- (nrepl-connection-buffers)))
- (should (equal (buffer-name b) (nrepl-default-connection-buffer))))))
+ (cider-connections)))
+ (should (equal (buffer-name b) (cider-default-connection))))))
(ert-deftest test-cider--var-namespace ()
(should (string= (cider--var-namespace "#'a/var-two") "a"))
@@ -275,26 +275,26 @@
(with-temp-buffer
(let ((b2 (current-buffer)))
(setq-local nrepl-endpoint '("123.123.123.123" 4006))
- (let ((nrepl-connection-list
+ (let ((cider-connections
(list (buffer-name b1) (buffer-name b2))))
- (nrepl-connection-browser)
- (with-current-buffer "*nrepl-connections*"
+ (cider-connection-browser)
+ (with-current-buffer "*cider connections*"
(should (equal " Host Port Project
* localhost 4005 proj
123.123.123.123 4006 \n\n"
(buffer-string)))
(goto-char 80) ; somewhere in the second connection listed
- (nrepl-connections-make-default)
- (should (equal (buffer-name b2) (car nrepl-connection-list)))
+ (cider-connections-make-default)
+ (should (equal (buffer-name b2) (car cider-connections)))
(should (equal " Host Port Project
localhost 4005 proj
* 123.123.123.123 4006 \n\n"
(buffer-string)))
(goto-char 80) ; somewhere in the second connection listed
- (nrepl-connections-close-connection)
- (should (equal (list (buffer-name b1)) nrepl-connection-list))
+ (cider-connections-close-connection)
+ (should (equal (list (buffer-name b1)) cider-connections))
(should (equal " Host Port Project
* localhost 4005 proj\n\n"
@@ -303,10 +303,10 @@
(let ((b3 (current-buffer)))
(with-current-buffer b1
(setq-local nrepl-repl-buffer b3))
- (with-current-buffer "*nrepl-connections*"
- (nrepl-connections-goto-connection)
+ (with-current-buffer "*cider connections*"
+ (cider-connections-goto-connection)
(should (equal b3 (current-buffer))))))
- (kill-buffer "*nrepl-connections*"))))))))
+ (kill-buffer "*cider connections*"))))))))
(ert-deftest test-nrepl-format-buffer-name-template ()
(should (equal "*template designation-foo*"
@@ -403,14 +403,14 @@
(with-temp-buffer
(setq-local nrepl-endpoint '("localhost" 1))
(let ((b1 (current-buffer)))
- (let ((nrepl-connection-list (list (buffer-name b1))))
+ (let ((cider-connections (list (buffer-name b1))))
(should
(equal (cider-repl-buffer-name) "*cider-repl localhost*"))))))
(ert-deftest test-cider-clojure-buffer-name-w/project ()
(with-temp-buffer
(let ((b1 (current-buffer)))
- (let ((nrepl-connection-list (list (buffer-name b1)))
+ (let ((cider-connections (list (buffer-name b1)))
(nrepl-project-dir "/a/test/directory/project"))
(should
(equal (cider-repl-buffer-name) "*cider-repl project*"))))))
@@ -425,7 +425,7 @@
(with-temp-buffer
(let* ((connection-buffer (current-buffer))
(repl-buffer connection-buffer)
- (nrepl-connection-list (list (buffer-name connection-buffer))))
+ (cider-connections (list (buffer-name connection-buffer))))
(with-current-buffer connection-buffer
(setq-local nrepl-repl-buffer (buffer-name repl-buffer))
(setq-local nrepl-server-buffer (buffer-name server-buffer)))
@@ -441,7 +441,7 @@
(let ((server-buffer (current-buffer)))
(with-temp-buffer
(let* ((connection-buffer (current-buffer))
- (nrepl-connection-list (list (buffer-name connection-buffer))))
+ (cider-connections (list (buffer-name connection-buffer))))
(with-temp-buffer
(rename-buffer "*cider-repl bob*") ;; Make a buffer that already has the designation
(with-temp-buffer
@@ -464,7 +464,7 @@
(ert-deftest cider-extract-designation-from-current-repl-buffer ()
(with-temp-buffer
(let* ((connection-buffer (current-buffer))
- (nrepl-connection-list (list (buffer-name connection-buffer))))
+ (cider-connections (list (buffer-name connection-buffer))))
(with-temp-buffer
(let ((repl-buffer (current-buffer)))
(rename-buffer "*cider-repl bob*")
@@ -476,7 +476,7 @@
(ert-deftest cider-extract-designation-from-current-repl-buffer-no-designation ()
(with-temp-buffer
(let* ((connection-buffer (current-buffer))
- (nrepl-connection-list (list (buffer-name connection-buffer))))
+ (cider-connections (list (buffer-name connection-buffer))))
(with-temp-buffer
(let ((repl-buffer (current-buffer)))
(rename-buffer "*cider-repl*")