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

From: Dmitry Gutov <[email-masked]>
Date: Thu, 28 Nov 2024 22:27:32 +0200

On 28/11/2024 20:32, Juri Linkov wrote:
>>> We want to select the new window in relation the "original" window
>>> (with a file-visiting buffer), while avoiding touching the "results
>>> list" window as well. E.g. when the original command was
>>> xref-find-definitions-other-window.
>> Let's see what Juri thinks of an
>>
>> (unsuitable . window-or-list-of-windows)
>>
>> alist entry.
> This can be achieved by an appropriate function in (some-window . (lambda ...))

What would than lambda do, though?

Currently xref--display-buffer-in-other-window is user to display the 
buffer in some "other" window compared to the original window, excluding 
the current one.

Would the proposed lambda call window-list, iterate through it, filter 
out the entries (dedicated and such), and check for equality with two 
given windows? The result might be longer than the current implementation.

The replacement for xref--display-buffer-in-window seems easier to do, 
IIUC this keeps all the current behavior (but it's also Emacs 31+ only):

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index e6f029f3fa8..c38b3e9f5f7 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -690,9 +690,9 @@ xref--show-pos-in-buf
                    (window-live-p xref--original-window)
                    (or (not (window-dedicated-p xref--original-window))
                        (eq (window-buffer xref--original-window) buf)))
-                 `((xref--display-buffer-in-window)
+                 `((display-buffer-use-some-window)
                     (category . xref-jump)
-                   (window . ,xref--original-window)))
+                   (some-window . ,(cl-constantly xref--original-window))))
                  (t
                   '(nil (category . xref-jump))))))
      (with-selected-window (display-buffer buf action)
@@ -707,12 +707,6 @@ xref--display-buffer-in-other-window
       (with-selected-window window
         (display-buffer buffer t)))))

-(defun xref--display-buffer-in-window (buffer alist)
-  (let ((window (assoc-default 'window alist)))
-    (cl-assert window)
-    (with-selected-window window
-      (display-buffer buffer '(display-buffer-same-window)))))
-
  (defun xref--show-location (location &optional select)
    "Help `xref-show-xref' and `xref-goto-xref' do their job.
  Go to LOCATION and if SELECT is non-nil select its window.