unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Gregory Heytings <gregory@heytings.org>
To: Michael Albinus <michael.albinus@gmx.de>
Cc: 60505@debbugs.gnu.org, Julien Roy <julien@jroy.ca>
Subject: bug#60505: 29.0.60; Fido Mode and Tramp Completion
Date: Wed, 01 Feb 2023 18:12:43 +0000	[thread overview]
Message-ID: <43562d4dd9c31382eb40@heytings.org> (raw)
In-Reply-To: <87o7qwm3dd.fsf@gmx.de>

[-- Attachment #1: Type: text/plain, Size: 1800 bytes --]


>> It's correct that the same problem is present in Emacs 28, but it is 
>> not in Emacs 27, so it's a regression.  As I tried to explain in 
>> bug#50387, the problem is that once Tramp is loaded, Tramp methods are 
>> returned when completions are requested for a root directory ("/"). 
>> This problem is even worse since commit d5c6bf9625: prior to that 
>> commit only the 'scp' and 'scpx' methods were returned (in emacs -Q), 
>> now all methods are returned.  And this confuses the flex and substring 
>> completion mechanisms.
>
> Yes. But this is not a Tramp fault.
>

It definitely is Tramp's "fault".

>
> Completion styles like flex (and substring, didn't test) do ignore Tramp 
> file name syntax. They simply think in terms of file name parts, 
> separated by "/". This is not appropriate for remote file names.
>

What filenames are is defined for example by POSIX in its Definitions 
chapter ("Filename", "Pathname", "Pathname Resolution").  It is quite 
clear in those definitions that there is no place for a _method_ or a 
_host name_ in file names.  Something with a method, a host name and a 
path is a different beast: it's an URI.  And it's not a coincidence if 
(absolute) file names start with a slash, and URI do _not_ start with a 
slash.

Tramp decided, for a reason I do not clearly understand, to invent URIs 
starting with a slash.  File name completion mechanisms rightly assume 
that file names correspond to the standard syntax of file names, and there 
is no reason (and, for that matter, no reliable way) to fix the current 
problem at the level of completion styles.

So I have yet another proposal: add a variable to let users (and modes) 
decide whether Tramp methods should be returned when completions for the 
root directory are requested.  Patch attached.

[-- Attachment #2: Improve-handling-of-Tramp-methods-by-completion-styl.patch --]
[-- Type: text/x-diff, Size: 4186 bytes --]

From e049a25599c8abf693b35736e76ba4412cbc7cbc Mon Sep 17 00:00:00 2001
From: Gregory Heytings <gregory@heytings.org>
Date: Wed, 1 Feb 2023 18:06:49 +0000
Subject: [PATCH] Improve handling of Tramp methods by completion styles.

* lisp/net/tramp.el (tramp-methods-in-completions): New defcustom.
(tramp-completion-handle-file-name-all-completions): Use it.

* lisp/icomplete.el (icomplete--fido-mode-setup): Add 'basic'
after 'flex' in the completion styles, for cases where 'flex' does
not return anything.  This is required by Tramp.  Also set the new
defcustom 'tramp-methods-in-completions' to nil.

* doc/misc/tramp.texi (File name completion): Replace the footnote
about the limitation of the 'substring' and 'flex' completion
styles: suggest to use the new defcustom.

Fixes bug#50387, bug#51386, bug#52758, bug#53513, bug#54042 and
bug#60505.
---
 doc/misc/tramp.texi |  7 +++----
 lisp/icomplete.el   |  7 ++++++-
 lisp/net/tramp.el   | 21 +++++++++++++++++++--
 3 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/doc/misc/tramp.texi b/doc/misc/tramp.texi
index 56436d32970..99f317dbbb8 100644
--- a/doc/misc/tramp.texi
+++ b/doc/misc/tramp.texi
@@ -3497,10 +3497,9 @@ File name completion
 Type @kbd{s h @value{postfixhop}} for the minibuffer completion to
 @samp{@value{prefix}ssh@value{postfixhop}}.  Typing @kbd{@key{TAB}}
 shows host names @value{tramp} extracts from @file{~/.ssh/config}
-@c bug#50387
-file, for example@footnote{Some completion styles, like
-@code{substring} or @code{flex}, require to type at least one
-character after the trailing @samp{@value{postfixhop}}.}.
+file, for example@footnote{For some completion styles, like
+@code{substring} or @code{flex}, it is necessary to set
+@code{tramp-methods-in-completions} to @code{t} for this to happen.}.
 
 @example
 @group
diff --git a/lisp/icomplete.el b/lisp/icomplete.el
index 014f38b2024..079e59e28e1 100644
--- a/lisp/icomplete.el
+++ b/lisp/icomplete.el
@@ -414,7 +414,12 @@ icomplete--fido-mode-setup
                 icomplete-show-matches-on-no-input t
                 icomplete-hide-common-prefix nil
                 icomplete-scroll (not (null icomplete-vertical-mode))
-                completion-styles '(flex)
+                ;; The 'basic' style is required by Tramp.  See
+                ;; bug#51386, bug#52758, bug#53513, bug#54042 and
+                ;; bug#60505.
+                completion-styles '(flex basic)
+                ;; Tell Tramp to display its methods lazily.
+                tramp-methods-in-completions nil
                 completion-flex-nospace nil
                 completion-ignore-case t
                 read-buffer-completion-ignore-case t
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 1916d50af03..533186d1633 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -812,6 +812,21 @@ tramp-syntax
   :initialize #'custom-initialize-default
   :set #'tramp-set-syntax)
 
+(defcustom tramp-methods-in-completions t
+  "How Tramp methods are displayed while completing file names.
+
+When t, Tramp methods are displayed unconditionally when
+completing file names, that is, as soon as completions are
+requested for the root directory.
+
+When nil, Tramp methods are displayed lazily when completing file
+names, that is, they are displayed only when no actual file in
+the root directory matches the current user input."
+  :type '(choice (const :tag "Unconditionally" t)
+                 (const :tag "Lazily" nil))
+  :require 'tramp
+  :version "29.1")
+
 (defvar tramp-prefix-format)
 (defvar tramp-prefix-regexp)
 (defvar tramp-method-regexp)
@@ -3022,8 +3037,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)
-- 
2.39.0


  reply	other threads:[~2023-02-01 18:12 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-02 19:37 bug#60505: 29.0.60; Fido Mode and Tramp Completion Julien Roy
2023-01-03  8:56 ` Michael Albinus
2023-01-05 13:07 ` Gregory Heytings
2023-01-05 13:55   ` Michael Albinus
2023-01-05 14:14     ` Gregory Heytings
2023-01-06  9:51       ` Gregory Heytings
2023-01-14 21:37         ` Gregory Heytings
2023-01-15 19:23           ` Michael Albinus
2023-01-15 22:38             ` Gregory Heytings
2023-01-18 12:30               ` Michael Albinus
2023-02-01 18:12                 ` Gregory Heytings [this message]
2023-02-01 20:15                   ` Michael Albinus
2023-02-01 21:27                     ` Gregory Heytings
2023-02-02  6:37                       ` Eli Zaretskii
2023-02-02  8:25                         ` Michael Albinus
2023-02-02  9:15                           ` Eli Zaretskii
2023-02-02 15:39                           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-03 15:40                             ` Michael Albinus
2023-02-03 18:43                               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-03 19:23                                 ` Michael Albinus
2023-02-03 20:51                                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-04 16:04                                     ` Michael Albinus
2023-02-04 16:48                                       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-03 22:33                               ` Gregory Heytings
2023-02-04  9:54                                 ` Michael Albinus
2023-02-06 17:26                               ` Michael Albinus
2023-02-06 17:41                                 ` Gregory Heytings
2023-02-07  0:35                                 ` Michael Heerdegen
2023-02-07  8:54                                   ` Michael Albinus
2023-02-07 18:20                                     ` Michael Heerdegen
2023-02-07 18:30                                       ` Michael Albinus
2023-02-07 20:39                                         ` Michael Heerdegen
     [not found]                                           ` <87357h19qj.fsf@dick>
2023-02-08  8:05                                             ` Michael Albinus
2023-02-08 11:27                                               ` dick
2023-02-08 13:08                                                 ` Michael Albinus
2023-02-08 13:20                                                   ` Eli Zaretskii
2023-02-08 14:13                                                     ` dick
2023-02-08 14:42                                                       ` Michael Albinus
2023-02-08 13:30                                                   ` dick
2023-02-08 15:04                                           ` Michael Albinus
2023-02-07 22:22                                         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-08 15:11                                           ` Michael Albinus
2023-02-08 16:18                                             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-08 17:59                                               ` Michael Albinus
2023-02-08 19:03                                                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-10 16:55                                                   ` Michael Albinus
2023-02-12 19:26                                                     ` Michael Albinus
2023-02-07 19:18                                     ` Michael Heerdegen
2023-02-08 15:09                                       ` Michael Albinus
2023-02-09  0:38                                         ` Michael Heerdegen
2023-02-03  0:23                         ` Gregory Heytings
2023-02-03  7:43                           ` Juri Linkov
2023-02-03  8:39                             ` Michael Albinus
2023-02-03 12:01                             ` Eli Zaretskii
2023-02-02 15:16                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-02 15:05     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-05 20:58   ` Julien Roy
     [not found] <874k4xblcy.fsf.ref@aol.com>
2022-02-17 14:47 ` bug#54042: 29.0.50; fido-mode and ssh not listing hosts Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-17 16:43   ` Michael Albinus
     [not found]   ` <handler.54042.D60505.167623003032452.notifdone@debbugs.gnu.org>
2023-02-15 18:31     ` bug#54042: closed (Re: bug#60505: 29.0.60; Fido Mode and Tramp Completion) Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-16  8:51       ` Michael Albinus
2023-02-18 17:25         ` Michael Albinus
2023-02-19  2:04           ` Ergus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-19  9:53             ` Michael Albinus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=43562d4dd9c31382eb40@heytings.org \
    --to=gregory@heytings.org \
    --cc=60505@debbugs.gnu.org \
    --cc=julien@jroy.ca \
    --cc=michael.albinus@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).