all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Open compilation window only on errors?
@ 2003-09-27 18:57 Matthew Calhoun
  0 siblings, 0 replies; 6+ messages in thread
From: Matthew Calhoun @ 2003-09-27 18:57 UTC (permalink / raw)


Hello,

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?

Thanks,
Matt

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Open compilation window only on errors?
       [not found] <mailman.813.1064689050.21628.help-gnu-emacs@gnu.org>
@ 2003-09-29  9:45 ` Jens Schmidt
  2003-10-13  8:05   ` Matthew Calhoun
  2003-09-29 14:45 ` François Fleuret
  2003-09-29 22:10 ` Kevin Rodgers
  2 siblings, 1 reply; 6+ messages in thread
From: Jens Schmidt @ 2003-09-29  9:45 UTC (permalink / raw)


Matthew Calhoun <calhounm@mac.com> writes:

> 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?

The following does not exactly do what you want to do since the
window on M-x compile gets opened anyway.  But you may do a C-x 1
to get rid of it and it will pop up again at end of compilation
if and only if compilation was unsuccessful.

I like the solution since you may both
- catch errors quickly that show up immediately and
- forget about long-running compilations regardless whether they
  finish up successfully or not.

(defun check-compilation-result (buffer msg)
  "Signal end of compilation.
Pops up a buffer with compilation results if necessary."
  (ding)
  (if (or (< (length msg) 8)
	  (not (equal (substring msg 0 8) "finished")))
      (display-buffer buffer))
  (message (concat "Compilation " (substring msg 0 -1))))

(setq compilation-finish-function 'check-compilation-result)

Jens

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Open compilation window only on errors?
       [not found] <mailman.813.1064689050.21628.help-gnu-emacs@gnu.org>
  2003-09-29  9:45 ` Jens Schmidt
@ 2003-09-29 14:45 ` François Fleuret
  2003-09-29 22:10 ` Kevin Rodgers
  2 siblings, 0 replies; 6+ messages in thread
From: François Fleuret @ 2003-09-29 14:45 UTC (permalink / raw)



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 `window-configuration-before-compilation'
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)
        (progn
          (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 (current-window-configuration))
    (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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Open compilation window only on errors?
       [not found] <mailman.813.1064689050.21628.help-gnu-emacs@gnu.org>
  2003-09-29  9:45 ` Jens Schmidt
  2003-09-29 14:45 ` François Fleuret
@ 2003-09-29 22:10 ` Kevin Rodgers
  2 siblings, 0 replies; 6+ messages in thread
From: Kevin Rodgers @ 2003-09-29 22:10 UTC (permalink / raw)


Matthew Calhoun wrote:

> When I compile using M-x compile, Emacs opens a new window for the 
> compilation buffer when it's finished.


Really?  I think it displays the *compilation* buffer immediately.  You can see
that with `M-x compile RET C-a C-k sleep 10 RET'.

> 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?

Well, you could undisplay the window when the compilation finishes by calling
delete-window or bury-buffer inside your own compilation-finish-function.  You
can access the EXIT-STATUS arg of compilation-handle-exit (which should be 0 for
a successful command), since Emacs variables have dynamic scope.

Or maybe you could do that inside
	(defadvice compile (after delete-window activate) ...)
and then (re)display the buffer within your compilation-finish-function.

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Open compilation window only on errors?
  2003-09-29  9:45 ` Jens Schmidt
@ 2003-10-13  8:05   ` Matthew Calhoun
  0 siblings, 0 replies; 6+ messages in thread
From: Matthew Calhoun @ 2003-10-13  8:05 UTC (permalink / raw)


Thanks to the superb guidance of Jens, Francois, and Kevin, I have a 
compilation-finish-function that works quite well. It looks like this:

(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?

Thanks,
Matt

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Open compilation window only on errors?
       [not found] <mailman.1571.1066032399.21628.help-gnu-emacs@gnu.org>
@ 2003-10-13 17:24 ` Kevin Rodgers
  0 siblings, 0 replies; 6+ messages in thread
From: Kevin Rodgers @ 2003-10-13 17:24 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-10-13 17:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1571.1066032399.21628.help-gnu-emacs@gnu.org>
2003-10-13 17:24 ` Open compilation window only on errors? Kevin Rodgers
     [not found] <mailman.813.1064689050.21628.help-gnu-emacs@gnu.org>
2003-09-29  9:45 ` Jens Schmidt
2003-10-13  8:05   ` Matthew Calhoun
2003-09-29 14:45 ` François Fleuret
2003-09-29 22:10 ` Kevin Rodgers
2003-09-27 18:57 Matthew Calhoun

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.