bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Juri Linkov
Subject: bug#74361: [PATCH] New option xref-navigation-display-window-action
Date: Thu, 05 Dec 2024 19:52:08 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu)

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]