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

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 06 Apr 2023 10:28:02 +0000

Your bug report

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

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
62413: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=62413
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#62413: 29.0.60; [PATCH] save-place-mode cannot restore saved position
From: Eli Zaretskii <[email-masked]>
To: Liu Hui <[email-masked]>
Cc: [email-masked], [email-masked]
Date: Thu, 06 Apr 2023 13:27:55 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: Liu Hui <[email-masked]>
> Date: Tue, 4 Apr 2023 09:37:26 +0800
> Cc: Eli Zaretskii <[email-masked]>, [email-masked], [email-masked]
> 
> Ruijie Yu <[email-masked]> 于2023年4月3日周一 11:06写道：
> 
> > Two minor comments below.
> >
> > > @@ -90,8 +92,32 @@ save-place-forget-unreadable-files
> > >  (defcustom save-place-abbreviate-file-names nil
> > > [...]
> > > +  :set (lambda (sym val)
> > > +         (set-default sym val)
> > > +         (let ((fun (if val 'abbreviate-file-name 'expand-file-name)))
> >
> > I believe function quotes "#'" are preferred over simple quotes "'" when
> > dealing with functions.
> 
> OK
> 
> > > @@ -214,7 +241,11 @@ save-place-to-alist
> > >                           ((and (derived-mode-p 'dired-mode) directory)
> > >                            (let ((filename (dired-get-filename nil t)))
> > >                              (if filename
> > > -                                `((dired-filename . ,filename))
> > > +                                   (list
> > > +                                    (cons 'dired-filename
> > > +                                          (if save-place-abbreviate-file-names
> > > +                                              (abbreviate-file-name filename)
> > > +                                            filename)))
> >
> > It seems that you rewrote the quote-backquote thing with regular
> > list-cons construct -- no comments on that.  I noticed that here, and in
> > a few other places, you are reusing the exact `if' construct multiple
> > times.  Does that warrant defining a helper function?
> 
> I feel such a function is too short.
> 
> > Also, while I was about to send the mail, regarding the docstring of
> > `save-place-abbreviate-file-names', instead of letting the user enable
> > `save-place-mode', would it be better if you directly call facilities in
> > saveplace to load `save-place-alist' from file system, within your :set
> > function?
> 
> Thanks for the suggestion. I have added `save-place-load-alist-from-file'
> to the :set function in the new patch.

Thanks, I installed this on the master branch, and I'm therefore
closing this bug.

Subject: 29.0.60; [PATCH] save-place-mode cannot restore saved position
From: Liu Hui <[email-masked]>
To: [email-masked]
Date: Fri, 24 Mar 2023 10:19:07 +0800
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi,

save-place-mode cannot restore last saved position when
`save-place-abbreviate-file-names' is non-nil:

- emacs -Q
- M-x save-place-mode, and set save-place-abbreviate-file-names to t
- open a file, scroll to some position, and kill buffer
- reopen the file, the position is not restored

The reason is it uses abbreviated file names when saving positions to
`save-place-alist', but uses full file names to find position in
`save-place-alist'.

Best,
Liu Hui
From 468b699e3123c008d8a5bd050c1efc3ad926b198 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 | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lisp/saveplace.el b/lisp/saveplace.el
index 7512fc87c5d..5262f574efc 100644
--- a/lisp/saveplace.el
+++ b/lisp/saveplace.el
@@ -353,8 +353,11 @@ 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* ((item (if (and (stringp buffer-file-name)
+                        save-place-abbreviate-file-names)
+                   (abbreviate-file-name buffer-file-name)
+                 buffer-file-name))
+         (cell (assoc item save-place-alist)))
     (if cell
 	(progn
 	  (or revert-buffer-in-progress-p
--
2.25.1