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

From: Juri Linkov <[email-masked]>
Date: Thu, 12 Dec 2024 18:40:16 +0200

>> grep/xref should remember that window in a buffer-local variable?
>
> As I'd envision it, xref would use a conceptually global variable called
> 'xref-target-window' or 'xref-last-window-used' and grep would do
> something similar.

Please not a global variable.  I often use many pairs of
source/target windows at the same time for different grep/xref results.

>>    (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))
>
> Wouldn't that be overkill?  The user's customization would have no
> effect IIUC.  I'd say
>
>     (display-buffer buffer `((nil (category . grep) (some-window . ,window))))
>
> would be grep's proposal and a user's
>
>     ((category . grep)
>      (display-buffer-in-previous-window))
>
> would try to find a window that previously displayed the buffer first.

Still too limited solution when the users can't store the last window
for other commands.  Better would be to add a new alist entry that
will force 'display-buffer' to remember the last window from any call:

  (display-buffer buffer `((nil (category . compilation)
                                (remember-last-window . t))))

or by user customization of display-buffer-alist:

  ((category . compilation)
   (nil (remember-last-window . t)))

And a function that stores/restores the last window could be customizable as well.
So the users could decide whether to save it in a buffer-local variable,
or in the window parameter.  This option could be like 'xref-history-storage'
that provides the choice of 'xref-global-history' or 'xref-window-local-history':

  ((category . compilation)
   (nil (remember-last-window . global)))

or

  ((category . compilation)
   (nil (remember-last-window . window-local)))

or

  ((category . compilation)
   (nil (remember-last-window . buffer-local)))