benhsu
benhsu

Reputation: 5526

How can I tell emacs to not split the window on M-x compile or elisp compilation error?

When I perform M-x compile or get an elisp compilation error, my emacs splits the window vertically, and displays the compile output/error message in the new window. I prefer to work with my buffers in a full screen window, because the vertically split window is too narrow for me. Can I tell emacs to not split the window and do a M-x switch-buffer to the compilation/error buffer?

Edit: Trey's suggestion works for compilation. Is there a way to set it for all the commands which split the window? The three I have in mind are elisp compiling, M-x apropos and M-x occur.

Upvotes: 6

Views: 1771

Answers (3)

jpkotta
jpkotta

Reputation: 9417

This is what I use for compilation windows. If there are no errors or warnings, it will display the compilation output buffer for a second and then kill it. Otherwise the buffer stays because you probably want find the errors and fix them. I got this from a newsgroup.

(defun kill-compile-buffer-if-successful (buffer string) 
  " kill a compilation buffer if succeeded without warnings " 
  (if (and 
       (string-match "compilation" (buffer-name buffer)) 
       (string-match "finished" string) 
       (not 
        (with-current-buffer buffer 
          (search-forward "warning" nil t)))) 
      (run-with-timer 1 nil 
                      'kill-buffer 
                      buffer)))
(add-hook 'compilation-finish-functions 'kill-compile-buffer-if-successful)

Upvotes: 0

jtahlborn
jtahlborn

Reputation: 53694

my guess is that you want to customize the split-window-preferred-function variable. the default value is split-window-sensibly. you should change it to a custom version which just switches the current buffer.

this seems to work:

(defun no-split-window ()
  (interactive)
  nil)

(setq split-window-preferred-function 'no-split-window)

Upvotes: 4

Trey Jackson
Trey Jackson

Reputation: 74430

Try this:

(setq compilation-window-height 1000)

You could get fancy and actually calculate the number of lines of text in the frame... (/ (frame-pixel-height) (frame-char-height)), but that seems silly.

Io control how Emacs generally displays buffers, you can configure the variable same-window-regexps to match all buffer names, and then all commands that display buffers using display-buffer will use the same window:

(setq same-window-regexps '("."))

See Choosing a Window for more details.

Upvotes: 5

Related Questions