@@ -569,14 +569,21 @@ If NO-ERROR is non-nil, show messages instead of throwing an error."
569
569
570
570
(defun nrepl--ssh-tunnel-connect (host port )
571
571
" Connect to a remote machine identified by HOST and PORT through SSH tunnel."
572
- (message " [nREPL] Establishing SSH tunneled connection to %s :%s ... " host port)
573
- (let* ((remote-dir (if host (format " /ssh:%s : " host) default-directory))
572
+ (let* ((current-buf (buffer-file-name ))
573
+ (tramp-file-regexp " /ssh:\\ (.+@\\ )?\\ (.+?\\ )\\ (:\\ |#\\ ).+" )
574
+ (remote-dir (cond
575
+ ((string-match tramp-file-regexp current-buf) current-buf)
576
+ (host (format " /ssh:%s : " host))
577
+ (t default-directory)))
578
+ (remote-host (or (match-string 2 current-buf)
579
+ host))
574
580
(ssh (or (executable-find " ssh" )
575
581
(error " [nREPL] Cannot locate 'ssh' executable " )))
576
582
(cmd (nrepl--ssh-tunnel-command ssh remote-dir port))
577
583
(tunnel-buf (nrepl-tunnel-buffer-name
578
- `((:host , host ) (:port , port ))))
584
+ `((:host , remote- host ) (:port , port ))))
579
585
(tunnel (start-process-shell-command " nrepl-tunnel" tunnel-buf cmd)))
586
+ (message " [nREPL] Establishing SSH tunneled connection to %s :%s ... " remote-host port)
580
587
(process-put tunnel :waiting-for-port t )
581
588
(set-process-filter tunnel (nrepl--ssh-tunnel-filter port))
582
589
(while (and (process-live-p tunnel)
@@ -589,7 +596,7 @@ If NO-ERROR is non-nil, show messages instead of throwing an error."
589
596
(thread-first
590
597
endpoint
591
598
(plist-put :tunnel tunnel)
592
- (plist-put :remote-host host))))))
599
+ (plist-put :remote-host remote- host))))))
593
600
594
601
(defun nrepl--ssh-tunnel-command (ssh dir port )
595
602
" Command string to open SSH tunnel to the host associated with DIR's PORT."
@@ -598,11 +605,12 @@ If NO-ERROR is non-nil, show messages instead of throwing an error."
598
605
; ; forwarding is set up, which is used to synchronise on, so that
599
606
; ; the port forwarding is up when we try to connect.
600
607
(format-spec
601
- " %s -v -N -L %p:localhost:%p %u'%h'"
608
+ " %s -v -N -L %p:localhost:%p %u'%h' %n "
602
609
`((?s . , ssh )
603
610
(?p . , port )
604
611
(?h . , v-host )
605
- (?u . ,(if v-user (format " -l '%s ' " v-user) " " ))))))
612
+ (?u . ,(if v-user (format " -l '%s ' " v-user) " " ))
613
+ (?n . ,(if v-port (format " -p '%s ' " v-port) " " ))))))
606
614
607
615
(autoload 'comint-watch-for-password-prompt " comint" " (autoload)." )
608
616
0 commit comments