@@ -212,7 +212,8 @@ Create REPL buffer and start an nREPL client connection."
212212 " Interactively select the host and port to connect to."
213213 (let* ((ssh-hosts (cider--ssh-hosts))
214214 (hosts (-distinct (append (when cider-host-history
215- (list (list (car cider-host-history))))
215+ ; ; history elements are strings of the form "host:port"
216+ (list (split-string (car cider-host-history) " :" )))
216217 (list (list (nrepl-current-host)))
217218 cider-known-endpoints
218219 ssh-hosts
@@ -221,24 +222,8 @@ Create REPL buffer and start an nREPL client connection."
221222 (list (list " localhost" ))))))
222223 (sel-host (cider--completing-read-host hosts))
223224 (host (car sel-host))
224- (local-p (or (nrepl-local-host-p host)
225- (not (assoc-string host ssh-hosts))))
226- ; ; Each lein-port is a list of the form (dir port)
227- (lein-ports (if local-p
228- ; ; might connect to localhost from a remote file
229- (let* ((change-dir-p (file-remote-p default-directory))
230- (default-directory (if change-dir-p " ~/" default-directory)))
231- (cider-locate-running-nrepl-ports (unless change-dir-p default-directory)))
232- (let ((vec (vector " sshx" nil host " " nil ))
233- ; ; might connect to a different remote
234- (dir (when (file-remote-p default-directory)
235- (with-parsed-tramp-file-name default-directory cur
236- (when (string= cur-host host) default-directory)))))
237- (tramp-maybe-open-connection vec)
238- (with-current-buffer (tramp-get-connection-buffer vec)
239- (cider-locate-running-nrepl-ports dir)))))
240- (ports (append (cdr sel-host) lein-ports))
241- (port (cider--completing-read-port host ports)))
225+ (port (or (cadr sel-host)
226+ (cider--completing-read-port host (cider--infer-ports host ssh-hosts)))))
242227 (list host port)))
243228
244229(defun cider--ssh-hosts ()
@@ -258,6 +243,26 @@ Return a list of the form (HOST PORT), where PORT can be nil."
258243 ; ; remove the label
259244 (if (= 3 (length host)) (cdr host) host)))
260245
246+ (defun cider--infer-ports (host ssh-hosts )
247+ " Infer nREPL ports on HOST.
248+ Return a list of elements of the form (directory port). SSH-HOSTS is a list
249+ of remote SSH hosts."
250+ (let ((localp (or (nrepl-local-host-p host)
251+ (not (assoc-string host ssh-hosts)))))
252+ (if localp
253+ ; ; change dir: current file might be remote
254+ (let* ((change-dir-p (file-remote-p default-directory))
255+ (default-directory (if change-dir-p " ~/" default-directory)))
256+ (cider-locate-running-nrepl-ports (unless change-dir-p default-directory)))
257+ (let ((vec (vector " sshx" nil host " " nil ))
258+ ; ; change dir: user might want to connect to a different remote
259+ (dir (when (file-remote-p default-directory)
260+ (with-parsed-tramp-file-name default-directory cur
261+ (when (string= cur-host host) default-directory)))))
262+ (tramp-maybe-open-connection vec)
263+ (with-current-buffer (tramp-get-connection-buffer vec)
264+ (cider-locate-running-nrepl-ports dir))))))
265+
261266(defun cider--completing-read-port (host ports )
262267 " Interactively select port for HOST from PORTS."
263268 (let* ((ports (cider-join-into-alist ports))
0 commit comments