Skip to content

Commit

Permalink
Infer host in tramp context #16
Browse files Browse the repository at this point in the history
  • Loading branch information
svaante committed Jan 5, 2024
1 parent 26f5bba commit 4393b10
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions dape.el
Original file line number Diff line number Diff line change
Expand Up @@ -775,21 +775,27 @@ Replaces symbol and string occurences of \"autoport\"."
(plist-put 'command-args command-args)))))

(defun dape-config-tramp (config)
"Apply tramp file prefix on CONFIG if started in tramp context."
(if-let* (((and (not (plist-get config 'prefix-local))
(not (plist-get config 'prefix-remote))
(plist-get config 'command)))
(default-directory (or (plist-get config 'command-cwd)
default-directory))
((tramp-tramp-file-p default-directory))
(parts (tramp-dissect-file-name default-directory))
(tramp-prefix
(tramp-completion-make-tramp-file-name (tramp-file-name-method parts)
(tramp-file-name-user parts)
(tramp-file-name-host parts)
"")))
(plist-put config 'prefix-local tramp-prefix)
config))
"Infer `prefix-local' and `host' on CONFIG if in tramp context."
(when-let* ((default-directory
(or (plist-get config 'command-cwd)
default-directory))
((tramp-tramp-file-p default-directory))
(parts (tramp-dissect-file-name default-directory)))
(when (and (not (plist-get config 'prefix-local))
(not (plist-get config 'prefix-remote))
(plist-get config 'command))
(plist-put config 'prefix-local
(tramp-completion-make-tramp-file-name
(tramp-file-name-method parts)
(tramp-file-name-user parts)
(tramp-file-name-host parts)
"")))
(when (and (plist-get config 'command)
(plist-get config 'port)
(not (plist-get config 'host))
(equal (tramp-file-name-method parts) "ssh"))
(plist-put config 'host (file-remote-p default-directory 'host))))
config)

(defun dape-ensure-command (config)
"Ensure that `command' from CONFIG exist system."
Expand Down

0 comments on commit 4393b10

Please sign in to comment.