I'd like to write an emacs lisp function that will write output to a window other than the current window. It should create a new window if only the current one exists, and it should use an existing one otherwise. This is similar to what happens when you run C-h-f (Describe Function), and the description pops up in another window. What is the best way to do this?
See display-buffer
:
display-buffer is an interactive compiled Lisp function in `window.el'.
It is bound to C-x 4 C-o.
(display-buffer buffer-or-name &optional not-this-window frame)
Make buffer buffer-or-name appear in some window but don't select it. buffer-or-name must be a buffer or the name of an existing buffer. Return the window chosen to display buffer-or-name or nil if no such window is found.
Optional argument not-this-window non-nil means display the buffer in a window other than the selected one, even if it is already displayed in the selected window.
Optional argument frame specifies which frames to investigate when the specified buffer is already displayed. If the buffer is already displayed in some window on one of these frames simply return that window. Possible values of frame are:
`visible' - consider windows on all visible frames.
0 - consider windows on all visible or iconified frames.
t - consider windows on all frames.
A specific frame - consider windows on that frame only.
nil - consider windows on the selected frame (actually the last non-minibuffer frame) only. If, however, either
display-buffer-reuse-frames' or
pop-up-frames' is non-nil (non-nil and not graphic-only on a text-only terminal), consider all visible or iconified frames.
Or you can use pop-to-buffer
if you want that buffer to be selected (which it sounds like you don't), or with-output-to-temp-buffer
which binds the standard-output
to be sent to the temporary buffer - read the documentation for more details (hat tip to Michael for that).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With