Skip to content

Commit

Permalink
[#1544] Don't fallback to SSH by default for remote hosts in case of …
Browse files Browse the repository at this point in the history
…a failed

direct connection

This behavior was confusing for some users and couldn't be manually configured.
Now the behavior is configurable via the new defcustom
`nrepl-use-ssh-fallback-for-remote-hosts`
and is disabled by default.
  • Loading branch information
bbatsov committed Jan 19, 2017
1 parent 858b81d commit 79f8cc6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
* [#1860](https://github.com/clojure-emacs/cider/issues/1860): Add `cider-repl-history` to browse the REPL input history and insert elements from it into the REPL buffer.
* Add new customization variable `cider-font-lock-reader-conditionals` which toggles syntax highlighting of reader conditional expressions based on the buffer connection.
* Add new face `cider-reader-conditional-face` which is used to mark unused reader conditional expressions.
* [#1544](https://github.com/clojure-emacs/cider/issues/1544): Add a new defcustom `nrepl-use-ssh-fallback-for-remote-hosts` to control the behavior of `nrepl-connect` (and in turn that of `cider-connect`) for remote hosts.

### Changes

* Drop support for Emacs 24.3.
* Don't try to use ssh automatically when connecting to remote hosts and a direct connection fails. See `nrepl-use-ssh-fallback-for-remote-hosts`.

### Bugs Fixed

Expand Down
22 changes: 16 additions & 6 deletions nrepl-client.el
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ The `nrepl-buffer-name-separator' separates cider-repl from the project name."
:type 'boolean
:group 'nrepl)

(defcustom nrepl-use-ssh-fallback-for-remote-hosts nil
"If non-nil, attempt to connect via ssh to remote hosts when unable to connect directly."
:type 'boolean
:group 'nrepl)

(defcustom nrepl-sync-request-timeout 10
"The number of seconds to wait for a sync response.
Setting this to nil disables the timeout functionality."
Expand Down Expand Up @@ -513,17 +518,22 @@ and kill the process buffer."
For local hosts use a direct connection. For remote hosts, if
`nrepl-force-ssh-for-remote-hosts' is nil, attempt a direct connection
first. If `nrepl-force-ssh-for-remote-hosts' is non-nil or the direct
connection failed, try to start a SSH tunneled connection. Return a plist
of the form (:proc PROC :host \"HOST\" :port PORT) that might contain
additional key-values depending on the connection type."
connection failed (and `nrepl-use-ssh-fallback-for-remote-hosts' is
non-nil), try to start a SSH tunneled connection. Return a plist of the
form (:proc PROC :host \"HOST\" :port PORT) that might contain additional
key-values depending on the connection type."
(let ((localp (if host
(nrepl-local-host-p host)
(not (file-remote-p default-directory)))))
(if localp
(nrepl--direct-connect (or host "localhost") port)
(or (and host (not nrepl-force-ssh-for-remote-hosts)
(nrepl--direct-connect host port 'no-error))
(nrepl--ssh-tunnel-connect host port)))))
;; we're dealing with a remote host
(if (and host (not nrepl-force-ssh-for-remote-hosts))
(nrepl--direct-connect host port 'no-error)
;; direct connection failed or `nrepl-force-ssh-for-remote-hosts' is non-nil
(when (or nrepl-use-ssh-fallback-for-remote-hosts
nrepl-force-ssh-for-remote-hosts)
(nrepl--ssh-tunnel-connect host port))))))

(defun nrepl--direct-connect (host port &optional no-error)
"If HOST and PORT are given, try to `open-network-stream'.
Expand Down

0 comments on commit 79f8cc6

Please sign in to comment.