7

I would prefer to have the *compilation* buffer always stay in its own frame. However, currently if I run M-x compile from another frame/window, the buffer pops up in a new window there as well. How can I cause emacs to instead only raise the existing frame which is displaying the *compilation* buffer?

  • I believe this is the answer to your question, which I wrote up 3 years ago at the beginning of my Emacs quest: stackoverflow.com/a/19415289/2112489 The applicable sections of code in compile.el may have changed, and I have since made many changes/improvements to my custom functions that target certain frames for buffer display: stackoverflow.com/questions/18346785/… Take a look and see if the first link is approximately what you are seeking -- who knows, it may even still work without making changes. – lawlist Apr 2 '16 at 21:32
5

Normally, Emacs considers the selected frame the only reusable frame. In other words, normally Emacs only searches the current ("selected") frame for windows that already contain the buffer-to-display ("reusable windows"). What you need is for Emacs to consider the compilation buffer's frame as a reusable frame:

(push '("\\*compilation\\*" . (nil (reusable-frames . t))) display-buffer-alist)

The above snippet will make all the frames reusable when display-buffer displays the *compilation* buffer. Look at the documentation of display-buffer-reuse-window to learn what other values reusable-frames can receive.

However, this doesn't take care of the other direction - opening a code buffer from the compilation window. For example, if you open a buffer by pressing a link in the compilation buffer, Emacs will open the buffer in the same frame as the compilation window. Changing that is another matter. I don't know how the behavior compares with the special-display-buffer-names solution.

2

Make buffer compilation always have a dedicated window. One way to do this is to customize option special-display-buffer-names, to include "*compilation*". Another is to customize option special-display-regexps, to include a regexp that matches that buffer name. (I include the regexp "[ ]?[*][^*]+[*]", which matches all buffers whose names are *...*.)

(See also option special-display-frame-alist, which you can use to specify the behavior and characteristics of the frame used for such special-display buffers.)

Emacs will tell you that these "special-display buffer" options are "obsolete", but thank goodness they are still supported. They offer a simple way to do what you want.

If you want to suffer through what Emacs prefers you do now, then customize option display-buffer-alist instead. The idea is essentially the same (it's just an uglier and more complicated user option).

  • Care to explain the downvotes? Is there something incorrect in this answer? – Drew Apr 3 '16 at 15:59
  • 1
    It's probably for the obsolete options and the snark ("suffer"). – lunaryorn May 4 '16 at 5:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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