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

From: martin rudalics <[email-masked]>
Date: Thu, 12 Dec 2024 10:23:59 +0100

>> 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?

It would have been the buffer-local value in the last target buffer
displayed.  But it's inconvenient and obviously fails if that target
buffer has been deleted in the meantime.  So it's not a good solution
either.  It's only advantage would have been that such a local variable
could have been shared between applications - grep and xref say - to
make sure one and the same buffer would always go to the same window.

 > 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.

 >> 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'.

No objections; just that the semantics of "previous-window" was so far a
"window that was showing that buffer" while here we would mean a "window
that was showing a buffer from the same caller".

 > 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))

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.

martin