Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using two frames in emacs, how do I prevent the compilation buffer from showing up in both?

I work with two monitors, and often use emacs with two frames open; one for each monitor. each frame is split into two side-by-side windows, like so:

 a | b   <-- frame 1 in monitor 1 -------  c | d   <-- frame 2 in monitor 2 

When I hit my 'compile' button while in window a, the compilation buffer opens in the buffer next to it. So far so good:

 a | compilation -----------------  c |     d 

However, if I then move to window c to edit some stuff, then hit compile again, window d visits the compilation buffer as well:

 a | compilation ------------------  c | compilation 

So now I have half of my screen real-estate taken up by two copies of the same compilation buffer, wondering why I have two monitors :)

I can prevent this by conscientiously only hitting the compile key when my cursor is in the buffer next to the currently open compile buffer, but I hit 'compile' so early and often that I usually don't have the presence of mind to do so. I feel like there must be something I can tweak in .emacs so I shouldn't have to.

Any suggestions? Ideally, when I hit 'compile', the currently open compilation buffer should move from its previous window to the one next to the currently used window. If that's too complicated, I'd easily settle for having emacs not visit the compilation buffer in the neighboring window, if it's already open in another window.

like image 901
SuperElectric Avatar asked Jul 22 '10 17:07

SuperElectric


People also ask

How do I close a buffer window in Emacs?

And a buffer can be closed by :q . Likewise in emacs, window can be split horizontally by C-x 2 , and vertically by C-x 3 . And close all other window by C-x 1 .

Can you have more than one buffer open in Emacs?

Working with Multiple Buffers. If you want to create a buffer that contains a file, simply type C-x C-f to find the file. Emacs automatically creates a second buffer and moves you there. If you already have a copy of the file in a buffer, C-x C-f just moves you to the existing buffer.

Can 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. But the windows showing the same buffer can show different parts of it, because each window has its own value of point.

What is a buffer in Emacs?

Buffers in Emacs editing are objects that have distinct names and hold text that can be edited. Buffers appear to Lisp programs as a special data type. You can think of the contents of a buffer as a string that you can extend; insertions and deletions may occur in any part of the buffer.


1 Answers

(setq-default display-buffer-reuse-frames t) 

From the documentation:

Non-nil means `display-buffer' should reuse frames. If the buffer in question is already displayed in a frame, raise that frame.

like image 160
rgiar Avatar answered Sep 28 '22 10:09

rgiar