1

I like to have the Help buffer in a some frame (with some other windows) and I try to reuse this window in this frame even when I am in another frame and issue a help command.

I tried setting

(setq display-buffer-alist
      '(("\\*Help\\*" display-buffer-reuse-window)))

but this seem to reuse the window only when it is in the same frame.

How can I tell the display-buffer system to reuse a window in any (visisble) frame?

2 Answers 2

1

reuse a window in another frame

The key to achieving this lies in using an action alist entry reusable-frames. For instance, setting its value to 0 with (reusable-frames . 0) enables searching for a reusable window on all visible or iconified frames.

The corresponding part of a configuration could then look as shown below (setopt is available since Emacs 29.1).

(setopt
 'display-buffer-alist
 '(("\\*Help\\*"
    (display-buffer-reuse-window
     display-buffer-in-previous-window
     display-buffer-use-some-frame
     display-buffer-pop-up-frame)
    (reusable-frames . visible))))

For more insight on how to manage Emacs windows, see Demystifying Emacs’s Window Manager.

And documentation, of course. In particular, I find the following pages to be the most helpful:

0

This is covered in the documentation for the function you're using.

Refer to all of the details regarding frames:

display-buffer-reuse-window is a byte-compiled Lisp function in
`window.el'.

(display-buffer-reuse-window BUFFER ALIST)

Return a window that is already displaying BUFFER.
Preferably use a window on the selected frame if such a window
exists.  Return nil if no usable window is found.

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 eligible for reuse.

If ALIST contains a `reusable-frames' entry, its value determines
which frames to search for a reusable 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 ALIST has a non-nil `inhibit-switch-frame' entry, then in the
event that a window on another frame is chosen, avoid raising
that frame.

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.
2
  • Interesting! I didn't know, that display-buffer-reuse-window is a normal function. But how can I give it as a property in display-buffer-alist the additional parameter so that it finds the window in other frames as well?
    – halloleo
    Apr 13, 2023 at 13:09
  • Follow the documented manual links, and see the adjacent node (elisp)The Zen of Buffer Display for many examples.
    – phils
    Apr 13, 2023 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.