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

From: Juri Linkov <[email-masked]>
Date: Wed, 04 Dec 2024 19:14:42 +0200

>> I see no problems with this patch.  Even better would be if Martin agrees
>> to modify 'display-buffer-use-some-window' to accept a window in
>> '(some-window . WINDOW)'.
>
> He obviously agrees (provided WINDOW is a live window).

Ok.  This reminds me adding '(previous-window . WINDOW)'
to 'display-buffer-in-previous-window' with:

    (when (and previous-window (symbolp previous-window)
               (boundp previous-window))
      (setq previous-window (symbol-value previous-window)))
    (when (and (setq window previous-window)
	       (window-live-p window)

Probably we should support both a symbol and a value for 'some-window'
as well.

BTW, here is an example of using 'previous-window' with an advice on
'window--display-buffer' that could be combined with 'some-window':

  (defvar-local display-buffer-previous-window nil)

  (add-to-list 'display-buffer-alist
               '((category . xref-jump)
                 display-buffer-in-previous-window
                 (previous-window . display-buffer-previous-window)
                 (inhibit-same-window . nil))
               ;; Append to not override display-buffer-same-window
               'append)

  (define-advice xref-goto-xref (:around (ofun &rest args) previous-window)
    (let ((buffer (current-buffer)))
      (apply ofun args)
      (with-current-buffer buffer
        (setq-local display-buffer-previous-window (selected-window)))))

  (define-advice window--display-buffer (:around (ofun &rest args) previous-window)
    (let ((buffer (current-buffer))
          (window (apply ofun args)))
      (with-current-buffer buffer
        (setq-local display-buffer-previous-window window))
      window))