[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/cider b02920ab5f: [Fix #2822] If current buffer is a TRAMP
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/cider b02920ab5f: [Fix #2822] If current buffer is a TRAMP buffer, use its filename for SSH tunnel (#3264) |
Date: |
Fri, 16 Dec 2022 03:58:34 -0500 (EST) |
branch: elpa/cider
commit b02920ab5f77114da2a82c76e16b4b9ed3fecce3
Author: Vadim Rodionov <47952597+OknoLombarda@users.noreply.github.com>
Commit: GitHub <noreply@github.com>
[Fix #2822] If current buffer is a TRAMP buffer, use its filename for SSH
tunnel (#3264)
If current buffer is a TRAMP buffer, use its filename for SSH tunnel. This
way, username and SSH port will be parsed from existing SSH connection, instead
of using current username and default SSH port.
Also fixes #3261.
---
CHANGELOG.md | 1 +
doc/modules/ROOT/pages/basics/up_and_running.adoc | 4 +++-
nrepl-client.el | 18 +++++++++++++++---
3 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2a4fe659b7..24343a8eb5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@
- Bump the injected nREPL version to 1.0.
- [#3291](https://github.com/clojure-emacs/cider/pull/3291): **Remove** the
`'cljs-pending` `repl-type`. It is replaced by
`cider-repl-cljs-upgrade-pending`.
+- [#3261](https://github.com/clojure-emacs/cider/issues/3261): If user is
connecting to nREPL from a TRAMP buffer, use its connection parameters (port,
username) for establishing SSH tunnel.
### Bugs fixed
diff --git a/doc/modules/ROOT/pages/basics/up_and_running.adoc
b/doc/modules/ROOT/pages/basics/up_and_running.adoc
index dc4725f79c..5d269ee384 100644
--- a/doc/modules/ROOT/pages/basics/up_and_running.adoc
+++ b/doc/modules/ROOT/pages/basics/up_and_running.adoc
@@ -262,7 +262,9 @@ config files such as `~/.ssh/config` and
`~/.ssh/known_hosts`. This is known to
cause problems with complex or nonstandard ssh configs.
You can safely run `cider-jack-in-*` while working with remote files over
TRAMP. CIDER
-will handle this use-case transparently for you.
+will reuse existing SSH connection's parameters (like port and username) for
establishing SSH tunnel.
+The same will happen if you try to `cider-connect-*` to a host that matches
the one you're currently
+connected to.
== Connecting via unix domain file socket
diff --git a/nrepl-client.el b/nrepl-client.el
index e8ac80df89..b0d554ed5f 100644
--- a/nrepl-client.el
+++ b/nrepl-client.el
@@ -570,7 +570,18 @@ If NO-ERROR is non-nil, show messages instead of throwing
an error."
(defun nrepl--ssh-tunnel-connect (host port)
"Connect to a remote machine identified by HOST and PORT through SSH tunnel."
(message "[nREPL] Establishing SSH tunneled connection to %s:%s ..." host
port)
- (let* ((remote-dir (if host (format "/ssh:%s:" host) default-directory))
+ (let* ((current-buf (buffer-file-name))
+ (tramp-file-regexp "/ssh:\\(.+@\\)?\\(.+?\\)\\(:\\|#\\).+")
+ (remote-dir (cond
+ ;; If current buffer is a TRAMP buffer and its host is
+ ;; the same as HOST, reuse its connection parameters for
+ ;; SSH tunnel.
+ ((and (string-match tramp-file-regexp current-buf)
+ (string= host (match-string 2 current-buf)))
current-buf)
+ ;; Otherwise, if HOST was provided, use it for
connection.
+ (host (format "/ssh:%s:" host))
+ ;; Use default directory as fallback.
+ (t default-directory)))
(ssh (or (executable-find "ssh")
(error "[nREPL] Cannot locate 'ssh' executable")))
(cmd (nrepl--ssh-tunnel-command ssh remote-dir port))
@@ -598,11 +609,12 @@ If NO-ERROR is non-nil, show messages instead of throwing
an error."
;; forwarding is set up, which is used to synchronise on, so that
;; the port forwarding is up when we try to connect.
(format-spec
- "%s -v -N -L %p:localhost:%p %u'%h'"
+ "%s -v -N -L %p:localhost:%p %u'%h' %n"
`((?s . ,ssh)
(?p . ,port)
(?h . ,v-host)
- (?u . ,(if v-user (format "-l '%s' " v-user) ""))))))
+ (?u . ,(if v-user (format "-l '%s' " v-user) ""))
+ (?n . ,(if v-port (format "-p '%s' " v-port) ""))))))
(autoload 'comint-watch-for-password-prompt "comint" "(autoload).")
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [nongnu] elpa/cider b02920ab5f: [Fix #2822] If current buffer is a TRAMP buffer, use its filename for SSH tunnel (#3264),
ELPA Syncer <=