Subject: bug#54001: 29.0.50; abbreviate-file-name has side-effects

From: Jim Porter <[email-masked]>
Date: Mon, 14 Feb 2022 09:52:32 -0800

On 2/14/2022 9:19 AM, Stefan Monnier via Bug reports for GNU Emacs, the 
Swiss army knife of text editors wrote:
> Package: Emacs
> Version: 29.0.50
> 
> 
> Since:
> 
>      commit bf505a63f98ed61934a8fb81ec65c96859606b6e
>      Author: Jim Porter <[email-masked]>
>      Date:   Mon Nov 15 13:33:07 2021 +0100
> 
>      Support abbreviating home directory of Tramp filenames
> 
> `abbreviate-file-name` has significantly changed in its behavior:
> - it's slower (because it goes through file-name-handlers)
> - it can have very visible side effects like prompting the user for a password.
> 
> I haven't measured the slowdown, so I'll assume it's acceptable, but
> asking for a password (or contacting a remote host) is not.

Sorry about that. I did what I could to minimize the slowdown (including 
some more general optimizations to make Tramp faster). There are some 
benchmarks in the original bug here (these are with 1000 iterations; 
you'll want to compare the first section with the last): 
<https://lists.gnu.org/archive/html/bug-gnu-emacs/2021-11/msg01293.html>.

> I suggest we take a step back and think of how to get that feature
> without having to contact any remote host during `abbreviate-file-name`.
> Maybe we can do that by making Tramp opportunistically add entries to
> `directory-abbrev-alist` when it performs expansion?

I think Michael Albinus suggested doing that in the original bug, 
although I was concerned about modifying defcustoms invisibly like that. 
Is that ok to do? Another option might be to store the abbreviations for 
a given file-name-handler somewhere internally and consult that when 
calling that file-name-handler's implementation of `abbreviate-file-name'.

Maybe this patch should be backed out for now; it shouldn't be 
interrupting the user. (I thought I'd tested that, but maybe it was on 
an earlier revision of the patch.) I'll probably have time to look into 
a new solution in a few weeks, but anyone else who's interested should 
feel free to fix it in the meantime.