help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Open compilation window only on errors?


From: Kevin Rodgers
Subject: Re: Open compilation window only on errors?
Date: Mon, 13 Oct 2003 11:24:03 -0600
User-agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2

Matthew Calhoun wrote:

(defun handle-compilation-window (buffer msg)
"Gets rid of compilation window on successful compilation, otherwise goes to first error."
  (if (and (equal (substring msg 0 8) "finished")
           (get-buffer-window buffer)) ; Compilation window is still open
      (progn (delete-window (get-buffer-window buffer))
             (message "Compilation was clean."))
    (next-error)))
(setq compilation-finish-function 'handle-compilation-window)

It even works correctly with my unit test failures, which was a pleasant surprise. But it's not perfect yet. When compilation results in warnings but no errors, my function is closing the compilation window because it receives a "finished" message, but I would rather keep the window open and go to the first warning, just like I would if there were errors. I know I could tell the compiler to treat warnings as errors, but that's not always feasible. Should I add a regexp to compilation-error-regexp-alist to fix this, or is there a better way?

First, I think it would be more reliable to check the compiler's exit
status directly rather than Emacs' message:


 ;; process-status == (process-status (get-buffer-process buffer))
 ;; exit-status == (process-exit-status (get-buffer-process buffer))
 (if (and (eq process-status 'exit)
           (= exit-status 0)
           (get-buffer-window buffer))
     ...)

Thtat's because Emacs doesn't parse the error or warning messages to
determine whether the compiler failed, it just looks at its exit status
so you may as well do the same.

My guess is that compilation-error-regexp-alist already matches your
compiler's warnings; you can test that by running next-error when you
only get warning messages.  If that works, you could set
compile-auto-highlight to automatically parse the compiler's output and
then check compilation-error-list in your finish function to see whether
any warnings or errors were reported.


--
Kevin Rodgers



reply via email to

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