Subject: Re: bug#74246: [PATCH] Reuse display windows in image-dired

From: Juri Linkov <[email-masked]>
Date: Thu, 12 Dec 2024 09:52:13 +0200

>> I still don't understand how a local variable in one target buffer could
>> help to display another buffer in the same window from grep/xref list.
>
> By having grep do the following:
>
> - Issue a first request to display a buffer from that list,
>
> - remember the window used,
>
> - set the local variable in the target buffer to the remembered value
>   before calling 'display-buffer' again.

What if the user switches buffers in that window, but still wants
to continue visiting next buffers from grep in the same window?

>>>>> pass the symbol of the function calling 'display-buffer' with some
>>>>> unique number identifying the nth call of 'display-buffer' within that
>>>>> function.  Everything else is guesswork.
>>>>
>>>> There is already such a symbol: 'category'.
>
> 'category' is much broader.
>
>>> But this one is already handled by 'buffer-match-p'.  We can't set it
>>> willy-nilly to some arbitrary value.  Otherwise, that function might
>>> match it in an unexpected way.
>>
>> 'display-buffer-reuse-category-window' could reuse the 'category' symbol.
>> Or '(some-window . reuse-category)'.
>
> Let me turn the table and ask you: Both grep/xref know very well which
> window was used for displaying the last match.  What speaks again to
> have them just remember that window after each call

grep/xref should remember that window in a buffer-local variable?

> and propose it via a (some-window . ,window) alist entry in the next
> call together with 'display-buffer-use-some-window'?

Such providing that window in the display-buffer call would be very nice
to do, e.g. with a more descriptive name like (previous-window . ,window).
This will make easier for users to customize by using different actions
that handle such alist entry: 'display-buffer-in-previous-window' or
'display-buffer-use-some-window'.

Then a category will be continued to be used only for matching,
e.g. the call

  (display-buffer buffer `((nil (category . grep) (previous-window . ,window))))

could be customized to match a category and to use the previous window:

  ((category . grep)
   (display-buffer-in-previous-window))

> I think the main advantage of such an
> approach is that grep/xref would be in complete control of a good
> proposal for such a window, something most users could hardly resist.

Agreed.