Subject: Re: bug#67930: 29.1; emacs 29.1 follows symlinks when a grep result is selected

From: Eli Zaretskii <[email-masked]>
Date: Wed, 20 Dec 2023 20:46:33 +0200

> Date: Wed, 20 Dec 2023 13:54:19 +0000
> From:  Jurgen De Backer via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> Since emacs 29.1 (possibly already in 28.x), symlinks are resolved
> whenever a file is selected in a grep result in the *grep* buffer.
> For our project, we preferred the old behaviour to remain in the symlink's
> directory.
> Also, when symlinks are resolved and a new grep is done, we may end up
> grepping in another directory than we started from.
> 
> Attached is a patch o revert the behaviour, and to add a custom
> variable compilation-follow-symlinks to disable/enable this behaviour.
> 
> It may be useful to allow the user to select either behaviour.

Thanks, but I don't think this is a matter of user preferences.  We
replaced expand-file-name there by file-truename because in some cases
the former doesn't work: it expands to a file that doesn't exist.  See
bug#8035, where such cases are presented.  We cannot ask the user to
set or reset this option each time they need to work with these or
those file names.

So I don't think the fix you propose is the right one.  I think we
need to use expand-file-name where it works, and file-truename where
expand-file-name doesn't work.  Or maybe just try expand-file-name
first, and if that produces a file name that fails file-exists-p, try
file-truename.

Would you like to propose and test a patch along these lines?