[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Open compilation window only on errors?

From: François Fleuret
Subject: Re: Open compilation window only on errors?
Date: 29 Sep 2003 16:45:15 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

Matthew Calhoun wrote on 27 Sep 2003 19:57:18 MET:

> When I compile using M-x compile, Emacs opens a new window for the
> compilation buffer when it's finished. This is great when there are
> warnings or errors, but when there aren't I would like to prevent
> Emacs from opening the new window, and instead maybe just put a
> message in the minibuffer indicating that compilation was
> successful. Is there a variable I can set for this, or does anyone
> have elisp code that does something similar?

This is my own recipe (sort of dirty, but has been working for months
here), maybe it can help:

;; <f1> runs the compilation according to the compile-command (and
;; thus does not ask any confirmation), shows the compilation buffer
;; during compilation AND removes it if the compilation ends with no
;; error (i.e. it restores the window configuration as it was before
;; <f1> was pressed)

;; <shift-f1> asks for a compilation command and runs the compilation
;; but does not restore the window configuration (i.e. the compilation
;; buffer's window will still be visible, as usual)

;; <f2> goes to the next compilation error (as C-x ` does on the
;; standard configuration)

(defun restore-windows-if-no-error (buffer msg)
  "Restores the window configuration according to 
if msg matches \"^finished\".

This function can be used by adding in your .emacs

\(setq compilation-finish-function \'restore-windows-if-no-error\)."

  (if (string-match "^finished" msg)
      (when (boundp 'window-configuration-before-compilation)
          (set-window-configuration window-configuration-before-compilation)
          (message (concat "Compilation '" compile-command "' finished with no 
error (compilation window removed)"))

  (makunbound 'window-configuration-before-compilation)

(setq compilation-finish-function 'restore-windows-if-no-error)

(defun fast-compile () "Compiles without asking anything" (interactive)
  (let ((compilation-read-command nil))
    (setq window-configuration-before-compilation 
    (compile compile-command)))

(define-key global-map [f1] 'fast-compile)
(define-key global-map [(shift f1)] 'compile)
(define-key global-map [f2] 'next-error)

François Fleuret

IMEDIA Research Group                            Tel +33 1 39 63 55 83
INRIA, France                                    Fax +33 1 39 63 59 95

reply via email to

[Prev in Thread] Current Thread [Next in Thread]