unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* compiling in C mode and the compilation buffer
@ 2004-07-24 22:35 Shug Boabie
  2004-07-25 22:52 ` Benjamin Rutt
  2004-07-26 22:59 ` Kevin Rodgers
  0 siblings, 2 replies; 8+ messages in thread
From: Shug Boabie @ 2004-07-24 22:35 UTC (permalink / raw)


hi there,

i like to compile my code from within Emacs as i have a Makefile setup.
however, upon compiling; even on a successful compile the compilation
buffer needs to be closed afterward.

i was wondering; is there a way to have the compilation buffer close
automatically if there are no warnings or errors?

also, is there a way to run the compile command, without having to agree
that `make -k` is the correct command each time? that extra 'enter' is just
annoying.

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

* Re: compiling in C mode and the compilation buffer
  2004-07-24 22:35 compiling in C mode and the compilation buffer Shug Boabie
@ 2004-07-25 22:52 ` Benjamin Rutt
  2004-07-28  1:24   ` Shug Boabie
  2004-07-26 22:59 ` Kevin Rodgers
  1 sibling, 1 reply; 8+ messages in thread
From: Benjamin Rutt @ 2004-07-25 22:52 UTC (permalink / raw)


Shug Boabie <no.spam@example.com> writes:

> i like to compile my code from within Emacs as i have a Makefile setup.
> however, upon compiling; even on a successful compile the compilation
> buffer needs to be closed afterward.
>
> i was wondering; is there a way to have the compilation buffer close
> automatically if there are no warnings or errors?
>
> also, is there a way to run the compile command, without having to agree
> that `make -k` is the correct command each time? that extra 'enter' is just
> annoying.

I would use the following for all of this:

(require 'compile)

;; don't prompt
(setq compilation-read-command nil)

;; close the window on successful compile
(defun my-compilation-finish-function-standard (buf str)
  ;; avoid doing this for buffers created from M-x grep
  (when (string-match "*compilation.*" (buffer-name buf))
    (if (string-match "exited abnormally" str)

	;;there were errors
	(progn
	  (message "compilation errors, press C-x ` to visit"))

      ;;no errors, make the compilation window go away
      (run-at-time 0.5 nil 'delete-windows-on buf)
      (message "NO COMPILATION ERRORS!"))))
(add-to-list 'compilation-finish-functions
	     'my-compilation-finish-function-standard)

-- 
Benjamin Rutt

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

* Re: compiling in C mode and the compilation buffer
  2004-07-24 22:35 compiling in C mode and the compilation buffer Shug Boabie
  2004-07-25 22:52 ` Benjamin Rutt
@ 2004-07-26 22:59 ` Kevin Rodgers
  1 sibling, 0 replies; 8+ messages in thread
From: Kevin Rodgers @ 2004-07-26 22:59 UTC (permalink / raw)


Shug Boabie wrote:
 > also, is there a way to run the compile command, without having to agree
 > that `make -k` is the correct command each time? that extra 'enter' is just
 > annoying.

M-x recompile

-- 
Kevin Rodgers

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

* Re: compiling in C mode and the compilation buffer
  2004-07-25 22:52 ` Benjamin Rutt
@ 2004-07-28  1:24   ` Shug Boabie
  2004-07-28  1:40     ` Shug Boabie
  0 siblings, 1 reply; 8+ messages in thread
From: Shug Boabie @ 2004-07-28  1:24 UTC (permalink / raw)


Benjamin Rutt wrote:
> Shug Boabie writes:
> > i was wondering; is there a way to have the compilation buffer close
> > automatically if there are no warnings or errors?
> >
> > also, is there a way to run the compile command, without having to agree
> > that `make -k` is the correct command each time? that extra 'enter' is just
> > annoying.
> 
> I would use the following for all of this:
> 
> (require 'compile)
> (setq compilation-read-command nil)
> (defun my-compilation-finish-function-standard (buf str)
>   ;; avoid doing this for buffers created from M-x grep
>   (when (string-match "*compilation.*" (buffer-name buf))
>     (if (string-match "exited abnormally" str)
> 	;;there were errors
> 	(progn
> 	  (message "compilation errors, press C-x ` to visit"))
>       ;;no errors, make the compilation window go away
>       (run-at-time 0.5 nil 'delete-windows-on buf)
>       (message "NO COMPILATION ERRORS!"))))
> (add-to-list 'compilation-finish-functions
> 	     'my-compilation-finish-function-standard)

excellent, however i would still like the window to remain open upon detection of warnings as well [in order to force me to write ISO C99 code :-)]. i use the compile command exclusively for C code, so a grep for "warning:" should be sufficient. however, my attempts to customise your function have failed. any further hints?

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

* Re: compiling in C mode and the compilation buffer
  2004-07-28  1:24   ` Shug Boabie
@ 2004-07-28  1:40     ` Shug Boabie
  2004-07-28 12:57       ` Benjamin Rutt
  0 siblings, 1 reply; 8+ messages in thread
From: Shug Boabie @ 2004-07-28  1:40 UTC (permalink / raw)


Shug Boabie wrote:

> excellent, however i would still like the window to remain open upon
> detection of warnings as well [in order to force me to write ISO C99 code
> :-)]. i use the compile command exclusively for C code, so a grep for
> "warning:" should be sufficient. however, my attempts to customise your
> function have failed. any further hints?

for the record, here is what i have been trying to do, but it is not
working:

(defun sam-compile (buf str)
  (when (string-match "*compilation.*" (buffer-name buf))
    (if (string-match "exited abnormally" str)
	(progn
          (message "compilation errors, press C-x ` to view"))
      (if (string-match "warning:" str)
          (progn
            (message "compilation warnings, press C-x ` to view"))
        (run-at-time 0.5 nil 'delete-windows-on buf)
        (message "no compile errors or warnings")))))

