Skip to content

Commit 1d8687b

Browse files
committed
Make TRAMP functionality work when using non-standard ports
1 parent cb104e8 commit 1d8687b

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- [#3393](https://github.com/clojure-emacs/cider/issues/3393): recompute namespace info on each shadow-cljs recompilation or evaluation.
2525
- Fix the `xref-find-definitions` CIDER backend to return correct filenames.
2626
- Fix the `cider-xref-fn-deps` buttons to direct to the right file.
27+
- Make TRAMP functionality work when using non-standard ports.
2728

2829
### Changes
2930

cider-common.el

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ create a valid path."
226226
(match-string 1 filename)
227227
filename)))
228228

229-
(defun cider-make-tramp-prefix (method user host)
230-
"Constructs a Tramp file prefix from METHOD, USER, HOST.
229+
(defun cider-make-tramp-prefix (method user host &optional port)
230+
"Constructs a Tramp file prefix from METHOD, USER, HOST, PORT.
231231
It originated from Tramp's `tramp-make-tramp-file-name'. The original be
232232
forced to make full file name with `with-parsed-tramp-file-name', not providing
233233
prefix only option."
@@ -240,6 +240,8 @@ prefix only option."
240240
(if (string-match tramp-ipv6-regexp host)
241241
(concat tramp-prefix-ipv6-format host tramp-postfix-ipv6-format)
242242
host))
243+
(when port
244+
(concat "#" port))
243245
tramp-postfix-host-format))
244246

245247
(defun cider-tramp-prefix (&optional buffer)
@@ -253,7 +255,7 @@ if BUFFER is local."
253255
(when (tramp-tramp-file-p name)
254256
(with-parsed-tramp-file-name name v
255257
(with-no-warnings
256-
(cider-make-tramp-prefix v-method v-user v-host))))))
258+
(cider-make-tramp-prefix v-method v-user v-host v-port))))))
257259

258260
(defun cider--client-tramp-filename (name &optional buffer)
259261
"Return the tramp filename for path NAME relative to BUFFER.

test/cider-common-tests.el

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,15 @@
6666

6767
(describe "cider-make-tramp-prefix"
6868
(it "returns tramp-prefix only"
69-
;;; The third parameter is a host. It must contains a port number.
69+
;;; The third parameter is a host.
7070
(expect (cider-make-tramp-prefix "ssh" "cider-devs" "192.168.50.9#22")
7171
:to-equal "/ssh:[email protected]#22:")
72+
(expect (cider-make-tramp-prefix "ssh" "cider-devs" "192.168.50.9")
73+
:to-equal "/ssh:[email protected]#22:")
74+
(expect (cider-make-tramp-prefix "ssh" "cider-devs" "192.168.50.9" "12345")
75+
:to-equal "/ssh:[email protected]#12345:")
76+
(expect (cider-make-tramp-prefix "ssh" "cider-devs" "192.168.50.9#12345")
77+
:to-equal "/ssh:[email protected]#12345:")
7278
;;; These two cases are for using ssh config alias.
7379
(expect (cider-make-tramp-prefix "ssh" nil "test.cider.com")
7480
:to-equal "/ssh:test.cider.com:")

0 commit comments

Comments
 (0)