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

From: Michael Albinus <[email-masked]>
Date: Tue, 07 Sep 2021 16:23:08 +0200

Gregory Heytings <[email-masked]> writes:

>> Alas it doesn't.
>>
>> emacs -Q -l tramp --eval "(add-to-list 'completion-styles 'substring)"
>>
>> C-x C-f /scp: TAB
>>
>> still shows "Sole completion".

In order to see what Tramp does, I have called

--8<---------------cut here---------------start------------->8---
# emacs -Q -l tramp --eval "(add-to-list 'completion-styles 'substring)" --eval "(trace-function-background 'tramp-completion-handle-file-name-all-completions)"
--8<---------------cut here---------------end--------------->8---

> Sorry, I typed too fast.  It displays two completion candidates:
> "pscp:" and "scp:", which is not what one expects at that point.

When I type "C-x C-f /scp: TAB", I see the same result as you, "pscp:"
and "scp:". However, the buffer *trace-output* contains

--8<---------------cut here---------------start------------->8---
======================================================================
1 -> (tramp-completion-handle-file-name-all-completions "" "/")
1 <- tramp-completion-handle-file-name-all-completions: ("sudoedit:" "sshfs:" "smb:" "rcp:" "remcp:" "scp:" "scpx:" "rsync:" "rsh:" "remsh:" "ssh:" "sshx:" "telnet:" "nc:" "su:" "sg:" "sudo:" "doas:" "ksu:" "krlogin:" "plink:" "plinkx:" "pscp:" "psftp:" "fcp:" "rclone:" "afp:" "dav:" "davs:" "gdrive:" "mtp:" "nextcloud:" "sftp:" "ftp:" "adb:")
======================================================================
1 -> (tramp-completion-handle-file-name-all-completions "" "/")
1 <- tramp-completion-handle-file-name-all-completions: ("sudoedit:" "sshfs:" "smb:" "rcp:" "remcp:" "scp:" "scpx:" "rsync:" "rsh:" "remsh:" "ssh:" "sshx:" "telnet:" "nc:" "su:" "sg:" "sudo:" "doas:" "ksu:" "krlogin:" "plink:" "plinkx:" "pscp:" "psftp:" "fcp:" "rclone:" "afp:" "dav:" "davs:" "gdrive:" "mtp:" "nextcloud:" "sftp:" "ftp:" "adb:")
--8<---------------cut here---------------end--------------->8---

That means, "scp:" hasn't been passed to
tramp-completion-handle-file-name-all-completions, and the result of
that function looks proper to me.

> With tramp-default-method set to "ssh", C-x C-f /ssh: TAB still
> displays "Sole completion".

Now I have called

--8<---------------cut here---------------start------------->8---
# emacs -Q -l tramp --eval "(add-to-list 'completion-styles 'substring)" --eval "(trace-function-background 'tramp-completion-handle-file-name-all-completions)" --eval '(setq tramp-default-method "ssh")'
--8<---------------cut here---------------end--------------->8---

Calling "C-x C-f /ssh: TAB" gives me indeed "Sole completion", and
*trace-output* still contains

--8<---------------cut here---------------start------------->8---
======================================================================
1 -> (tramp-completion-handle-file-name-all-completions "" "/")
1 <- tramp-completion-handle-file-name-all-completions: ("sudoedit:" "sshfs:" "smb:" "rcp:" "remcp:" "scp:" "scpx:" "rsync:" "rsh:" "remsh:" "ssh:" "sshx:" "telnet:" "nc:" "su:" "sg:" "sudo:" "doas:" "ksu:" "krlogin:" "plink:" "plinkx:" "pscp:" "psftp:" "fcp:" "rclone:" "afp:" "dav:" "davs:" "gdrive:" "mtp:" "nextcloud:" "sftp:" "ftp:" "adb:")
--8<---------------cut here---------------end--------------->8---

This also looks proper to me.

>From the Tramp POV, there's no problem I believe. How completion
packages call file-name-all-completions, and how they interpret the
result, is out of Tramp's responsibility.

Best regards, Michael.