Subject: Re: bug#76165: [PATCH] ansi-osc-directory-tracker respects Tramp remote files

From: Visuwesh <[email-masked]>
Date: Mon, 10 Feb 2025 09:37:00 +0530

[ஞாயிறு பிப்ரவரி 09, 2025] Ship Mints wrote:

> Tramp remote forms are now retained when changes to 'default-directory' are
> detected by this filter.  Previously, for example,
> /ssh:hostname:/home/username would be stripped to just /home/username.
>
> -Stephane
> [...]
>  This functionality serves as an alternative to `dirtrack-mode'
>  and `shell-dirtrack-mode'."
>    (let ((url (url-generic-parse-url text)))
> @@ -123,8 +128,14 @@ ansi-osc-directory-tracker
>                 (or (null (url-host url))
>                     ;; Use `downcase' to match `url-generic-parse-url' behavior
>                     (string= (url-host url) (downcase (system-name)))))
> -      (ignore-errors
> -        (cd-absolute (url-unhex-string (url-filename url)))))))
> +      (let ((current-default-directory default-directory))
> +        (when (ignore-errors
> +                (cd-absolute (url-unhex-string (url-filename url))))
> +          (when (and (fboundp 'tramp-tramp-file-p)
> +                     (tramp-tramp-file-p current-default-directory))
> +            (setq default-directory (tramp-make-tramp-file-name
> +                                     (tramp-dissect-file-name current-default-directory 'nodefault)
> +                                     default-directory))))))))
>  
>  ;; Hyperlink handling (OSC 8)

Is it necessary to invoke so many Tramp functions?  I have the following
simpler advice in my config and it has worked faithfully for many months
now.

    (define-advice comint-osc-directory-tracker (:override (_ text) vz/handle-remote-paths-as-well)
      (let ((url (url-generic-parse-url text)))
        (when (equal (url-type url) "file")
          (ignore-errors
            (let ((file (url-unhex-string (url-filename url))))
              (cd-absolute (concat (file-remote-p default-directory) file)))))))