Subject: Re: bug#60505: 29.0.60; Fido Mode and Tramp Completion

From: Michael Albinus <[email-masked]>
Date: Fri, 03 Feb 2023 20:23:26 +0100

Stefan Monnier <[email-masked]> writes:

Hi Stefan,

>> +(defun tramp-completion-handle-expand-file-name (filename &optional directory)
>> +  "Like `expand-file-name' for partial Tramp files."
>> +  (if (file-name-absolute-p filename)
>> +      filename
>> +    (concat (or directory default-directory "/") filename)))
>
> Hmm... shouldn't a "/" may need to be added if `directory` or
> `default-directory` doesn't end with one (except in cases like `/ssh:`)?

Rather not. We're speaking about the tramp-completion-file-name-handler,
which is activated for file names matching
"\\`\\(?:\\)?/\\(?:\\(?:\\(-\\|[[:alnum:]]\\{2,\\}\\)\\(?::\\)\\(?:\\([^/:|[:blank:]]+\\)\\(?:@\\)\\)?\\(\\(?:[%._[:alnum:]-]+\\|\\(?:\\[\\)\\(?:\\(?:[[:alnum:]]*:\\)+[.[:alnum:]]*\\)?\\(?:]\\)\\)\\(?:\\(?:#\\)\\(?:[[:digit:]]+\\)\\)?\\)?\\)\\(?:|\\)\\)*\\(?:\\(?:-\\|[[:alnum:]]+\\)\\(?:\\(?::\\)\\(?:[%._[:alnum:]-]+\\)?\\)?\\)?\\'".

It looks complex, but in practice it is everything until
"/method:user@host" without a trailing colon. No slash there.

It's value is

--8<---------------cut here---------------start------------->8---
    (rx
     bos
     ;; `file-name-completion' uses absolute paths for matching.
     ;; This means that on W32 systems, something like
     ;; "/ssh:host:~/path" becomes "c:/ssh:host:~/path".  See also
     ;; `tramp-drop-volume-letter'.
     (? (regexp tramp-volume-letter-regexp))
     ;; We cannot use `tramp-prefix-regexp', because it starts with `bol'.
     (literal tramp-prefix-format)

     ;; Optional multi hops.
     (* (regexp tramp-remote-file-name-spec-regexp)
        (regexp tramp-postfix-hop-regexp))

     ;; Last hop.
     (? (regexp tramp-completion-method-regexp)
	;; Method separator, user name and host name.
	(? (regexp tramp-postfix-method-regexp)
	   ;; This is a little bit lax, but it serves.
	   (? (regexp tramp-host-regexp))))

     eos)
--8<---------------cut here---------------end--------------->8---

> Then again, maybe not.  I don't understand enough of the details of when
> `tramp-completion-file-name-handler` is used (IOW what is meant exactly by
> "partial Tramp file name").

Exactly that.

> I didn't remember this part of the design, but it sounds good and does
> make changes to that part (like the proposed patch) "safer", so it's
> probably OK to try it on `master`.

There is no special design for it. Ordinary file name handler machinery.

> I wonder how this patch interacts with `locate-dominating-file`.

I'll check tomorrow. But since there isn't a slash in such filenames
(except the leading one), I expect it shall work. Needs more testing,
this case and other use cases.

>         Stefan

Best regards, Michael.