From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Albinus Newsgroups: gmane.emacs.bugs Subject: bug#60505: 29.0.60; Fido Mode and Tramp Completion Date: Fri, 03 Feb 2023 16:40:53 +0100 Message-ID: <87mt5udaey.fsf@gmx.de> References: <87k024918k.fsf@jroy.ca> <8dea9f3e0e411c315b04@heytings.org> <87tu15m6g7.fsf@gmx.de> <8dea9f3e0eb47ac9e4ab@heytings.org> <371ba1d0be1f14c7c798@heytings.org> <8aadf0ddd54d67a3213d@heytings.org> <87a62jmwj6.fsf@gmx.de> <87o7qwm3dd.fsf@gmx.de> <43562d4dd9c31382eb40@heytings.org> <87k011dtw2.fsf@gmx.de> <43562d4dd93037f7d01f@heytings.org> <834js4zi69.fsf@gnu.org> <87cz6seanu.fsf@gmx.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21803"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 60505@debbugs.gnu.org, Eli Zaretskii , Gregory Heytings , julien@jroy.ca To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Feb 03 16:42:24 2023 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 1pNyCk-0005Pl-Oj for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 03 Feb 2023 16:42:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNyCT-0007I4-Gj; Fri, 03 Feb 2023 10:42:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNyCR-0007Hf-4J for bug-gnu-emacs@gnu.org; Fri, 03 Feb 2023 10:42:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pNyCQ-0002NI-Oe for bug-gnu-emacs@gnu.org; Fri, 03 Feb 2023 10:42:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pNyCQ-0003Uh-98 for bug-gnu-emacs@gnu.org; Fri, 03 Feb 2023 10:42:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Michael Albinus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 03 Feb 2023 15:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60505 X-GNU-PR-Package: emacs Original-Received: via spool by 60505-submit@debbugs.gnu.org id=B60505.167543887413374 (code B ref 60505); Fri, 03 Feb 2023 15:42:02 +0000 Original-Received: (at 60505) by debbugs.gnu.org; 3 Feb 2023 15:41:14 +0000 Original-Received: from localhost ([127.0.0.1]:39805 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pNyBd-0003Td-LD for submit@debbugs.gnu.org; Fri, 03 Feb 2023 10:41:14 -0500 Original-Received: from mout.gmx.net ([212.227.17.20]:56931) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pNyBX-0003T8-9Z for 60505@debbugs.gnu.org; Fri, 03 Feb 2023 10:41:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1675438856; bh=ndLXk7+fADvm2CAjZcWQ5UXMIpWJGakkgz3RUMWJuNM=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date; b=hrFkc9KN9g4vf4M4YO0PgdjsCq7JGF1FjOxDtbAPT9cV2IzW5n4ito7VKUS+DbE0X ne40gkPCgyK7PYLLEfuBPzkKr/MR9lsWjEl4h5AgQJjHoLjWXFOkncSwutAZ+ycdfp 5XWFca4aDC7Ekf+dUenjXY1Y7ih2CqjHMHztqq/bJElidXlrte8jqf9ZrVYI8YR6+7 1TERcuJo+rTSDH6OyW552DTjd+LD/2WpNsAsG4dejfmvV2BlPdFdpHEsqR3dw5kH3h BI8fSFUns3PeFYhOMljdgxUcqLMsl9nn02YDPNzC13WocHVOdPnI+zY+iWmgFV9A2s z+tOUcWxC4sAQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from gandalf.gmx.de ([185.89.39.22]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MF3HU-1pQ8zP3IGe-00FRcX; Fri, 03 Feb 2023 16:40:55 +0100 In-Reply-To: (Stefan Monnier's message of "Thu, 02 Feb 2023 10:39:25 -0500") X-Provags-ID: V03:K1:El7GpFa/3BFTSdTHonwtZ3RJNGrikBmJem485hO7GvRmlVKrX5g QxFP32HNachd+2xqjwJmWctDdubylArj3Glr03e6JVnGfQiXhZNxXYWaSavQE6dOUK3e0PQ lCCNdc9mbmLv63gCtAU/1WGmNjaF/NaNeKO6dy960fV9DhlYJMoD9ftKzwBCEWukF1amHJG kdEXgoIB5lVdRD8IOLTsQ== UI-OutboundReport: notjunk:1;M01:P0:qVMKWx2eZno=;nEnmO5Ui5agr7ChVODY3XE8bzzF d9YpqdQFOjsncUpPyOX6dR6bjUQDUSUVAtn25DpBTy5f1pbLGueWNPzGW0J3zLdPpydFDpy5F jXq048g55vPHyXVpsftFl4YUQMhhxemtx2KupCwHxNyzJSuphGoVB/UgsvNSo10mowqxQig0j mLiBFaYEfl8cxFX6DAHlPqkCymwJSQ0h2s2DIA7BhchuQMBL/5KFF3FgAZhRcW/D4ZPvR1A5z iYR1gHBYxlJoywf2wmPJ+B8oNuUl6EoceLyddTfqgblHVK9Bfi56NuuSRuSfDAUlyOn6s2k9y YOD8S4STCY04+9a8E4ATcR+BgSuLZLmOXmEP19elFII9X4Uet6Xa9OscHsVztXhBELGkVE5w+ LTCGFX5Tab8hYNEXpsOwJgwSkEDNqHLjuxBa6viEkKv6Lacd+GjKXDKrrzDpVu5ftVO54blU2 pzO5Z4P6pkqHCBpg8HW3FbWHUoTO1O+50uiaVqJP8qRUFT9Y0aqr3lESfq2k0UITdkGl5bNpQ 0uUsTvKbgWKE69wNd74c8exV6/9Ioesf2qELqUZP6R8Bd98t6+g7zrl72XDvK0eplR2m+Y/7R fl3Qdf5Dt8y9X/jrfR1f49p6gLvbgygX10joU62GoZODyPGR5oZ01GiG5GfPinn1ofLh2iWRI j4LxngHb/YrWVBQfc1fUvWnEH6C4e53c+UWZCJXpn6xEywl0K+HhRZX1Z7dnYOZxF2haoINpB t7hdPM6Zm1cu3thKDsgxoHmzTYiw1OzsQaYHkElLZcNdIaidgDOCmpTf6f3wihgPD5/Rq2BF 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:254734 Archived-At: --=-=-= Content-Type: text/plain Stefan Monnier writes: Hi Stefan, >> I could imagine that the completion machinery offers an API that a >> package could register its own idea of a file name syntax. > > The completion code relies on `file-name-directory`, > `directory-file-name`, etc... for that. > > The problem as I see it goes as follows: > > According to `file-name-directory`, in `/ssh:myhost` the part > `ssh:myhost` is an element of the `/` directory. For this reason, the > completion machinery would expect (file-name-all-completions "s" "/") to > include "ssh:myhost" in its return list rather than only "ssh:". > > Now, it's impractical for Tramp to do that. So the end result is the > kind of bug reports we're discussing. > > One way to fix the problem is for Tramp to "teach" the rest of the > system that `/ssh:` is a kind of directory, in which case the completion > machinery would know that (file-name-all-completions "s" "/") returns > "ssh:" and that "myhost" would be included only in the return value of > (file-name-all-completions "" "/ssh:"). I've played with this idea, and the appended patch makes it work, indeed. I had to adapt expand-file-name, file-exists-p, file-name-directory and file-name-nondirectory, but the changes look simple. It works for me now for the default completion styles (basic partial-completion emacs22) as well as for fido-mode, with both the default and simplified Tramp syntax. It doesn't work (yet) for the separated Tramp syntax, but this isn't our major problem, and could be fixed later. Could people check how it plays in their environment? > Another is to change Tramp's syntax so that it uses the regular "/" > separator rather than ":". This would get a similar result but without > touching `file-name-directory` and friends. No way. We have had syntax ambiguities for Tramp in the past, and I don't want to go this painful way, again. > We could also consider introducing a new set of (file-name) functions > > completion-file-name-directory, completion-directory-file-name, ... > > so the completion code can use its own notion of how a file name gets > separated into parts. That's what I have done in the patch, adding such functions for the tramp-completion-file-name-handler implementation. An implementation for directory-file-name wasn't needed, but we could add if necessary. > But introducing such a subtle distinction would likely introduce a lot > of bugs&confusion as well. Perhaps. So this patch isn't a candidate for Emacs 29.1. I would push it to the master branch (when there is positive feedback), and I would also add it to the tramp-2-6-stable branch in the Tramp git repo. By this, the next Tramp 2.6 release on GNU ELPA would contain this change as well, and we could get broader feedback. What do people think? > Stefan Best regards, Michael. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment Content-Transfer-Encoding: quoted-printable diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 21dbd40b1d2..0dc7d68983b 100644 =2D-- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -441,6 +441,8 @@ tramp-default-method-alist (defconst tramp-default-method-marker "-" "Marker for default method in remote file names.") +(add-to-list 'tramp-methods `(,tramp-default-method-marker)) + (defcustom tramp-default-user nil "Default user to use for transferring files. It is nil by default; otherwise settings in configuration files like @@ -1414,9 +1416,13 @@ tramp-password-prompt-not-unique during direct remote copying with scp.") (defconst tramp-completion-file-name-handler-alist - '((file-name-all-completions + '((expand-file-name . tramp-completion-handle-expand-file-name) + (file-exists-p . tramp-completion-handle-file-exists-p) + (file-name-all-completions . tramp-completion-handle-file-name-all-completions) - (file-name-completion . tramp-completion-handle-file-name-completion)= ) + (file-name-completion . tramp-completion-handle-file-name-completion) + (file-name-directory . tramp-completion-handle-file-name-directory) + (file-name-nondirectory . tramp-completion-handle-file-name-nondirect= ory)) "Alist of completion handler functions. Used for file names matching `tramp-completion-file-name-regexp'. Operations not mentioned here will be handled by Tramp's file @@ -1707,7 +1713,6 @@ tramp-dissect-file-name :port port :localname localname :hop hop)) ;; The method must be known. (unless (or nodefault non-essential - (string-equal method tramp-default-method-marker) (assoc method tramp-methods)) (tramp-user-error v "Method `%s' is not known." method)) @@ -2941,6 +2946,30 @@ tramp-connectable-p (and vec (process-live-p (get-process (tramp-buffer-name vec)))) (not non-essential)))) +(defun tramp-completion-handle-expand-file-name (filename &optional direc= tory) + "Like `expand-file-name' for partial Tramp files." + (if (file-name-absolute-p filename) + filename + (concat (or directory default-directory "/") filename))) + +(defun tramp-completion-handle-file-exists-p (filename) + "Like `file-exists-p' for partial Tramp files." + ;; We need special handling only when a method is needed. Then we + ;; regard all files "/method:" or "/[method/" as existent, if + ;; "method" is a valid Tramp method. + (or (and (not (string-empty-p tramp-method-regexp)) + (string-match + (rx + (regexp tramp-prefix-regexp) + (group (regexp tramp-method-regexp)) + (regexp tramp-postfix-method-regexp)) + filename) + ;; Is it a valid method? + (member + filename + (tramp-get-completion-methods (match-string 1 filename)))) + (tramp-run-real-handler #'file-exists-p (list filename)))) + ;; Method, host name and user name completion. ;; `tramp-completion-dissect-file-name' returns a list of ;; `tramp-file-name' structures. For all of them we return possible @@ -3176,6 +3205,27 @@ tramp-get-completion-user-host (unless (zerop (+ (length user) (length host))) (tramp-completion-make-tramp-file-name method user host nil))) +(defun tramp-completion-handle-file-name-directory (filename) + "Like `file-name-directory' for partial Tramp files." + ;; We need special handling only when a method is needed. Then we + ;; return "/method:" or "/[method/", if "method" is a valid Tramp + ;; method. + (if (and (not (string-empty-p tramp-method-regexp)) + (string-match + (rx (group + (regexp tramp-prefix-regexp) + (group (regexp tramp-method-regexp)) + (regexp tramp-postfix-method-regexp))) + filename) + ;; Is it a valid method? + (assoc (match-string 2 filename) tramp-methods)) + (match-string 1 filename) + (tramp-run-real-handler #'file-name-directory (list filename)))) + +(defun tramp-completion-handle-file-name-nondirectory (filename) + "Like `file-name-nondirectory' for partial Tramp files." + (tramp-compat-string-replace (file-name-directory filename) "" filename= )) + (defun tramp-parse-default-user-host (method) "Return a list of (user host) tuples allowed to access for METHOD. This function is added always in `tramp-get-completion-function' --=-=-=--