all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Daniel Mendler <mail@daniel-mendler.de>
Cc: Michael Albinus <michael.albinus@gmx.de>, 53053@debbugs.gnu.org
Subject: bug#53053: 28.0.90; Tramp completion bug of path /sudo::~/
Date: Mon, 07 Feb 2022 16:51:32 -0500	[thread overview]
Message-ID: <jwv35ku1i28.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <e55a5c8e-fd2a-8b1f-021b-865bd45fc188@daniel-mendler.de> (Daniel Mendler's message of "Fri, 4 Feb 2022 01:11:56 +0100")

> For example both
>
> (completion-boundaries "/sudo::~/" #'read-file-name-internal nil "")
> (completion-boundaries "/sudo::/" #'read-file-name-internal nil "")
>
> incorrectly return (8 . 0) as boundaries.

The problem comes from the quoting/unquoting.

`read-file-name-internal` is used for file names that will pass through
`substitute-in-file-name` (as is the case for file names read from
`read-file-name`).

So when you ask to complete "/sudo::~/", Emacs first expands it with
`substitute-in-file-name` and then asks for the completion.
The problem is that the expansion of "/sudo::~/" is exactly the same as
the expansion of "/sudo::~"

So maybe the "right fix" is to change Tramp's handling of
`substitute-in-file-name` such that
"/sudo::~" returns "/sudo:root@<host>:~" instead of
"/sudo:root@<host>:~/",
but in the mean time I installed the patch below which should avoid
this problem at least in the original recipe.  You can still bump into
side effects of the underlying problem, of course.

As pointed out in the comment in `completion--sifn-requote`, this
function is fundamentally asked to do the impossible.


        Stefan


diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index c9f58239403..36b8d808417 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2932,6 +2932,10 @@
   (let* ((ustr (substitute-in-file-name qstr))
          (uprefix (substring ustr 0 upos))
          qprefix)
+    (if (eq upos (length ustr))
+        ;; Easy and common case.  This not only speed things up in a very
+        ;; common case but it also avoids problems in some cases (bug#53053).
+        (cons (length qstr) #'minibuffer-maybe-quote-filename)
     ;; Main assumption: nothing after qpos should affect the text before upos,
     ;; so we can work our way backward from the end of qstr, one character
     ;; at a time.
@@ -2951,7 +2955,7 @@
                                    (substitute-in-file-name
                                     (substring qstr 0 (1- qpos)))))
         (setq qpos (1- qpos)))
-      (cons qpos #'minibuffer-maybe-quote-filename))))
+        (cons qpos #'minibuffer-maybe-quote-filename)))))
 
 (defalias 'completion--file-name-table
   (completion-table-with-quoting #'completion-file-name-table







  parent reply	other threads:[~2022-02-07 21:51 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-06 12:52 bug#53053: 28.0.90; Tramp completion bug of path /sudo::~/ Daniel Mendler
2022-01-07 14:05 ` Michael Albinus
2022-02-04  0:11   ` Daniel Mendler
2022-02-05 14:42     ` Michael Albinus
2022-02-05 18:10     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-07 16:11       ` Daniel Mendler
2022-02-07 21:51     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-02-17  9:43       ` Michael Albinus
2022-02-17 13:08         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-17 15:04           ` 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

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

  git send-email \
    --in-reply-to=jwv35ku1i28.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=53053@debbugs.gnu.org \
    --cc=mail@daniel-mendler.de \
    --cc=michael.albinus@gmx.de \
    --cc=monnier@iro.umontreal.ca \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.