Subject: bug#33458: 27.0.50; dired loses position when reverted from outside place

From: Juri Linkov <[email-masked]>
Date: Sun, 02 Dec 2018 00:30:06 +0200

>>> The buffer's point is OK.  So we could introduce a variable, say
>>> 'set-window-point-from-point', and set this to t when reverting a
>>> buffer reveals that 'get-buffer-window' is nil.  Redisplaying the
>>> buffer would then always go to the buffer's point instead of some
>>> position stored in the window's list of previous buffers.
>>>
>>> I'm not sure when to reset this mechanism though.  The first time we
>>> display the buffer again?  Then switching to that buffer in another
>>> window later would suffer from the initial problem.  Keep it for every
>>> other window until it has seen the buffer again?  How would we do
>>> that?
>>
>> Maybe until point is moved to another position either by the user or
>> by any other code that doesn't set 'set-window-point-from-point' again.
>
> I'm not sure how to avoid defeating the idea behind 'window-point' -
> showing the same buffer at different positions simultaneously.

Code that sets 'window-point-from-point' could decide how
'window-point-from-point' should be used, e.g. if it sets
a value 'all-windows' it affects all windows, if 'once'
then reset after first use, etc.

>>> Finally note that this does not fix the dired problem.  There we want
>>> the cursor go to the line showing the file where point previously was
>>> in that window.
>>
>> Maybe for dired store meta-information such as dired-filename
>> in window parameters.  Then when a dired buffer is restored in a window,
>> and dired-revert moved point-marker to the beginning of the dired buffer,
>> move point to the file from the window parameter.
>
> Interesting idea.  The parameter could also include the name of the
> file at 'window-start' and try to restore that position as well.
> Still we'd have to access each window's list of previous and next
> buffers and store the parameter only if the buffer appears in any of
> these lists (not to talk about window configurations stored somewhere
> else).  And we would have to remove the parameter whenever the buffer
> gets killed.

Then better idea: add a buffer-local variable with an alist
mapping windows to dired-filenames or any other metadata:

'((#<window 1> . (dired-filename . "file1"))
  (#<window 2> . (dired-filename . "file2")))