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

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

bug#70949: display-buffer-choose-some-window


From: Juri Linkov
Subject: bug#70949: display-buffer-choose-some-window
Date: Fri, 24 May 2024 20:38:34 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu)

>> This makes the behavior more predictable: the user will know that all
>> buffers will be displayed in the most recently used window, so the user
>> can switch to that window before continuing to navigate buffers.
>
> Not really.  The window switched to becomes the selected window and the
> 'mru' window used will be the window where the user was working before
> the switch due to NOT-SELECTED being t.

I meant switching to the window to instruct display-buffer what window
to use as mru, then switch back to the rgrep window.

>>> Then maybe a separate category for rgrep buffers could help here.
>>
>> This is not about rgrep buffers.
>
> Consider the completely untested action function below supposed to be
> called with a (related-window . rgrep) alist argument.

We already have 'previous-window' that I'm using for a long time,
and it works nicely with such configuration:

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

(defun display-buffer-from-grep-p (_buffer-name _action)
  (with-current-buffer (window-buffer)
    (and (memq this-command '(compile-goto-error))
         (derived-mode-p '(compilation-mode)))))

(add-to-list 'display-buffer-alist
             '(display-buffer-from-grep-p
               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 compile-goto-error (: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)))))

But this is very complicated configuration.  So I wanted to help people
to do basically the same with much simpler setting that overrides
the hard-coded 'lru' with just '(some-window . mru)'.

The only problem with '(some-window . mru)' is that its NOT-SELECTED is t,
so this excludes the very useful case of displaying the buffer
in the same selected window.  For example, with 'previous-window'
I often visit rgrep results in the same window where the rgrep buffer
was displayed.  This keeps everything confined to one window.

I see that in your display-buffer-in-related-window
'related-window' is a window parameter.  I think this is
much better than a buffer-local variable that I used above.
But a new alist 'related-window' should also update
the 'related-window' window parameter in 'post-command-hook'
like 'post-command-select-window' does.

Then the customization for users would be very simple:

(add-to-list 'display-buffer-alist
             '((category . rgrep) (display-buffer-in-related-window)))

Or maybe a better name would be 'display-buffer-in-last-window'?

In any case this looks like a workable solution
that will create a connection between windows.





reply via email to

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