Subject: Re: bug#74361: [PATCH] New option xref-navigation-display-window-action

From: Juri Linkov <[email-masked]>
Date: Sun, 24 Nov 2024 19:40:19 +0200

>> This is a nice feature.  But please use a different name
>> since the 'category' alist entry is reserved exclusively
>> to match display-buffer calls in user's configuration
>> in the user option 'display-buffer-alist'.
>> When using the same name for different purposes
>> then the users won't be able to match by category
>> and not to reuse the same window.
>
> This is over my head: How can a (category . foo) entry make sense if it
> is not initially set up by the 'foo' package?  As a user I might not
> have the slightest idea of categories.  I'd proceed as follows:
>
> - Package 'foo' designates a 'display-buffer' call as something
>   pertaining to 'foo-some' by adding a (category . foo-some) alist entry
>   and facultatively providing one or a couple of suitable action
>   functions.
>
> - A knowledgeable user can override the suggestion of 'foo' by putting
>   into 'display-buffer-alist' a (category . foo-some) condition (so
>   'buffer-match-p' will handle it) with an appropriate ACTION.
>
> - 'display-buffer' has to
>
>   - respect the user customization if there is one (and it's not
>     overridden by the caller),
>
>   - tries any action function provided by the caller,
>
>   - automagically tries to do something reasonable by finding a window
>     that already has an association with 'foo-some'.
>
> Am I wrong about this concept?

The key word is "automagically".  Only this is a problem.
Many users might not want such magic.

Compare this with 'display-buffer-reuse-mode-window'.
Its alist entry `mode' is not the same as `major-mode' in condition:

  (add-to-list 'display-buffer-alist
               '((major-mode . Info-mode)
                 (display-buffer-reuse-mode-window)
                 (mode . help-mode)))

But the category should be the same to match:

  (add-to-list 'display-buffer-alist
               '((category . Info-mode)
                 (display-buffer-same-window)))

  (display-buffer (get-buffer-create "*info*")
                  '(nil (category . Info-mode)))

So for a similar function like 'display-buffer-reuse-category-window'
we need another alist element, not 'category'.
Maybe 'display-buffer-reuse-group-window' with 'group' list element
for a group of buffers in the same window.