GNU bug report logs - #74361
[PATCH] New option xref-navigation-display-window-action

Previous Next

Package: emacs;

Reported by: Dmitry Gutov <dmitry <at> gutov.dev>

Date: Thu, 14 Nov 2024 22:30:02 UTC

Severity: wishlist

Tags: patch

Fixed in version 31.1

Full log


Message #212 received at 74361 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: martin rudalics <rudalics <at> gmx.at>
Cc: Dmitry Gutov <dmitry <at> gutov.dev>, 74361 <at> debbugs.gnu.org
Subject: Re: bug#74361: [PATCH] New option
 xref-navigation-display-window-action
Date: Thu, 05 Dec 2024 19:52:08 +0200
>> 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)))
>
> Where and how is or would this be used?  In the sources all I see is
>
> 		          `((previous-window . ,debugger-previous-window))))))
>
> so I suppose the symbol value would be used in customizations only.

I just tried to understand the differences between
display-buffer-in-previous-window and display-buffer-use-some-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.
>
> Where and how would this be used?

Mostly in customizations to support both ways:

    `((previous-window . display-buffer-previous-window))
    `((previous-window . ,display-buffer-previous-window))

    `((some-window . display-buffer-some-window))
    `((some-window . ,display-buffer-some-window))

>> 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)
>
> So here 'display-buffer' would retrieve the symbol-value of whatever is
> in the buffer-local value of 'display-buffer-previous-window'.  Right?

Right.

>>                   (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)))))
>
> This relies on 'ofun' selecting a window and would not work for plain
> 'display-buffer'.  Right?

It should work for plain 'display-buffer' because of using 'with-current-buffer'.

>>    (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))
>
> And this assumes that the current buffer is the one where to set the
> variable.  Would this work with a function calling 'xref-goto-xref',
> bound to a key and called interactively with an arbitrary window
> selected?

This is how it's designed to work: to associate the displayed window
with the buffer that was current.




This bug report was last modified 170 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.