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

From: Juri Linkov <[email-masked]>
Date: Thu, 13 Dec 2018 01:29:30 +0200

>> I think we should run a hook when a buffer appears in the window,
>> either by e.g. 'C-x <left>' (previous-buffer) or by 'window-state-put',
>> then a buffer-local hook in Dired will move its point to the right file.
>
> The problem with 'dired' is that we have to make any amendments at the
> time the buffer is reverted.  It's already too late when switching to
> the buffer afterwards.
>
> The only thing we can do at the time of switching to a buffer is to go
> to the buffer's point (which should work when the buffer was displayed
> only in one window before).

For example, saveplace.el uses dired-initial-position-hook to set
Dired buffer's point initially to a remembered dired-filename.

A switch-to-buffer hook could do the same to move point to a dired-filename
previously displayed in that window, by getting the filename from e.g.
a buffer-local mapping from windows to filenames.