Nordlöw
Nordlöw

Reputation: 12138

Display Buffer in Other Window in Recent Emacs

How do I programmatically display a buffer in a window other than the current, similar to the behaviour of Emacs' grep next-error. I want this to work in the most recent Emacs 24.1. Note that this logic recently was modified in Emacs trunk and merged into a single function display-buffer with quite complicated calling semantics. I find it hard to figure out how use display-buffer even after having read the help on it several times. Why isn't there a wrapper function for this such as display-buffer-other-window?

Upvotes: 6

Views: 895

Answers (3)

Stefan
Stefan

Reputation: 28531

And the wrapper exists, BTW, it's called switch-to-buffer-other-window.

Upvotes: 3

phils
phils

Reputation: 73246

The lengthy docstring to display-buffer includes the following:

The ACTION argument to `display-buffer' can also have a non-nil and non-list value. This means to display the buffer in a window other than the selected one, even if it is already displayed in the selected window. If called interactively with a prefix argument, ACTION is t.

Therefore to display a specified buffer in a window other than the current, you can use:

(display-buffer BUFFER-OR-NAME t)

Upvotes: 6

Nordlöw
Nordlöw

Reputation: 12138

The Emacs sources gave me the answer

(pop-to-buffer BUFFER 'other-window)

Upvotes: 3

Related Questions