(emacs)Compilation


Next: Debuggers Up: Building

Running `make', or Compilers Generally
======================================

   Emacs can run compilers for noninteractive languages such as C and
Fortran as inferior processes, feeding the error log into an Emacs
buffer.  It can also parse the error messages and show you the source
lines where compilation errors occurred.

`M-x compile'
     Run a compiler asynchronously under Emacs, with error messages to
     `*compilation*' buffer.

`M-x grep'
     Run `grep' asynchronously under Emacs, with matching lines listed
     in the buffer named `*grep*'.

`M-x kill-compilation'
`M-x kill-grep'
     Kill the running compilation or `grep' subprocess.

`C-x `'
     Visit the locus of the next compiler error message or `grep' match.

   To run `make' or another compilation command, do `M-x compile'.
This command reads a shell command line using the minibuffer, and then
executes the command in an inferior shell, putting output in the buffer
named `*compilation*'.  The current buffer's default directory is used
as the working directory for the execution of the command; normally,
therefore, the compilation happens in this directory.

   When the shell command line is read, the minibuffer appears
containing a default command line, which is the command you used the
last time you did `M-x compile'.  If you type just RET, the same command
line is used again.  For the first `M-x compile', the default is `make
-k'.

   The default compilation command comes from the variable
`compile-command'; if the appropriate compilation command for a file is
something other than `make -k', it can be useful for the file to
specify a local value for `compile-command' (Note: File Variables.).

   Starting a compilation displays the buffer `*compilation*' in
another window but does not select it.  The buffer's mode line tells you
whether compilation is finished, with the word `run' or `exit' inside
the parentheses.  You do not have to keep this buffer visible;
compilation continues in any case.  While a compilation is going on, the
string `Compiling' appears in the mode lines of all windows.  When this
string disappears, the compilation is finished.

   To kill the compilation process, do `M-x kill-compilation'.  When
the compiler process terminates, the mode line of the `*compilation*'
buffer changes to say `signal' instead of `run'.  Starting a new
compilation also kills any running compilation, as only one can exist
at any time.  However, `M-x compile' asks for confirmation before
actually killing a compilation that is running.

   The `*compilation*' buffer uses a special major mode, Compilation
mode.  This mode provides the keys SPC and DEL to scroll by screenfuls,
and `M-n' and `M-p' to move to the next or previous error message.  You
can also use `M-{' and `M-}' to move up or down to an error message for
a different source file.  You can visit the source for any particular
error message by moving point in `*compilation*' to that error message
and typing `C-c C-c' (`compile-goto-error').

   To parse the compiler error messages sequentially, type `C-x `'
(`next-error').  The character following the `C-x' is the backquote or
"grave accent," not the single-quote.  This command is available in all
buffers, not just in `*compilation*'.  It displays the next error
message at the top of one window and source location of the error in
another window.

   The first time `C-x `' is used after the start of a compilation, it
moves to the first error's location.  Subsequent uses of `C-x `'
advance down the data set up by the first use.  When the preparsed error
messages are exhausted, the next `C-x `' checks for any more error
messages that have come in; this is useful if you start editing the
compilation errors while the compilation is still going on.  If no more
error messages have come in, `C-x `' reports an error.

   `C-u C-x `' discards the preparsed error message data and parses the
`*compilation*' buffer over again, then displaying the first error.
This way, you can process the same set of errors again.

   Instead of running a compiler, you can run `grep' and see the lines
on which matches were found.  To do this, type `M-x grep' with an
argument line that contains the same arguments you would give `grep'
when running it normally: a `grep'-style regexp (usually in
single-quotes to quote the shell's special characters) followed by file
names which may use wildcards.  The output from `grep' goes in the
`*grep*' buffer and the lines that matched can be found with `C-x `' as
if they were compilation errors.

   Note: a shell is used to run the compile command, but the shell is
told that it should be noninteractive.  This means in particular that
the shell starts up with no prompt.  If you find your usual shell
prompt making an unsightly appearance in the `*compilation*' buffer, it
means you have made a mistake in your shell's init file (`.cshrc' or
`.shrc' or ...) by setting the prompt unconditionally.  The shell init
file should set the prompt only if there already is a prompt.  In
`csh', here is how to do it:

     if ($?prompt) set prompt = ...


automatically generated by info2www