|
70 | 70 | Normally it won't be used, unless `pkg-info' fails to extract the
|
71 | 71 | version from the CIDER package or library.")
|
72 | 72 |
|
| 73 | +(defcustom cider-known-endpoints nil |
| 74 | + "Specify a list of custom endpoints where each endpoint is a list. |
| 75 | +For example: '((\"label\" \"host\" \"port\")). |
| 76 | +The label is optional so that '(\"host\" \"port\") will suffice. |
| 77 | +This variable is used by the CIDER command." |
| 78 | + :type 'list |
| 79 | + :group 'cider) |
| 80 | + |
73 | 81 | ;;;###autoload
|
74 | 82 | (defun cider-version ()
|
75 | 83 | "Display CIDER's version."
|
@@ -104,12 +112,35 @@ start the server."
|
104 | 112 | (setq nrepl-project-dir project-dir))
|
105 | 113 | (message "Starting nREPL server...")))))
|
106 | 114 |
|
| 115 | +(defun cider-known-endpoint-candidates () |
| 116 | + "Known endpoint candidates for establishing an nREPL connection. |
| 117 | +A default will be included consisting of `nrepl-default-host' and |
| 118 | +`nrepl-default-port'." |
| 119 | + (-distinct |
| 120 | + (mapcar (lambda (endpoint) |
| 121 | + (mapconcat 'identity endpoint " ")) |
| 122 | + (cons (list (nrepl-current-host) (nrepl-default-port)) |
| 123 | + cider-known-endpoints)))) |
| 124 | + |
| 125 | +(defun cider-select-known-endpoint () |
| 126 | + "Select an endpoint from known endpoints. |
| 127 | +The returned endpoint has the label removed." |
| 128 | + (let ((selected-endpoint (split-string |
| 129 | + (ido-completing-read |
| 130 | + "Host: " (cider-known-endpoint-candidates))))) |
| 131 | + (if (= 3 (length selected-endpoint)) |
| 132 | + (cdr selected-endpoint) |
| 133 | + selected-endpoint))) |
| 134 | + |
107 | 135 | ;;;###autoload
|
108 | 136 | (defun cider (host port)
|
109 | 137 | "Connect to an nREPL server identified by HOST and PORT."
|
110 |
| - (interactive (list (read-string "Host: " (nrepl-current-host) nil (nrepl-current-host)) |
111 |
| - (string-to-number (let ((port (nrepl-default-port))) |
112 |
| - (read-string "Port: " port nil port))))) |
| 138 | + (interactive (let ((known-endpoint (when cider-known-endpoints |
| 139 | + (cider-select-known-endpoint)))) |
| 140 | + (list (or (car known-endpoint) |
| 141 | + (read-string "Host: " (nrepl-current-host) nil (nrepl-current-host))) |
| 142 | + (string-to-number (let ((port (or (cadr known-endpoint) (nrepl-default-port)))) |
| 143 | + (read-string "Port: " port nil port)))))) |
113 | 144 | (setq cider-current-clojure-buffer (current-buffer))
|
114 | 145 | (when (nrepl-check-for-repl-buffer `(,host ,port) nil)
|
115 | 146 | (nrepl-connect host port)))
|
|
0 commit comments