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] Abbreviate remote home directories in `abbreviate-file-name' Date: Sat, 06 Nov 2021 16:34:47 +0100 Message-ID: <87mtmhmh60.fsf@gmx.de> References: <5ac0b5f3-302c-2f96-771c-8d38088aa573@gmail.com> 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="33014"; 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 Sat Nov 06 16:35:21 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 1mjNiy-0008Nm-ED for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 06 Nov 2021 16:35:20 +0100 Original-Received: from localhost ([::1]:54114 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mjNix-0001qp-88 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 06 Nov 2021 11:35:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44826) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mjNig-0001qX-Hy for bug-gnu-emacs@gnu.org; Sat, 06 Nov 2021 11:35:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38629) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mjNig-00052y-7F for bug-gnu-emacs@gnu.org; Sat, 06 Nov 2021 11:35:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mjNif-00081Z-Rw for bug-gnu-emacs@gnu.org; Sat, 06 Nov 2021 11:35:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michael Albinus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 06 Nov 2021 15:35:01 +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.163621289930833 (code B ref 51622); Sat, 06 Nov 2021 15:35:01 +0000 Original-Received: (at 51622) by debbugs.gnu.org; 6 Nov 2021 15:34:59 +0000 Original-Received: from localhost ([127.0.0.1]:50175 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mjNid-00081D-1D for submit@debbugs.gnu.org; Sat, 06 Nov 2021 11:34:59 -0400 Original-Received: from mout.gmx.net ([212.227.17.21]:52129) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mjNia-00080w-Ik for 51622@debbugs.gnu.org; Sat, 06 Nov 2021 11:34:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1636212889; bh=ag41Zgp4asPKaeBg8UEV2+lBEgHKD5SZjOHibzR7+wY=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=bi70st0FdxYfaELMaMZ/sM+2RAFZUUzGRqth5w0Lm6Vku9xsQBGGQhqPO4CFndsbN 13RWz0dUsdd3dl/X7dLpebLV9sjxF3YBcrLeptDXbJjqhB+v3/SQz+KIqKSLxLcGlW Ic22POHEOQH5TOfsjr5eLS75RbtpJGf8sAu/7iyM= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from gandalf.gmx.de ([79.140.112.248]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Mr9Bu-1mLaIA41Ju-00oG38; Sat, 06 Nov 2021 16:34:49 +0100 In-Reply-To: <5ac0b5f3-302c-2f96-771c-8d38088aa573@gmail.com> (Jim Porter's message of "Fri, 5 Nov 2021 20:44:44 -0700") X-Provags-ID: V03:K1:7zZVbTQcqz7Kh3hRR1RWK2uOz1TyJ/SvnakzTcIY7SXEPAae/PQ ZYssg+2CNzUCKRecSx7xLd3KvkxAb8LV0Em+juVoJgfivYgbLftcjNQF3KzUglIrS9Y/WUF UvJcCYMDOW2tIFGPaeRLQaQjKqtOZtQE+efb0h6GSR00v9/4yvbkidHEg3+IuXIaIAvpqSA nc5ozBpnOJ75GHuZCHfPQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:eIKLQr0XeYA=:6gjnaHf0i7TLq1a6XeJsPQ h/1/yVW9hubTKFMf6hSbXezoQc2ideleroD0tmimgRDRaO7U8bpMXXIdb1aktiu2L6i0mTSXA +cwpCftaPf1IccMLEltTtotqXKk19UsjSlm7QjMhU8N0FZ/x+wL3KjUhnV607ib6pOUP1/N7F DDYnPQ+R7RwoWnDwbXpSXn9r5uxicbHpQ/f0HeNLd6xovDoecxcsphz/kDF1X2ho1ro9vI5Oa cp40BPF49ZyTdojp25rVOA8YF321g7ignRd9a+ixxWrf85hPlDK4pEktQnmV8v3MdtgHHlcRg TZsq+z9iwKxLzjEgi+dal9SB8Npo03M+gJKkyGiwGaTEqgohCmT6uNXPnw8ASOobhZdNudw3k vIL1dH5VyU8tSKbqhhdmzbFrhcT57C/yxnmY9JAlE5tUYL3AvzTmOiSv4jpH4iGE8HHOoCXdY Zsfyxu7xxypX58OPTPR9ZOS8Ggq8gpKAy36i0vlb399Cg/FybRqdZk0E/BLCuWFD5CMKBxfVM C+aOna8l1aFNEoqQ7qGja0sEBoORbMHznbtkN4EpfGYN+JHO5v+uW534LaUYmyQYszHeDKj0N Z6DDc/P0NDnkT/sztD3me2gF9y+D0qHpkw6w1QtV7s4Vn+yRUh7ttEbrzGGJABIm0KAMiDQBb 928RDurk4jC4jnHFArANFWQvaa6gaftOrndqLYmjF73QstZRoTw5ZA4bvpuh3sDJYPPPNTzlE offPEOiG9ZA7VryRoW4DR6+atUdmfVxd/R/evm9rGCVHlfTeYHOtiv6ybKEJG77plV/n5E6M 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:219111 Archived-At: --=-=-= Content-Type: text/plain Jim Porter writes: Hi Jim, > Currently, `abbreviate-file-name' abbreviates home directories, but > only for the local system. For example: > > $ emacs -Q > M-: (abbreviate-file-name "/home/jim/src") RET > ;; => "~/src" > M-: (abbreviate-file-name "/sshx:localhost:/home/jim/src") RET > ;; => "/sshx:localhost:/home/jim/src" > > It'd be nice to abbreviate TRAMP home dirs, especially for the buffer > list, where the long length of TRAMP paths means that I often just see > the same leading bits of the paths repeated in the File column. As a > result, it can be hard to tell the exact file it refers to. (Of > course, as a workaround, I could just widen the window.) Nice idea :-) > Attached is a patch series to do this, but the patches probably > warrant some explanation. First, I removed `automount-dir-prefix'; > it's been obsolete since 24.3, and it would have made implementation > of the second part more complex. This is not related to the problem, and it isn't needed because I propose to skip your second patch (see below). Personally I have no opinion about, you might apply this patch if you believe it makes sense, but independently from the feature request. > Second, I removed the caching of the abbreviated home dir. Since > adding TRAMP support means there are multiple home dirs (one per > host), keeping the caching would have been fairly complex, and it's > already the source of potential bugs (e.g. when temporarily setting > HOME to something else). I did some benchmarking on this (see > attached), and while it is indeed slower without the caching, I don't > think it's worth keeping the caching around. The real performance cost > comes from calling `abbreviate-file-name' with a TRAMP file (even > before my patch), but abbreviating a local file is quite fast, even > with a pathologically large `directory-abbrev-alist'. I also wrote a > couple of unit tests to make sure this function works correctly. I disagree. We shall keep the cached abbreviated-home-dir as *local* home directory. Remote home directories shall be handled in Tramp, and nowhere else. This is a general design goal which I try to follow. Mixing Tramp needs with other packages is good for trouble, and shall be avoided if possible. > Finally, I added the actual TRAMP support. This has a pretty > significant performance hit to TRAMP files. Looking at profiles, > this appears to be because my patch calls both > `file-name-case-insensitive-p' and `file-remote-p' on the TRAMP path, > and these duplicate quite a bit of work. Is there a way to make this > more efficient (e.g. by getting the file handler just once instead of > twice)? It might also be useful to add some unit tests here, but I > wasn't 100% sure how to do that with TRAMP paths (the tests in my > benchmark actually open an SSH connection, so that probably won't work > on all systems). I believe there is a much simpler solution: Add the following entry (derived from your example) to directory-abbrev-alist: ("\\`/sshx:localhost:/home/jim" . "/sshx:localhost:~") The appended patch is a proof of concept w/o any systematic testing, it is not ready for commit. You might use it in order to get the idea, and to provide an applicable patch. It handles only tramp-sh.el; other Tramp backends might need something similar. Tramp tests could be added to tramp-tests.el. You'll see there a Tramp mockup method which gives you the possibility to add a test w/o a working ssh connection or alike. > In addition to the patches, I've also attached a simple benchmark > script that I used to measure the performance of these patches as well > as the results from my system. The performance for local paths is > still quite good I think, and even the worst-case scenario for TRAMP > paths (abbreviating with a 500-item `directory-abbrev-alist') clocks > in at 4.6ms per call. It'd be nice to make that faster, but maybe > that's the best we can do if we want this feature. I'm eager to see new figures with an adapted patch. Best regards, Michael. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment diff --git a/lisp/tramp-sh.el b/lisp/tramp-sh.el index 6f3b3245..974e3f3a 100644 --- a/lisp/tramp-sh.el +++ b/lisp/tramp-sh.el @@ -2723,6 +2723,14 @@ the result will be a local, non-Tramp, file name." (format "cd %s && pwd" (tramp-shell-quote-argument uname))) (with-current-buffer (tramp-get-buffer v) (goto-char (point-min)) + (add-to-list + 'directory-abbrev-alist + (cons + (concat + "\\`" (tramp-make-tramp-file-name v 'noloc 'nohop) + (buffer-substring (point) (point-at-eol))) + (concat + (tramp-make-tramp-file-name v 'noloc 'nohop) uname))) (buffer-substring (point) (point-at-eol))))) (setq localname (concat uname fname)))) ;; There might be a double slash, for example when "~/" --=-=-=--