i have tried to do

 if (grep==error)
    error
 else if (grep==warning)
    warning
 else
    everything ok

but my elisp is not the best

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

* Re: compiling in C mode and the compilation buffer
  2004-07-28  1:40     ` Shug Boabie
@ 2004-07-28 12:57       ` Benjamin Rutt
  2004-07-28 20:29         ` Shug Boabie
  0 siblings, 1 reply; 8+ messages in thread
From: Benjamin Rutt @ 2004-07-28 12:57 UTC (permalink / raw)


Shug Boabie <no.spam@example.com> writes:

>> excellent, however i would still like the window to remain open upon
>> detection of warnings as well [in order to force me to write ISO C99 code
>> :-)]. i use the compile command exclusively for C code, so a grep for
>> "warning:" should be sufficient. however, my attempts to customise your
>> function have failed. any further hints?
>
> for the record, here is what i have been trying to do, but it is not
> working:
>
> (defun sam-compile (buf str)
>   (when (string-match "*compilation.*" (buffer-name buf))
>     (if (string-match "exited abnormally" str)
> 	(progn
>           (message "compilation errors, press C-x ` to view"))
>       (if (string-match "warning:" str)
>           (progn
>             (message "compilation warnings, press C-x ` to view"))
>         (run-at-time 0.5 nil 'delete-windows-on buf)
>         (message "no compile errors or warnings")))))

This won't work because the `str' variable above only gets the last
line output by emacs during a compilation.  It will either look like
"Compilation exited abnormally" or "Compilation finished".

I suggest if you really want to treat warnings as errors, you can tell
your compiler to do so.  Under gcc, you would pass the -Werror flag
during compilation.

Note, also, that even during successful compilation, you can still do
C-x ` to take you to any warnings that may have occured.
-- 
Benjamin Rutt

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

* Re: compiling in C mode and the compilation buffer
  2004-07-28 12:57       ` Benjamin Rutt
@ 2004-07-28 20:29         ` Shug Boabie
  2004-07-28 21:41           ` Benjamin Rutt
  0 siblings, 1 reply; 8+ messages in thread
From: Shug Boabie @ 2004-07-28 20:29 UTC (permalink / raw)


Benjamin Rutt wrote:
> Shug Boabie <no.spam@example.com> writes:
> 
> >> excellent, however i would still like the window to remain open upon
> >> detection of warnings as well [in order to force me to write ISO C99
> >code> :-)]. i use the compile command exclusively for C code, so a grep
> >for> "warning:" should be sufficient. however, my attempts to customise
> >your> function have failed. any further hints?
> >
> > for the record, here is what i have been trying to do, but it is not
> > working:
> >
> > (defun sam-compile (buf str)
> >   (when (string-match "*compilation.*" (buffer-name buf))
> >     (if (string-match "exited abnormally" str)
> > 	(progn
> >           (message "compilation errors, press C-x ` to view"))
> >       (if (string-match "warning:" str)
> >           (progn
> >             (message "compilation warnings, press C-x ` to view"))
> >         (run-at-time 0.5 nil 'delete-windows-on buf)
> >         (message "no compile errors or warnings")))))
> 
> This won't work because the `str' variable above only gets the last
> line output by emacs during a compilation.  It will either look like
> "Compilation exited abnormally" or "Compilation finished".

aah, i thought that might have been the case. cheers.

> I suggest if you really want to treat warnings as errors, you can tell
> your compiler to do so.  Under gcc, you would pass the -Werror flag
> during compilation.

yeah... i've been doing that as a workaround, but it would be nice to be
able to have it detect warnings.

if this function were made more advanced... like parsing the whole output,
it would allow warning detection AND also auto jump-to the first line of
warnings/errors that the compile command produces. but thats an exercise
for the more confident elisp user :-)

thanks for the function... it basically does what i wanted :-)

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

* Re: compiling in C mode and the compilation buffer
  2004-07-28 20:29         ` Shug Boabie
@ 2004-07-28 21:41           ` Benjamin Rutt
  0 siblings, 0 replies; 8+ messages in thread
From: Benjamin Rutt @ 2004-07-28 21:41 UTC (permalink / raw)


Shug Boabie <no.spam@example.com> writes:

> if this function were made more advanced... like parsing the whole output,
> it would allow warning detection AND also auto jump-to the first line of
> warnings/errors that the compile command produces. but thats an exercise
> for the more confident elisp user :-)

I can't help with the warning detection, but at least the following
version will teleport you to the error line (I personally hated this
when I had it this way though):

(defun my-compilation-finish-function-standard (buf str)
  ;; avoid doing this for buffers created from M-x grep
  (when (string-match "*compilation.*" (buffer-name buf))
    (if (string-match "exited abnormally" str)

	;;there were errors
	(progn
	  (message "compilation errors, press C-x ` to visit")
          (next-error 1))

      ;;no errors, make the compilation window go away
      (run-at-time 0.5 nil 'delete-windows-on buf)
      (message "NO COMPILATION ERRORS!"))))
-- 
Benjamin Rutt

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

end of thread, other threads:[~2004-07-28 21:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-24 22:35 compiling in C mode and the compilation buffer Shug Boabie
2004-07-25 22:52 ` Benjamin Rutt
2004-07-28  1:24   ` Shug Boabie
2004-07-28  1:40     ` Shug Boabie
2004-07-28 12:57       ` Benjamin Rutt
2004-07-28 20:29         ` Shug Boabie
2004-07-28 21:41           ` Benjamin Rutt
2004-07-26 22:59 ` Kevin Rodgers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).