From e049a25599c8abf693b35736e76ba4412cbc7cbc Mon Sep 17 00:00:00 2001 From: Gregory Heytings 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