Stefan Monnier writes: Hi Stefan, >> I could imagine that the completion machinery offers an API that a >> package could register its own idea of a file name syntax. > > The completion code relies on `file-name-directory`, > `directory-file-name`, etc... for that. > > The problem as I see it goes as follows: > > According to `file-name-directory`, in `/ssh:myhost` the part > `ssh:myhost` is an element of the `/` directory. For this reason, the > completion machinery would expect (file-name-all-completions "s" "/") to > include "ssh:myhost" in its return list rather than only "ssh:". > > Now, it's impractical for Tramp to do that. So the end result is the > kind of bug reports we're discussing. > > One way to fix the problem is for Tramp to "teach" the rest of the > system that `/ssh:` is a kind of directory, in which case the completion > machinery would know that (file-name-all-completions "s" "/") returns > "ssh:" and that "myhost" would be included only in the return value of > (file-name-all-completions "" "/ssh:"). I've played with this idea, and the appended patch makes it work, indeed. I had to adapt expand-file-name, file-exists-p, file-name-directory and file-name-nondirectory, but the changes look simple. It works for me now for the default completion styles (basic partial-completion emacs22) as well as for fido-mode, with both the default and simplified Tramp syntax. It doesn't work (yet) for the separated Tramp syntax, but this isn't our major problem, and could be fixed later. Could people check how it plays in their environment? > Another is to change Tramp's syntax so that it uses the regular "/" > separator rather than ":". This would get a similar result but without > touching `file-name-directory` and friends. No way. We have had syntax ambiguities for Tramp in the past, and I don't want to go this painful way, again. > We could also consider introducing a new set of (file-name) functions > > completion-file-name-directory, completion-directory-file-name, ... > > so the completion code can use its own notion of how a file name gets > separated into parts. That's what I have done in the patch, adding such functions for the tramp-completion-file-name-handler implementation. An implementation for directory-file-name wasn't needed, but we could add if necessary. > But introducing such a subtle distinction would likely introduce a lot > of bugs&confusion as well. Perhaps. So this patch isn't a candidate for Emacs 29.1. I would push it to the master branch (when there is positive feedback), and I would also add it to the tramp-2-6-stable branch in the Tramp git repo. By this, the next Tramp 2.6 release on GNU ELPA would contain this change as well, and we could get broader feedback. What do people think? > Stefan Best regards, Michael.