Subject: bug#35860: Delayed window positioning after buffer display

From: Juri Linkov <[email-masked]>
Date: Wed, 19 Jun 2019 00:02:42 +0300

>> +(defvar delayed-window-point nil
>
> Name space conventions would recommend 'window-delayed-point'.

Then 'window-delayed-start' would be too ambiguous.  Maybe then
'window-start-delayed' and 'window-point-delayed'.

>> +  "Marker to override default `window-point' in all windows.
>
> Why "marker" and why "all windows"?  As for the former, I think it
> makes sense because then one can specify an insertion type as well.
> But IIRC you earlier wanted to allow plain integers here too?

Yes, plain integers should be allowed as well.

>> +`delayed-window-point' is a buffer-local marker you can move to a valid
>> +position of the buffer shown in the window in order to override the standard
>> +positioning mechanism (`point-min') chosen by window displaying functions.")
>
> IIUC there is no such "mechanism" except for buffers just created.
> And what about 'switch-to-buffer-preserve-window-point'?  "window ???
> displaying functions" implicitly hints at the fact that the mechanism
> works only when the buffer is shown by 'display-buffer'.  But are we
> sure that this restriction always applies?

Maybe the same should be allowed for 'switch-to-buffer' as well,
and even for buffers displayed by set-window-configuration.

>> I see no reason to use macros here.
>> We need to replace these macros with the elegant solution that we already
>> have of using action alists.
>
> Macros are useful in as much as they allow to specify the evaluation
> order of their arguments.  Action alists are dumb in this regard.

The problem is that currently the whole cycle of buffer displaying
doesn't allow executing arbitrary code at different stages:
there are no pre-display-buffer and post-display-buffer hooks.

Adding such hooks would allow to get rid of macros easily.
For example, instead of using two variables 'window-point-delayed'
and 'window-start-delayed', a pre-display hook in 'view-lossage'
will be able just to set a buffer-local run-once post-display hook
that will adjust the window positions after the buffer is displayed
in the window.

Another candidate that can be placed into such post-display hook is
fit-window-to-buffer for cases when adding an action alist
as an arg of display-buffer call is not possible.

And vice versa, pre/post-display actions could be specified
in an action alist of display-buffer, when using hooks is not possible.