Subject: bug#62413: 29.0.60; [PATCH] save-place-mode cannot restore saved position

From: Eli Zaretskii <[email-masked]>
Date: Sat, 25 Mar 2023 17:17:11 +0300

> From: Liu Hui <[email-masked]>
> Date: Sat, 25 Mar 2023 22:14:02 +0800
> Cc: [email-masked]
> 
> > Wouldn't it be best to always test for abbreviated file name if the
> > full file name fails to match?  E.g., it could be that the user turned
> > on save-place-abbreviate-file-names for a while, then turned it off
> > (or vice versa), thus causing mixed file names in the saved history.
> > It would also make the code simpler, I think.
> 
> I agree that it is better to consider mixed file names. Please see the
> updated patch.
> 
> From ad5f2d4f3c878a15c2fd1d2eca09e2f2fbecec15 Mon Sep 17 00:00:00 2001
> From: Liu Hui <[email-masked]>
> Date: Fri, 24 Mar 2023 10:08:12 +0800
> Subject: [PATCH] Restore positions for abbreviated file names in saveplace.el
> 
> * lisp/saveplace.el (save-place-find-file-hook): Use abbreviated file
> name when `save-place-abbreviate-file-names' is non-nil.
> ---
>  lisp/saveplace.el | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/lisp/saveplace.el b/lisp/saveplace.el
> index 7512fc87c5d..6c3ed34f198 100644
> --- a/lisp/saveplace.el
> +++ b/lisp/saveplace.el
> @@ -353,7 +353,14 @@ save-place-find-file-hook
>    "Function added to `find-file-hook' by `save-place-mode'.
>  It runs the hook `save-place-after-find-file-hook'."
>    (or save-place-loaded (save-place-load-alist-from-file))
> -  (let ((cell (assoc buffer-file-name save-place-alist)))
> +  (let ((cell (and (stringp buffer-file-name)
> +                   (if save-place-abbreviate-file-names
> +                       (or (assoc (abbreviate-file-name buffer-file-name)
> +                                  save-place-alist)
> +                           (assoc buffer-file-name save-place-alist))
> +                     (or (assoc buffer-file-name save-place-alist)
> +                         (assoc (abbreviate-file-name buffer-file-name)
> +                                save-place-alist))))))
>      (if cell

But now testing save-place-abbreviate-file-names here should be
redundant, right?

Also, I think we should first test buffer-file-name, and only after
that its abbreviated variant.