Subject: Re: bug#13882: 24.2; saveplace.el limit drop least recently used

From: Dmitry Gutov <[email-masked]>
Date: Thu, 07 Mar 2013 19:32:45 +0400

Kevin Ryde <[email-masked]> writes:
> When saveplace.el reaches save-place-limit, the file positions retained
> via ~/.emacs-places are the first limit-many in alphabetical order.
> I hoped instead it would be the first limit-many most recently used.
> Ie. drop the least recently visited files in order to enforce the limit.
>
> I struck this when I reached my save-place-limit with lots of files I
> had visited long ago but which happened to be alphabetically before ones
> I was visiting now.  The save-place feature no longer saved places
> across sessions for files I now visited.
> <example>

I can confirm that this is a problem, and it doesn't look "minor" in the
context of this package.

> ...
> I get some joy from not sorting save-place-alist when saving per change
> below.
>
> I believe save-place-to-alist keeps save-place-alist in "most recent
> first" order (by delq and re-push to move an existing entry to the
> start), and that that order should be preserved when saving.

I like the solution, but according to the ChangeLog the decision to sort
the list was made at the request of a user, who apparently has to merge
saveplace history files from time to time:

2010-12-29  Karl Fogel  <[email-masked]>

	* saveplace.el (save-place-alist-to-file): Save list sorted and
	pretty-printed, so that it is mergeable by line-based text merging,
	as suggested by Iain Dalton <iain.dalton {_AT_} gmail.com>.

Paging the author.

Karl, do you think this consideration is still important? I don't see a
reasonable way to keep the list easy to merge and still retain the
"most-recently used" information.

You either keep the list unsorted (and continually shuffle the
elements), or store some timestamps, which will also be a source of
merge conflicts.

> 2013-03-04  Kevin Ryde  <[email-masked]>
>
> 	* saveplace.el (save-place-alist-to-file): Don't `sort'
> 	save-place-alist alphabetically, keep it in "most recent first" order.
> 	This ensures save-place-limit drops the least recently visited files,
> 	not the alphabetically last files.  Dropping alphabetically last files
> 	had meant save-place stopped working across sessions after
> 	.emacs-places filled with alphabetically early names.

--Dmitry