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

From: Gregory Heytings <[email-masked]>
Date: Fri, 03 Feb 2023 00:23:21 +0000

>> More importantly (as I unsuccessfully tried to convey) it circumvents 
>> the bug in the implementation of a particular completion mechanism, 
>> which is not the place where the bug lies and should be fixed.  It is 
>> not reasonable to expect that all existing and future file completion 
>> mechanisms should implement specific rules to deal with the Tramp 
>> syntax (or, for that matter, with the syntax of any other package).
>
> From my POV, it is very reasonable to expect that completion mechanisms 
> know about Tramp syntax and support it.  Tramp became long ago an 
> integral part of the Emacs core, so its syntax is as important to 
> support as any other syntactical aspects of file names in Emacs, such as 
> the "/:" "quoting".
>

The possibility that it would be necessary at some point to add an 
explicit support for the Tramp syntax(es) in the completion mechanisms 
cannot be ruled out, of course.  But this bug (and the related ones) is 
not a reason to do that, because it can easily be fixed inside Tramp.

Did you look at the options that are on the table?

Option 1 is a trivial three-line patch to tramp.el, which adds a 
conditional around an existing statement to give users and modes control 
on the way Tramp methods are displayed (unconditionally with 
tramp-methods-in-completions t, lazily with tramp-methods-in-completions 
nil):

diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 1916d50af03..ca08a0a2cd2 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -812,6 +812,8 @@ tramp-syntax
    :initialize #'custom-initialize-default
    :set #'tramp-set-syntax)

+(defcustom tramp-methods-in-completions t)
+
  (defvar tramp-prefix-format)
  (defvar tramp-prefix-regexp)
  (defvar tramp-method-regexp)
@@ -3022,8 +3024,10 @@ tramp-completion-handle-file-name-all-completions
                                (delq nil all-user-hosts)))))

             ;; Possible methods.
-           (setq result
-                 (append result (tramp-get-completion-methods m)))))))
+           (unless (and (string-empty-p method)
+                        (not tramp-methods-in-completions))
+             (setq result
+                   (append result (tramp-get-completion-methods m))))))))

      ;; Unify list, add hop, remove nil elements.
      (dolist (elt result)

Option 2 is a N-lines patch (which doesn't exist yet) to minibuffer.el 
(and possibly other files) to add support for the Tramp syntax in 
completions mechanisms.

Option 3, 4, 5 and 6 were suggested by Stefan in his last three posts: 
change the completion-table API, make Tramp teach the rest of the system 
that its methods are a kind of directory, change Tramp's syntax from e.g. 
'/ssh:' to '/ssh/', introduce a new set of completion file name functions. 
I have no idea how complex any of these solutions are, but it's clear that 
none of them can be implemented easily.