[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Fix hostname completion on MS Windows

From: Jim Porter
Subject: Re: [PATCH] Fix hostname completion on MS Windows
Date: Thu, 8 Apr 2021 12:39:06 -0700

On Thu, Apr 8, 2021 at 5:40 AM Michael Albinus <> wrote:
> I don't mind to apply such a patch, but I haven't heard about this kind
> of file name completion to "c:/ssh:host:/path/to/file". Could you pls
> show an example, and what you have typed in order to get this?

Starting with "emacs -Q":
M-: (require 'tramp)
C-x C-f /ss TAB

I'd expect completion to append an "h" to the path I'm typing, and if
I hit TAB again, to show "ssh:" and "sshx:" as possible completions.
The same issue happens if I type:

C-x C-f /sshx:serv TAB

I'd expect this to append "er:" so I have "/sshx:server:".[1]

> Best might be to enable Tramp traces after loading Tramp, like... [snip]

I've attached the trace output, though it might not be very useful,
since it didn't show where I think things are going wrong. To the best
of my knowledge, here's what's happening:

1) I type C-x C-f /ss TAB
2) Eventually, this calls (file-name-completion "ss" "/"
file-exists-p). All good so far.
3) The first thing `file-name-completion' does with the directory[2]
("/") is to call `expand-file-name' on it. This is a problem because
on MS Windows, `expand-file-name' will prepend the volume letter, so
now our directory is "c:/". Emacs is now effectively trying to
complete the file name "c:/ss", which Tramp's completion regexp
doesn't recognize.

> > The attached patch fixes things for me; it's somewhat hacky, since it
> > tries to recognize the mutilated path string as shown above.
> That would be OK, but perhaps we make the volume letter optional? Like
> --8<---------------cut here---------------start------------->8---
> (when (eq system-type 'windows-nt)
>     "\\(?:[[:alpha:]]:\\)?")
> --8<---------------cut here---------------end--------------->8---

That seems reasonable. I've attached an updated patch.

> I know, that Eli Zaretskii (maintainer of Emacs) has committed several
> patches in order to drop such a volume letter for remote file names, but
> I don't remember where they have been applied. Perhaps, this was an
> Emacs 28 change.

It looks like `file-name-completion' still adds the volume letter by
calling `expand-file-name' on Emacs 28. I didn't see any changes to
`file-name-completion' since Emacs 27.

> This patch is small enough (the upper limit are ~15 lines), but in
> general it is a good idea to sign copyright papers for future
> changes. To start the assignment process you should download
> and return the completed information to the address at the top.


> > As a small addendum: this patch still doesn't fix things when
> > `default-directory' is a UNC path (e.g. "\\server\mnt\"), but the same
> > issue applies to `tramp-drop-volume-letter', and this case should be
> > rare in practice anyway.
> Yep, we could handle this case afterwards. If needed.
> > - Jim
> Best regards, Michael.

[1] At least for sshx, my understanding is that this would only happen
if you had the connection info cached in ~/.emacs.d/tramp, so you
wouldn't see this with "emacs -Q" even with my patch to fix things. It
would matter in everyday usage though.


Attachment: tramp-trace.log
Description: Binary data

Attachment: 0001-tramp.el-tramp-completion-file-name-regexp-default.patch
Description: Binary data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]