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

From: Juri Linkov <[email-masked]>
Date: Tue, 10 Dec 2024 19:30:28 +0200

>> What would be the safest approach to detect the same 'display-buffer' call?
>> A category?
>
> As I already mentioned: The calling function would have to reserve a
> separate alist entry for it.  In my initial proposal I had even a
> separate argument for that purpose.  Alternatively, one could reserve a
> local variable in the target buffer for that purpose ('display-buffer'
> would have to reset it).

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.

>>> Unless a user has customized it or 'display-buffer-below-selected' fails
>>> for some reason.
>>
>> Then displaying it by some-window in the same window instead of lru
>> looks as a nice thing to do.
>
> Would you like that?  I think displaying *backtrace* in the same window
> is always a bad idea.

Only when 'display-buffer-below-selected' fails that is extremely rare.

>>> As I said above this is not reliable.  The only reliable thing is to
>>> 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'.
>
> 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)'.

>>> If a user issues the command to display an image in a window that
>>> already shows an image and insists on using another window, an arbitrary
>>> other window can be chosen.  Users who want that just get the usual
>>> chaotic behavior lru provides.  They asked for it.
>>
>> The users might want to switch displaying to another window,
>> and continue displaying other images in the same other window.
>
> Yes.  But then either of the windows could be chosen by the next call
> (if that window still exists).

Not either, but preferably the last used window.

>>> With 'image-dired' it can be set in the image buffer because that buffer
>>> is always the same.
>>
>> This is an exception, not a general rule such as for navigating
>> grep/xref results.  I see no reason for image-dired be different
>> from grep/xref.
>
> 'image-dired' _is_ different because it always uses the same buffer for
> showing images stored in different files.  I know of no other function
> doing that.  Do you?

I don't remember any other function doing such non-standard things.