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: martin rudalics
Subject: bug#70949: display-buffer-choose-some-window
Date: Fri, 24 May 2024 11:32:16 +0200
User-agent: Mozilla Thunderbird

> And I tried to address exactly the same problem.  I only disagreed with
> using the word "confusing".  I think this is rather about convenience.

Then I won't insist.

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

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

martin

(defun display-buffer-in-related-window (buffer alist)
  "Display BUFFER in a related window.
ALIST is an association list of action symbols and values.  See
Info node `(elisp) Buffer Display Action Alists' for details of
such alists.

If ALIST has a non-nil `inhibit-same-window' entry, the selected
window is not usable.  A dedicated window is usable only if it
already shows BUFFER.  If ALIST contains a `related-window'
entry, the window specified by that entry (either a variable
or a value) is usable even if it never showed BUFFER before.

If ALIST contains a `reusable-frames' entry, its value determines
which frames to search for a usable window:
  nil -- the selected frame (actually the last non-minibuffer frame)
  A frame   -- just that frame
  `visible' -- all visible frames
  0   -- all frames on the current terminal
  t   -- all frames.

If ALIST contains no `reusable-frames' entry, search just the
selected frame if `display-buffer-reuse-frames' and
`pop-up-frames' are both nil; search all frames on the current
terminal if either of those variables is non-nil.

If more than one window is usable according to these rules,
apply the following order of preference:

- Use the window specified by any `related-window' ALIST entry,
  provided it is not the selected window.

- Use a window that showed BUFFER before, provided it is not the
  selected window.

- Use the selected window if it is either specified by a
  `related-window' ALIST entry or showed BUFFER before.

This is an action function for buffer display, see Info
node `(elisp) Buffer Display Action Functions'.  It should be
called only by `display-buffer' or a function directly or
indirectly called by the latter."
  (let* ((alist-entry (assq 'reusable-frames alist))
         (inhibit-same-window
          (cdr (assq 'inhibit-same-window alist)))
         (frames (cond
                  (alist-entry (cdr alist-entry))
                  ((window--pop-up-frames alist)
                   0)
                  (display-buffer-reuse-frames 0)
                  (t (last-nonminibuffer-frame))))
         (first (and (frame-live-p frames) (frame-first-window frames)))
         (related-window (cdr (assq 'related-window alist)))
         best-window second-best-window window)
    ;; Scan windows whether they have a matching 'related-window'
    ;; parameter.
    (catch 'best
      (dolist (window (window-list-1 first 'nomini frames))
        (when (and (eq (window-parameter window 'related-window)
                       related-window)
                   (not (window-dedicated-p window)))
          (if (eq window (selected-window))
              (unless inhibit-same-window
                (setq second-best-window window))
            (setq best-window window)
            (throw 'best t)))))
    ;; When ALIST has a `related-window' entry, that entry may override
    ;; anything we found so far.
    (when (and related-window (symbolp related-window)
               (boundp related-window))
      (setq related-window (symbol-value related-window)))
    (when (and (setq window related-window)
               (window-live-p window)
               (or (eq buffer (window-buffer window))
                   (not (window-dedicated-p window))))
      (if (eq window (selected-window))
          (unless inhibit-same-window
            (setq second-best-window window))
        (setq best-window window)))
    ;; Return best or second best window found.
    (when (setq window (or best-window second-best-window))
      (window--display-buffer buffer window 'reuse alist))))





reply via email to

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