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#51622: 29.0.50; [PATCH v2] Abbreviate remote home directories in `abbreviate-file-name' Date: Sun, 14 Nov 2021 15:43:20 +0100 Message-ID: <874k8eg5mf.fsf@gmx.de> References: <5ac0b5f3-302c-2f96-771c-8d38088aa573@gmail.com> <87mtmhmh60.fsf@gmx.de> <87a6ihchbo.fsf@gmx.de> <87sfw7u7zw.fsf@gmx.de> <9c2f6b1b-9091-3996-e414-0de4b1618f7f@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26590"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: 51622@debbugs.gnu.org To: Jim Porter Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Nov 14 15:44:11 2021 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 1mmGjq-0006kj-9I for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 14 Nov 2021 15:44:10 +0100 Original-Received: from localhost ([::1]:51714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mmGjo-0005Zo-Fs for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 14 Nov 2021 09:44:08 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:51766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mmGji-0005ZQ-Lw for bug-gnu-emacs@gnu.org; Sun, 14 Nov 2021 09:44:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38053) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mmGji-0007Fg-DY for bug-gnu-emacs@gnu.org; Sun, 14 Nov 2021 09:44:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mmGji-0007gx-CG for bug-gnu-emacs@gnu.org; Sun, 14 Nov 2021 09:44: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: Sun, 14 Nov 2021 14:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51622 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 51622-submit@debbugs.gnu.org id=B51622.163690101129519 (code B ref 51622); Sun, 14 Nov 2021 14:44:02 +0000 Original-Received: (at 51622) by debbugs.gnu.org; 14 Nov 2021 14:43:31 +0000 Original-Received: from localhost ([127.0.0.1]:49599 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmGjC-0007g3-LO for submit@debbugs.gnu.org; Sun, 14 Nov 2021 09:43:31 -0500 Original-Received: from mout.gmx.net ([212.227.15.19]:58211) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mmGjA-0007fp-Qs for 51622@debbugs.gnu.org; Sun, 14 Nov 2021 09:43:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1636901002; bh=/OaLY/nbwC+QwkFzy3WYO9j66jeDyR19CAht2OyKgTs=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=Cd1eliRiiYyv0UrAGg/5jwbDYPa9YQry9ctI2Lqn4i1Z93HxDusx3+AtU/WHBjuG4 7Owgeuhrq2kEdYPMZrTBS3xZ3qTtNM/9vLyPFZsvNhEBX8yiKnaioohJ8NX6Sqm+ge 8j1RQGobn7GCf1QgTzsFBZoseDg9T30vYRs2IXj0= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from gandalf.gmx.de ([79.140.112.102]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M6Db0-1mk5w13r5c-006gPs; Sun, 14 Nov 2021 15:43:22 +0100 In-Reply-To: <9c2f6b1b-9091-3996-e414-0de4b1618f7f@gmail.com> (Jim Porter's message of "Sat, 13 Nov 2021 18:10:50 -0800") X-Provags-ID: V03:K1:J9OAS9KpytrCASG4X0U+fD8vtNfv94x926BcOA+le8/zlyaLWyi p1qNnz1pbq2p1u7cNC1rxmRlMvaj9hVN77U15u7p2c5XJXqTt2q5av030K/tdVlv5pMNZSn 2uIYy0KZlM8dt5y96CLDNCacYLL/rsG5VA/kBwJrvB9l3AEnVaZ/lp59EQ4ZdCPz6v2ft16 st5stRk9o0SYuXFjHEITQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:jSj4JqOVG1w=:2kO2cZkTBRw2pvD+GKPv0e ZVWEvbZE5+TY59VKLlkKNQ8eLn2HT54IO9CX8PHGn+Ua4t0mJNI8UKGogCho+CRBdlfJ3AbNN Sfb3LdL5rwBEyV1zAy+XvpqLLbAzyZtGTus8enx7IEoMlSPUM8yEV+rrfKxxigEy7ACwFl8Ks cHHL3vjAuMMJFVrgT+ygYLq3bxhrahjgNOO4WC5M+6xH3a0KkCMXEuZGnp0OJLi6sMKlzvMtP 09Y9kx+BdW8tWErIB7Q+9sKohlerNFpoUVjz5KsSaAhPwNZ+a4bu4XRR4lxYMAtpCTCqPkZgw NsdJxyfaBIHpCp+m1YXbz1YQzpbFw2QTRfDWQdzRfupNw2Eakh2LAjvasmiJBJ6ervNk2os5H MG9v2TI8rQVJBCSP9lkdF4H9wHBzoDiYMc3wv8aYfeynShRTKKjhDQPJOmZc9I+HKaoacz8Yf hF10RkbxWP6xRSpujuACbOsdWjQa67OJCyJORN8z0gqdMUrxDtCqKplf4p7s1ZLOLZERNJAxA V/bTHBWEPafQdJZXuPG4eIyC5L1r0c+SvAkRFIykuRxCv9izfAdYmallcOzzszzM3nwPstRCV e49ymDHt0JIs7Y/8+AEXOn95lUxjdxCyqFnEcqHYR4cat8+5Jul+a+ry/h/wBunhm1y7S9Ujf MOa+vMFq05c1v3izlxjtgwPGZ5ofDzR7fuM64ckQ/t8zx/2EE1d7OmkSkKCZAZl9oHkVpXEbo 8a0tcElBUBWcqbvVCDJ7fy8xzsTb5PFZmqkwizvd+FneB+zQbL0+JC5tuyM6nvYKTvG9WYbG 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:219948 Archived-At: Jim Porter writes: Hi Jim, >> Nice. I've pushed them to the emacs-28 branch in your name, merged also >> to the master branch. Maybe you could also add a test for quoted file >> names, i.e. a file name "/:/home/albinus/" should *not* be >> abbreviated. See files-tests-file-name-non-special-* tests in >> files-tests.el. > > Ok, I added a test for this in the first patch. Thanks. However, I believe this test shall be called `files-tests-file-name-non-special-file-abbreviate-file-name', like the other non-special tests. And perhaps it shall be located prior `files-tests-file-name-non-special-access-file'. > I added a NEWS entry to mention that `abbreviate-file-name' respects > file name handlers now. I didn't update the Tramp entry though since I > haven't added "~user" support (at least, not yet...). See below for > some explanation. Agreed. > I looked at doing this, but it was a bit more complex than I thought > it would be initially, so I've held off for now. This does seem like a > useful feature though, and would probably be nice to have for local > paths too. It should be possible to enhance `expand-file-name' to > cache the "~user" -> "/home/user" mapping similarly to how > `tramp-sh-handle-expand-file-name' does. > > I could keep working on this patch to add "~user" support, or maybe > that could be a followup for later. ATM, it might be sufficient to push what we have. Adding "~user" support might come later. > Incidentally, another interesting > feature would be abbreviating default methods/users. That's probably > easy when Tramp has filled in those values since the file name has > `tramp-default' properties set. I'm not sure how tricky it would be to > do without those properties though. You cannot trust the `tramp-default' property. It is set when a method or user or host name is expanded as in "/ssh::". But when the host name is used explicitly by the user, as in "/ssh:host:", the property is not set, even if "host" is the default. Same for user. But it shouldn't be too hard to determine the defaults. We have tramp-default-method{-alist}, tramp-default-user{-alist}, and tramp-default-host{-alist}. All needed information is there. > I've tried to reduce as much duplication as possible here by creating > two new functions: `directory-abbrev-make-regexp' and > `directory-abbrev-apply'. The former just takes a directory and > returns a regexp that would match it, and the latter loops over > `directory-abbrev-alist' and applies the transformations. > > I tried to do this via `(tramp-run-real-handler #'abbreviate-file-name > ...)', but it ended up being simpler (and faster to execute) this way. Fine, let's go this way. After your patch, we'll need some backward compatibility voodoo in Tramp, but this can wait until the dust has settle= d. > I also attached a slightly-updated benchmark script as well as new > results. Performance on local file names is the same as before the > patch, and just slightly faster than before with Tramp file > names. (Most of the performance improvements here happened in > bug#51699, so I mainly wanted to maintain the current performance in > this patch.) Good, no regression :-) Some few comments on the code: > --- a/etc/NEWS > +++ b/etc/NEWS > +** Tramp > + > ++++ This shall be rather "---". We don't add documentation (yet) for this new Tramp feature. > +*** Tramp supports abbreviating remote home directories now. > +When calling 'abbreviate-file-name' on a Tramp filename, the result > +will abbreviate the home directory to "~". This might be misleading. ... the result will abbreviate the remote home directory to "/ssh:user@host:~" (for example). > --- a/lisp/net/tramp-sh.el > +++ b/lisp/net/tramp-sh.el > @@ -942,7 +942,8 @@ tramp-vc-registered-read-file-names > ;; New handlers should be added here. > ;;;###tramp-autoload > (defconst tramp-sh-file-name-handler-alist > - '((access-file . tramp-handle-access-file) > + '((abbreviate-file-name . tramp-sh-handle-abbreviate-file-name) > + (access-file . tramp-handle-access-file) Well, I believe we can implement abbreviation also for other Tramp backends, like in tramp-sudoedit.el. So it might be better to call this handler `tramp-handle-abbreviate-file-name'. > +(defun tramp-sh-handle-abbreviate-file-name (filename) This shall be in tramp.el then, as `tramp-handle-abbreviate-file-name'. > + "Like `abbreviate-file-name' for Tramp files." > + (let* ((case-fold-search (tramp-handle-file-name-case-insensitive-p f= ilename)) Please use `case-insensitive-p'. We don't know whether there will be other implementation for this magic function in the future. And we shall not bypass the checks in `tramp-file-name-handler', which are important for parallel invocations of Tramp handlers. > + (home-dir > + (with-parsed-tramp-file-name filename nil > + (with-tramp-connection-property v "home-directory" > + (directory-abbrev-apply (tramp-sh-handle-expand-file-name Same here. Please use `expand-file-name'. Best regards, Michael.