Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tell Emacs to open new buffer in specific window

If an Emacs frame is split in several windows and a new buffer is opened, is there a possibility to tell Emacs in which window to open the buffer.

Especially, if one window contains a dired buffer and I want to tell Emacs in which of the other opened windows a new file shall be displayed.

If the Emacs frame is for example split like this:

____________________
|        |         |
|        |         |
|   A    |    B    |
|        |         |
|        |         |
--------------------
|        |         |
|   C    |    D    |
|        |         |
--------------------

Where A,B,C and D are the windows. If A contains a dired buffer, can I tell Emacs to open a new file in a new buffer in window D?

like image 369
Hypnotoad Avatar asked Jun 06 '14 10:06

Hypnotoad


People also ask

Can you only have one buffer open in Emacs at a time?

Each Emacs window displays one Emacs buffer at any time. A single buffer may appear in more than one window; if it does, any changes in its text are displayed in all the windows where it appears.

How do I select a buffer in Emacs?

Read a number n and move to line n in the most recently selected buffer other than the current buffer. To select the buffer named bufname , type C-x b bufname <RET> . This runs the command switch-to-buffer with argument bufname . You can use completion on an abbreviation for the buffer name you want (see Completion).

How do you change from one buffer to another?

For conveniently switching between a few buffers, use the commands C-x LEFT and C-x RIGHT . C-x LEFT ( previous-buffer ) selects the previous buffer (following the order of most recent selection in the current frame), while C-x RIGHT ( next-buffer ) moves through buffers in the reverse direction.

How do I open a new frame in Emacs?

To open a new frame, select Make New Frame from the Files menu or press C-x 5 2 (for make-frame). Emacs makes a new frame containing the current buffer and puts it on top of the current frame. These lines set up sizes for the width and height of Emacs frames.


Video Answer


1 Answers

Here's another answer --

You can do what you want using Icicles. In Icicle mode, C-x o, which is normally other-window, is icicle-other-window-or-frame. A prefix arg gives it several alternative behaviors, one of which (for Emacs 24 and later) is to choose a window that will be used by the next buffer-displaying operation (e.g., C-x C-f, C-x b).

That's what happens if you use a double plain prefix arg: C-u C-u C-x o. That invokes command icicle-choose-window-for-buffer-display, which you could of course also bind to any other key.

You choose the target window by name (using completion or cycling etc.).

All that command does is set variable icicle-next-window-for-display-buffer to the window that you choose. Icicles advises commands display-buffer, switch-to-buffer, and switch-to-buffer-other-window so that the next time they are called they use the window that is the value of icicle-next-window-for-display-buffer. (After that invocation they return to their normal behavior.)

This means too that if you have another method of choosing a window, which you prefer (e.g. cycling using one of the other methods mentioned here), then you could modify that method to set icicle-next-window-for-display-buffer to the chosen window, to get the same effect (in Icicle mode). IOW, it does matter how you choose the window; just set the variable value to it and the next buffer-displaying action will use it.

like image 142
Drew Avatar answered Sep 25 '22 06:09

Drew