Function: nrepl-connect

nrepl-connect is a byte-compiled function defined in nrepl-client.el.

Signature

(nrepl-connect HOST PORT)

Documentation

Connect to the nREPL server identified by HOST and PORT.

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 (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.

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20260414.1619/nrepl-client.el
(defun nrepl-connect (host port)
  "Connect to the nREPL server identified by HOST and PORT.
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 (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)
      ;; we're dealing with a remote host
      (if (and host (not nrepl-force-ssh-for-remote-hosts))
          (or (nrepl--direct-connect host port 'no-error)
              ;; direct connection failed
              ;; fallback to ssh tunneling if enabled
              (and nrepl-use-ssh-fallback-for-remote-hosts
                   (message "[nREPL] Falling back to SSH tunneled connection ...")
                   (nrepl--ssh-tunnel-connect host port))
              ;; fallback is either not enabled or it failed as well
              (if (and (null nrepl-use-ssh-fallback-for-remote-hosts)
                       (not localp))
                  (error "[nREPL] Direct connection to %s:%s failed; try setting `nrepl-use-ssh-fallback-for-remote-hosts' to t"
                         host port)
                (error "[nREPL] Cannot connect to %s:%s" host port)))
        ;; `nrepl-force-ssh-for-remote-hosts' is non-nil
        (nrepl--ssh-tunnel-connect host port)))))