[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

32.2 Compilation Mode

The ‘*compilation*’ buffer uses a special major mode, Compilation mode, whose main feature is to provide a convenient way to visit the source line corresponding to an error message. These commands are also available in other special buffers that list locations in files, including those made by M-x grep and M-x occur.

M-g M-n
M-g n
C-x `

Visit the locus of the next error message or match.

M-g M-p
M-g p

Visit the locus of the previous error message or match.

<RET>

Visit the locus of the error message that point is on. This command is used in the compilation buffer.

Mouse-2

Visit the locus of the error message that you click on.

M-n

Find and highlight the locus of the next error message, without selecting the source buffer.

M-p

Find and highlight the locus of the previous error message, without selecting the source buffer.

M-}

Move point to the next error for a different file than the current one.

M-{

Move point to the previous error for a different file than the current one.

C-c C-f

Toggle Next Error Follow minor mode, which makes cursor motion in the compilation buffer produce automatic source display.

You can visit the source for any particular error message by moving point in the ‘*compilation*’ buffer to that error message and typing <RET> (compile-goto-error). Alternatively, you can click Mouse-2 on the error message; you need not switch to the ‘*compilation*’ buffer first.

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. It also temporarily highlights the relevant source line, for a period controlled by the variable next-error-highlight.

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 to subsequent errors. If you visit a specific error message with <RET> or Mouse-2, subsequent C-x ` commands advance from there. When C-x ` gets to the end of the buffer and finds no more error messages to visit, it fails and signals an Emacs error. C-u C-x ` starts scanning from the beginning of the compilation buffer, and goes to the first error's location.

By default, C-x ` skips less important messages. The variable compilation-skip-threshold controls this. If its value is 2, C-x ` skips anything less than error, 1 skips anything less than warning, and 0 doesn't skip any messages. The default is 1.

When the window has a left fringe, an arrow in the fringe points to the current message in the compilation buffer. The variable compilation-context-lines controls the number of lines of leading context to display before the current message. Going to an error message location scrolls the ‘*compilation*’ buffer to put the message that far down from the top. The value nil is special: if there's a left fringe, the window doesn't scroll at all if the message is already visible. If there is no left fringe, nil means display the message at the top of the window.

If you're not in the compilation buffer when you run next-error, Emacs will look for a buffer that contains error messages. First, it looks for one displayed in the selected frame, then for one that previously had next-error called on it, and then at the current buffer. Finally, Emacs looks at all the remaining buffers. next-error signals an error if it can't find any such buffer.

To parse messages from the compiler, Compilation mode uses the variable compilation-error-regexp-alist which lists various formats of error messages and tells Emacs how to extract the source file and the line number from the text of a message. If your compiler isn't supported, you can tailor Compilation mode to it by adding elements to that list. A similar variable grep-regexp-alist tells Emacs how to parse output of a grep command.

Compilation mode also redefines the keys <SPC> and <DEL> to scroll by screenfuls, and M-n (compilation-next-error) and M-p (compilation-previous-error) to move to the next or previous error message. You can also use M-{ (compilation-next-file and M-} (compilation-previous-file) to move up or down to an error message for a different source file.

You can type C-c C-f to toggle Next Error Follow mode. In this minor mode, ordinary cursor motion in the compilation buffer automatically updates the source buffer. For instance, moving the cursor to the next error message causes the location of that error to be displayed immediately.

The features of Compilation mode are also available in a minor mode called Compilation Minor mode. This lets you parse error messages in any buffer, not just a normal compilation output buffer. Type M-x compilation-minor-mode to enable the minor mode. This defines the keys <RET> and Mouse-2, as in the Compilation major mode.

Compilation minor mode works in any buffer, as long as the contents are in a format that it understands. In an Rlogin buffer (voir la section Remote Host Shell), Compilation minor mode automatically accesses remote source files by FTP (voir la section File Names).


[ < ] [ > ]   [ << ] [Plus haut] [ >> ]         [Top] [Table des matières] [Index] [ ? ]

Ce document a été généré par Eric Reinbold le 23 Février 2009 en utilisant texi2html 1.78.