Subject: Re: bug#33871: 27.0.50; Revert Dired window saved in window configuration

From: Juri Linkov <[email-masked]>
Date: Tue, 22 Feb 2022 19:14:27 +0200

>>> How would 'save-window-excursion' handle the case of a dired buffer that
>>> gets reverted while its FORMS are run?
>>
>> 'dired-goto-file' will restore dired-positions after 'save-window-excursion'.
>
> Who calculated those dired-positions and who calls 'dired-goto-file' to
> restore them?

Like in bug#54038 (about having access to windows in window configurations),
the problem is that there is no way to update and even peek inside
a window configuration.  In bug#54038 the cleanup function can't tell
if a window is still live in a window configuration.

And here 'dired-revert' can't update windows saved in a window configuration.

'dired-save-positions' goes to great lengths to employ get-buffer-window-list,
and walk-windows with window-prev-buffers to update the Dired buffer
even in window-prev-buffers.  And 'dired-restore-positions' with the
same number of lines tries to restore all prev-buffers.

But still 'dired-revert' fails to update the Dired buffer in
window configurations saved in tabs, or in winner.el, or
in 'C-x r w' (window-configuration-to-register), etc.

A possible solution would be to add two hooks:

1. hook before finishing 'current-window-configuration' that will add all
windows to some variable that the cleanup function could check in bug#54038.
This is like 'dired-save-positions'.

2. hook after calling 'set-window-configuration' that will restore
previous positions.  This is like 'dired-restore-positions' that
uses 'dired-goto-file'.