From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#53053: 28.0.90; Tramp completion bug of path /sudo::~/ Date: Mon, 07 Feb 2022 16:51:32 -0500 Message-ID: References: <58e88707-e8e1-604d-945a-4a1e234b86a5@daniel-mendler.de> <87sftz8wul.fsf@gmx.de> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28122"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Michael Albinus , 53053@debbugs.gnu.org To: Daniel Mendler Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 07 22:52:31 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nHBvx-00075s-CA for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 07 Feb 2022 22:52:29 +0100 Original-Received: from localhost ([::1]:38562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHBvv-00018d-Ci for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 07 Feb 2022 16:52:28 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:50728) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHBvW-00017e-Gx for bug-gnu-emacs@gnu.org; Mon, 07 Feb 2022 16:52:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50113) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHBvW-0006pg-8F for bug-gnu-emacs@gnu.org; Mon, 07 Feb 2022 16:52:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nHBvW-0004rp-7v for bug-gnu-emacs@gnu.org; Mon, 07 Feb 2022 16:52:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 07 Feb 2022 21:52:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53053 X-GNU-PR-Package: emacs Original-Received: via spool by 53053-submit@debbugs.gnu.org id=B53053.164427070518686 (code B ref 53053); Mon, 07 Feb 2022 21:52:02 +0000 Original-Received: (at 53053) by debbugs.gnu.org; 7 Feb 2022 21:51:45 +0000 Original-Received: from localhost ([127.0.0.1]:44010 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nHBvF-0004rK-1n for submit@debbugs.gnu.org; Mon, 07 Feb 2022 16:51:45 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:14563) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nHBvD-0004r6-4j for 53053@debbugs.gnu.org; Mon, 07 Feb 2022 16:51:43 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id EC800805D6; Mon, 7 Feb 2022 16:51:36 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 646C0805CE; Mon, 7 Feb 2022 16:51:35 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1644270695; bh=XoRlJ9gjuTJMT+wcSKgONdGaz+5UvPJmlCV1tLC2nPg=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=j8g4GZWYs0Tw3hjacYlUiKEHzEeaZQGFWllvuQj+DJ3oUU6KCp4XIsoDqYPKo/Akk ba/aOCdNwf9K3Op2gdkQv+GqVh91cv39BUNowMIUIfVOvRY+gVvE2EvbkxWGWSNA83 EHegSuHfLSiJJjW8QuVVXnI6lhguay/rn/xtEQEuxnSDml7CXwuHkWKG/h1ErwXzDM UOpeqnr+fV/cpwk99tKJs+THWjyTG8blONHsPOBICK5xCMX+T/pEC+s4vLUMPXohxG q0BaZ7C6y8iTKRZdwuONdOteGpBNtyCwqcoiEBJheKi7SDJip6eEGzwbtt7i90q7Jd N0922bGYfI30Q== Original-Received: from pastel (76-10-138-212.dsl.teksavvy.com [76.10.138.212]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 29F991207E4; Mon, 7 Feb 2022 16:51:35 -0500 (EST) In-Reply-To: (Daniel Mendler's message of "Fri, 4 Feb 2022 01:11:56 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:226286 Archived-At: > 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@:~" instead of "/sudo:root@:~/", 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