Subject: bug#50387: Possible bug in Tramp or in completions

From: Michael Albinus <[email-masked]>
Date: Tue, 07 Sep 2021 14:58:06 +0200

Gregory Heytings <[email-masked]> writes:

> Hi Michael,

Hi Gregory,

>>> * lisp/net/tramp.el (tramp-completion-handle-file-name-all-completions):
>>> Do not return methods when the filename already contains a complete method.
>>> Fixes bug#50387.
>>
>> I don't see this implemented. You rather don't return methods when
>> the filename does not contain a possible method string at all.
>
> Yet this is what is happening.  You can try it yourself: emacs -Q, M-:
> (require 'tramp), M-: (add-to-list 'completion-styles 'substring), C-x
> C-f /scp: TAB.  This will display "Sole completion", and it displays
> "Sole completion" because "scp:" and "scpx:" are added in the
> completion candiates in
> tramp-completion-handle-file-name-all-completions.  You can see this
> with
>
> (message "method '%s' result '%s'" method (tramp-get-completion-methods m))
>
> around "Possible methods".  With C-x C-f /scp TAB, you will see
>
> method ’scp’ result ’(nil nil nil nil nil nil nil nil nil nil nil nil
> nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil /scpx:
> /scp: nil nil nil nil nil)’
>
> which is correct, but with C-x C-f /scp: TAB, you will see
>
> method ’’ result ’(nil nil nil nil nil nil nil nil nil nil nil nil nil
> nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil /scpx:
> /scp: nil nil nil nil nil)’
>
> which is wrong.

All of this does not fit to your commit message "Do not return methods
when the filename already contains a complete method.", I believe. But
so what.

Your patch does not handle the case when `tramp-syntax' is
`separate'. There are no methods in the remote file name then, and you
must handle user and host names properly.

Finally, I have submitted a patch to master, which deactivates *default*
method, user and host name expansion in
`tramp-completion-handle-file-name-all-completions'. The difference to
your patch is, that it doesn't manipulate the results, but it
deactivates this expansion by usual Tramp means.

Could you pls check how it fits in your use case? My (limited) tests
along your examples look good.

Best regards, Michael.