* dired-x.el (dired-mode-map): Rebind dired-omit-mode to C-x M-o
[bpt/emacs.git] / doc / misc / flymake.texi
CommitLineData
4009494e
GM
1\input texinfo @c -*-texinfo-*-
2@comment %**start of header
db78a8cb 3@setfilename ../../info/flymake
4009494e
GM
4@set VERSION 0.3
5@set UPDATED April 2004
6@settitle GNU Flymake @value{VERSION}
7@syncodeindex pg cp
8@comment %**end of header
9
10@copying
11This manual is for GNU Flymake (version @value{VERSION}, @value{UPDATED}),
12which is a universal on-the-fly syntax checker for GNU Emacs.
13
6bc383b1 14Copyright @copyright{} 2004--2014 Free Software Foundation, Inc.
4009494e
GM
15
16@quotation
17Permission is granted to copy, distribute and/or modify this document
6a2c4aec 18under the terms of the GNU Free Documentation License, Version 1.3 or
4009494e
GM
19any later version published by the Free Software Foundation; with no
20Invariant Sections, with the Front-Cover texts being ``A GNU Manual,''
21and with the Back-Cover Texts as in (a) below. A copy of the license
debf4439 22is included in the section entitled ``GNU Free Documentation License''.
4009494e 23
6f093307 24(a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
6bf430d1 25modify this GNU manual.''
4009494e
GM
26@end quotation
27@end copying
28
0c973505 29@dircategory Emacs misc features
4009494e 30@direntry
62e034c2 31* Flymake: (flymake). A universal on-the-fly syntax checker.
4009494e
GM
32@end direntry
33
34@titlepage
35@title GNU Flymake
36@subtitle for version @value{VERSION}, @value{UPDATED}
37@author Pavel Kobiakov(@email{pk_at_work@@yahoo.com})
38@page
39@vskip 0pt plus 1filll
40@insertcopying
41@end titlepage
42
43@contents
44
45@ifnottex
46@node Top
47@top GNU Flymake
1df7defd 48@insertcopying
4009494e
GM
49@end ifnottex
50
51@menu
52* Overview of Flymake::
53* Installing Flymake::
54* Using Flymake::
55* Configuring Flymake::
56* Flymake Implementation::
57* GNU Free Documentation License::
58* Index::
59@end menu
60
61@node Overview of Flymake
62@chapter Overview
63@cindex Overview of Flymake
64
65Flymake is a universal on-the-fly syntax checker implemented as an
5d028165 66Emacs minor mode. Flymake runs the pre-configured syntax check tool
65e7ca35 67(compiler for C++ files, @code{perl} for perl files, etc.)@: in the
4009494e 68background, passing it a temporary copy of the current buffer, and
5d028165 69parses the output for known error/warning message patterns. Flymake
1df7defd 70then highlights erroneous lines (i.e., lines for which at least one
4009494e 71error or warning has been reported by the syntax check tool), and
5d028165 72displays an overall buffer status in the mode line. Status information
4009494e
GM
73displayed by Flymake contains total number of errors and warnings
74reported for the buffer during the last syntax check.
75
76@code{flymake-goto-next-error} and @code{flymake-goto-prev-error}
77functions allow for easy navigation to the next/previous erroneous
78line, respectively.
79
80Calling @code{flymake-display-err-menu-for-current-line} will popup a
81menu containing error messages reported by the syntax check tool for
5d028165 82the current line. Errors/warnings belonging to another file, such as a
4009494e 83@code{.h} header file included by a @code{.c} file, are shown in the
5d028165
XF
84current buffer as belonging to the first line. Menu items for such
85messages also contain a filename and a line number. Selecting such a
4009494e
GM
86menu item will automatically open the file and jump to the line with
87error.
88
5d028165 89Syntax check is done 'on-the-fly'. It is started whenever
4009494e
GM
90
91@itemize @bullet
92@item buffer is loaded
93@item a newline character is added to the buffer
94@item some changes were made to the buffer more than @code{0.5} seconds ago (the
95delay is configurable).
96@end itemize
97
98Flymake is a universal syntax checker in the sense that it's easily
99extended to support new syntax check tools and error message
5d028165 100patterns. @xref{Configuring Flymake}.
4009494e
GM
101
102@node Installing Flymake
103@chapter Installing
104@cindex Installing Flymake
105
106
107Flymake is packaged in a single file, @code{flymake.el}.
108
109To install/update Flymake, place @code{flymake.el} to a directory
5d028165 110somewhere on Emacs load path. You might also want to byte-compile
4009494e
GM
111@code{flymake.el} to improve performance.
112
113Also, place the following line in the @code{.emacs} file.
114
115@lisp
116(require 'flymake)
117@end lisp
118
119You might also map the most frequently used Flymake functions, such as
120@code{flymake-goto-next-error}, to some keyboard shortcuts:
121
122@lisp
123(global-set-key [f3] 'flymake-display-err-menu-for-current-line)
124(global-set-key [f4] 'flymake-goto-next-error)
125@end lisp
126
127@node Using Flymake
128@chapter Using Flymake
129@cindex Using Flymake
130
131@menu
132* Flymake mode::
133* Running the syntax check::
134* Navigating to error lines::
135* Viewing error messages::
136* Syntax check statuses::
137* Troubleshooting::
138@end menu
139
140@node Flymake mode
141@section Flymake mode
142@cindex flymake-mode
143
5d028165 144Flymake is an Emacs minor mode. To use Flymake, you
4009494e
GM
145must first activate @code{flymake-mode} by using the
146@code{flymake-mode} function.
147
148Instead of manually activating @code{flymake-mode}, you can configure
149Flymake to automatically enable @code{flymake-mode} upon opening any
5d028165 150file for which syntax check is possible. To do so, place the following
4009494e
GM
151line in @code{.emacs}:
152
153@lisp
154(add-hook 'find-file-hook 'flymake-find-file-hook)
155@end lisp
156
157@node Running the syntax check
158@section Running the syntax check
159@cindex Manually starting the syntax check
160
161When @code{flymake-mode} is active, syntax check is started
5d028165 162automatically on any of the three conditions mentioned above. Syntax
4009494e 163check can also be started manually by using the
5d028165 164@code{flymake-start-syntax-check-for-current-buffer} function. This
4009494e
GM
165can be used, for example, when changes were made to some other buffer
166affecting the current buffer.
167
168@node Navigating to error lines
169@section Navigating to error lines
170@cindex Navigating to error lines
171
172After syntax check is completed, lines for which at least one error or
173warning has been reported are highlighted, and total number of errors
5d028165 174and warning is shown in the mode line. Use the following functions to
4009494e
GM
175navigate the highlighted lines.
176
177@multitable @columnfractions 0.25 0.75
178
179@item @code{flymake-goto-next-error}
180@tab Moves point to the next erroneous line, if any.
181
182@item @code{flymake-goto-prev-error}
183@tab Moves point to the previous erroneous line.
184
185@end multitable
186
5d028165 187These functions treat erroneous lines as a linked list. Therefore,
4009494e
GM
188@code{flymake-goto-next-error} will go to the first erroneous line
189when invoked in the end of the buffer.
190
191@node Viewing error messages
192@section Viewing error messages
193@cindex Viewing error messages
194
195To view error messages belonging to the current line, use the
5d028165 196@code{flymake-display-err-menu-for-current-line} function. If there's
4009494e
GM
197at least one error or warning reported for the current line, this
198function will display a popup menu with error/warning texts.
199Selecting the menu item whose error belongs to another file brings
200forward that file with the help of the
201@code{flymake-goto-file-and-line} function.
202
203@node Syntax check statuses
204@section Syntax check statuses
205@cindex Syntax check statuses
206
207After syntax check is finished, its status is displayed in the mode line.
208The following statuses are defined.
209
210@multitable @columnfractions 0.25 0.75
211@item Flymake* or Flymake:E/W*
5d028165 212@tab Flymake is currently running. For the second case, E/W contains the
6800ff8d 213error and warning count for the previous run.
4009494e
GM
214
215@item Flymake
5d028165
XF
216@tab Syntax check is not running. Usually this means syntax check was
217successfully passed (no errors, no warnings). Other possibilities are:
6800ff8d
GM
218syntax check was killed as a result of executing
219@code{flymake-compile}, or syntax check cannot start as compilation
220is currently in progress.
4009494e
GM
221
222@item Flymake:E/W
223@tab Number of errors/warnings found by the syntax check process.
224
225@item Flymake:!
226@tab Flymake was unable to find master file for the current buffer.
227@end multitable
228
229The following errors cause a warning message and switch flymake mode
230OFF for the buffer.
231
232@multitable @columnfractions 0.25 0.75
233@item CFGERR
234@tab Syntax check process returned nonzero exit code, but no
5d028165 235errors/warnings were reported. This indicates a possible configuration
6800ff8d
GM
236error (for example, no suitable error message patterns for the
237syntax check tool).
4009494e
GM
238
239@item NOMASTER
240@tab Flymake was unable to find master file for the current buffer.
241
242@item NOMK
243@tab Flymake was unable to find a suitable buildfile for the current buffer.
244
245@item PROCERR
246@tab Flymake was unable to launch a syntax check process.
247@end multitable
248
249
250@node Troubleshooting
251@section Troubleshooting
252@cindex Logging
253@cindex Troubleshooting
254
255Flymake uses a simple logging facility for indicating important points
5d028165
XF
256in the control flow. The logging facility sends logging messages to
257the @code{*Messages*} buffer. The information logged can be used for
4009494e
GM
258resolving various problems related to Flymake.
259
260Logging output is controlled by the @code{flymake-log-level}
5d028165 261variable. @code{3} is the most verbose level, and @code{-1} switches
4009494e
GM
262logging off.
263
264@node Configuring Flymake
265@chapter Configuring and Extending Flymake
266@cindex Configuring and Extending Flymake
267
268@menu
269* Customizable variables::
270* Adding support for a new syntax check tool::
271@end menu
272
273Flymake was designed to be easily extended for supporting new syntax
274check tools and error message patterns.
275
276@node Customizable variables
277@section Customizable variables
278@cindex Customizable variables
279
280This section summarizes variables used for Flymake
281configuration.
282
283@table @code
284@item flymake-log-level
285Controls logging output, see @ref{Troubleshooting}.
286
287@item flymake-allowed-file-name-masks
288A list of @code{(filename-regexp, init-function, cleanup-function
5d028165 289getfname-function)} for configuring syntax check tools. @xref{Adding
4009494e
GM
290support for a new syntax check tool}.
291
9b97b143 292@ignore
4009494e
GM
293@item flymake-buildfile-dirs
294A list of directories (relative paths) for searching a
5d028165 295buildfile. @xref{Locating the buildfile}.
9b97b143 296@end ignore
4009494e
GM
297
298@item flymake-master-file-dirs
5d028165 299A list of directories for searching a master file. @xref{Locating a
4009494e
GM
300master file}.
301
302@item flymake-get-project-include-dirs-function
303A function used for obtaining a list of project include dirs (C/C++
5d028165 304specific). @xref{Getting the include directories}.
4009494e
GM
305
306@item flymake-master-file-count-limit
307@itemx flymake-check-file-limit
5d028165 308Used when looking for a master file. @xref{Locating a master file}.
4009494e
GM
309
310@item flymake-err-line-patterns
311Patterns for error/warning messages in the form @code{(regexp file-idx
5d028165 312line-idx col-idx err-text-idx)}. @xref{Parsing the output}.
4009494e 313
c5b0993e
EW
314@item flymake-warning-predicate
315Predicate to classify error text as warning. @xref{Parsing the output}.
316
4009494e
GM
317@item flymake-compilation-prevents-syntax-check
318A flag indicating whether compilation and syntax check of the same
319file cannot be run simultaneously.
320
321@item flymake-no-changes-timeout
322If any changes are made to the buffer, syntax check is automatically
323started after @code{flymake-no-changes-timeout} seconds.
324
325@item flymake-gui-warnings-enabled
326A boolean flag indicating whether Flymake will show message boxes for
5d028165 327non-recoverable errors. If @code{flymake-gui-warnings-enabled} is
4009494e
GM
328@code{nil}, these errors will only be logged to the @code{*Messages*}
329buffer.
330
331@item flymake-start-syntax-check-on-newline
332A boolean flag indicating whether to start syntax check after a
333newline character is added to the buffer.
334
176c6903 335@item flymake-errline
4009494e
GM
336A custom face for highlighting lines for which at least one error has
337been reported.
338
176c6903 339@item flymake-warnline
4009494e
GM
340A custom face for highlighting lines for which at least one warning
341and no errors have been reported.
342
24c38527
GM
343@item flymake-error-bitmap
344A bitmap used in the fringe to mark lines for which an error has
345been reported.
346
347@item flymake-warning-bitmap
348A bitmap used in the fringe to mark lines for which a warning has
349been reported.
350
351@item flymake-fringe-indicator-position
352Which fringe (if any) should show the warning/error bitmaps.
353
4009494e
GM
354@end table
355
356@node Adding support for a new syntax check tool
357@section Adding support for a new syntax check tool
358@cindex Adding support for a new syntax check tool
359
360@menu
f99f1641
PE
361* Example---Configuring a tool called directly::
362* Example---Configuring a tool called via make::
4009494e
GM
363@end menu
364
365Syntax check tools are configured using the
5d028165 366@code{flymake-allowed-file-name-masks} list. Each item of this list
4009494e
GM
367has the following format:
368
369@lisp
370(filename-regexp, init-function, cleanup-function, getfname-function)
371@end lisp
372
373@table @code
374@item filename-regexp
375This field is used as a key for locating init/cleanup/getfname
376functions for the buffer. Items in
5d028165 377@code{flymake-allowed-file-name-masks} are searched sequentially. The
4009494e 378first item with @code{filename-regexp} matching buffer filename is
5d028165 379selected. If no match is found, @code{flymake-mode} is switched off.
4009494e
GM
380
381@item init-function
382@code{init-function} is required to initialize the syntax check,
5d028165
XF
383usually by creating a temporary copy of the buffer contents. The
384function must return @code{(list cmd-name arg-list)}. If
4009494e
GM
385@code{init-function} returns null, syntax check is aborted, by
386@code{flymake-mode} is not switched off.
387
388@item cleanup-function
389@code{cleanup-function} is called after the syntax check process is
390complete and should take care of proper deinitialization, which is
391usually deleting a temporary copy created by the @code{init-function}.
392
393@item getfname-function
394This function is used for translating filenames reported by the syntax
5d028165 395check tool into ``real'' filenames. Filenames reported by the tool
4009494e
GM
396will be different from the real ones, as actually the tool works with
397the temporary copy. In most cases, the default implementation
398provided by Flymake, @code{flymake-get-real-file-name}, can be used as
399@code{getfname-function}.
400
401@end table
402
403To add support for a new syntax check tool, write corresponding
404@code{init-function}, and, optionally @code{cleanup-function} and
405@code{getfname-function}. If the format of error messages reported by
406the new tool is not yet supported by Flymake, add a new entry to
407the @code{flymake-err-line-patterns} list.
408
409The following sections contain some examples of configuring Flymake
410support for various syntax check tools.
411
f99f1641
PE
412@node Example---Configuring a tool called directly
413@subsection Example---Configuring a tool called directly
4009494e
GM
414@cindex Adding support for perl
415
416In this example, we will add support for @code{perl} as a syntax check
5d028165 417tool. @code{perl} supports the @code{-c} option which does syntax
4009494e
GM
418checking.
419
420First, we write the @code{init-function}:
421
422@lisp
176c6903 423(defun flymake-perl-init ()
4009494e 424 (let* ((temp-file (flymake-init-create-temp-buffer-copy
176c6903 425 'flymake-create-temp-inplace))
9360256a 426 (local-file (file-relative-name
5ef5ef3f
RS
427 temp-file
428 (file-name-directory buffer-file-name))))
4009494e
GM
429 (list "perl" (list "-wc " local-file))))
430@end lisp
431
432@code{flymake-perl-init} creates a temporary copy of the buffer
433contents with the help of
434@code{flymake-init-create-temp-buffer-copy}, and builds an appropriate
435command line.
436
437Next, we add a new entry to the
438@code{flymake-allowed-file-name-masks}:
439
440@lisp
441(setq flymake-allowed-file-name-masks
442 (cons '(".+\\.pl$"
443 flymake-perl-init
444 flymake-simple-cleanup
445 flymake-get-real-file-name)
446 flymake-allowed-file-name-masks))
447@end lisp
448
449Note that we use standard @code{cleanup-function} and
450@code{getfname-function}.
451
452Finally, we add an entry to @code{flymake-err-line-patterns}:
453
454@lisp
455(setq flymake-err-line-patterns
456 (cons '("\\(.*\\) at \\([^ \n]+\\) line \\([0-9]+\\)[,.\n]"
457 2 3 nil 1)
458 flymake-err-line-patterns))
459@end lisp
460
f99f1641
PE
461@node Example---Configuring a tool called via make
462@subsection Example---Configuring a tool called via make
4009494e
GM
463@cindex Adding support for C (gcc+make)
464
465In this example we will add support for C files syntax checked by
8ae818e4 466@command{gcc} called via @command{make}.
4009494e
GM
467
468We're not required to write any new functions, as Flymake already has
5d028165 469functions for @command{make}. We just add a new entry to the
4009494e
GM
470@code{flymake-allowed-file-name-masks}:
471
472@lisp
473(setq flymake-allowed-file-name-masks
474 (cons '(".+\\.c$"
475 flymake-simple-make-init
476 flymake-simple-cleanup
477 flymake-get-real-file-name)
478 flymake-allowed-file-name-masks))
479@end lisp
480
8ae818e4 481@code{flymake-simple-make-init} builds the following @command{make}
4009494e
GM
482command line:
483
484@lisp
485(list "make"
486 (list "-s" "-C"
487 base-dir
488 (concat "CHK_SOURCES=" source)
489 "SYNTAX_CHECK_MODE=1"
490 "check-syntax"))
491@end lisp
492
493@code{base-dir} is a directory containing @code{Makefile}, see @ref{Locating the buildfile}.
494
5d028165 495Thus, @code{Makefile} must contain the @code{check-syntax} target. In
4009494e
GM
496our case this target might look like this:
497
498@verbatim
499check-syntax:
064e2d08 500 gcc -o /dev/null -S ${CHK_SOURCES}
4009494e
GM
501@end verbatim
502
8ae818e4
CY
503@noindent
504The format of error messages reported by @command{gcc} is already
4009494e 505supported by Flymake, so we don't have to add a new entry to
8ae818e4
CY
506@code{flymake-err-line-patterns}. Note that if you are using
507Automake, you may want to replace @code{gcc} with the standard
508Automake variable @code{COMPILE}:
509
510@verbatim
511check-syntax:
512 $(COMPILE) -o /dev/null -S ${CHK_SOURCES}
513@end verbatim
4009494e
GM
514
515@node Flymake Implementation
516@chapter Flymake Implementation
517@cindex Implementation details
518
519@menu
520* Determining whether syntax check is possible::
521* Making a temporary copy::
522* Locating a master file::
523* Getting the include directories::
524* Locating the buildfile::
525* Starting the syntax check process::
526* Parsing the output::
527* Highlighting erroneous lines::
528* Interaction with other modes::
529@end menu
530
531Syntax check is started by calling @code{flymake-start-syntax-check-for-current-buffer}.
532Flymake first determines whether it is able to do syntax
5d028165 533check. It then saves a copy of the buffer in a temporary file in the
f99f1641 534buffer's directory (or in the system temp directory, for java
4009494e 535files), creates a syntax check command and launches a process with
5d028165 536this command. The output is parsed using a list of error message patterns,
4009494e 537and error information (file name, line number, type and text) is
5d028165 538saved. After the process has finished, Flymake highlights erroneous
4009494e
GM
539lines in the buffer using the accumulated error information.
540
541@node Determining whether syntax check is possible
542@section Determining whether syntax check is possible
543@cindex Syntax check models
544@cindex Master file
545
546Syntax check is considered possible if there's an entry in
547@code{flymake-allowed-file-name-masks} matching buffer's filename and
548its @code{init-function} returns non-@code{nil} value.
549
550Two syntax check modes are distinguished:
551
552@enumerate
553
554@item
555Buffer can be syntax checked in a standalone fashion, that is, the
556file (its temporary copy, in fact) can be passed over to the compiler to
5d028165 557do the syntax check. Examples are C/C++ (.c, .cpp) and Java (.java)
4009494e
GM
558sources.
559
560@item
561Buffer can be syntax checked, but additional file, called master file,
5d028165 562is required to perform this operation. A master file is a file that
4009494e 563includes the current file, so that running a syntax check tool on it
5d028165 564will also check syntax in the current file. Examples are C/C++ (.h,
4009494e
GM
565.hpp) headers.
566
567@end enumerate
568
569These modes are handled inside init/cleanup/getfname functions, see
570@ref{Adding support for a new syntax check tool}.
571
572Flymake contains implementations of all functionality required to
8ae818e4
CY
573support different syntax check modes described above (making temporary
574copies, finding master files, etc.), as well as some tool-specific
65e7ca35 575(routines for Make, Ant, etc.)@: code.
4009494e
GM
576
577
578@node Making a temporary copy
579@section Making a temporary copy
580@cindex Temporary copy of the buffer
581@cindex Master file
582
583After the possibility of the syntax check has been determined, a
584temporary copy of the current buffer is made so that the most recent
5d028165 585unsaved changes could be seen by the syntax check tool. Making a copy
4009494e
GM
586is quite straightforward in a standalone case (mode @code{1}), as it's
587just saving buffer contents to a temporary file.
588
589Things get trickier, however, when master file is involved, as it
590requires to
591
592@itemize @bullet
593@item locate a master file
594@item patch it to include the current file using its new (temporary)
595name.
596@end itemize
597
598Locating a master file is discussed in the following section.
599
600Patching just changes all appropriate lines of the master file so that they
5d028165 601use the new (temporary) name of the current file. For example, suppose current
4009494e 602file name is @code{file.h}, the master file is @code{file.cpp}, and
5d028165 603it includes current file via @code{#include "file.h"}. Current file's copy
4009494e 604is saved to file @code{file_flymake.h}, so the include line must be
5d028165 605changed to @code{#include "file_flymake.h"}. Finally, patched master file
4009494e
GM
606is saved to @code{file_flymake_master.cpp}, and the last one is passed to
607the syntax check tool.
608
609@node Locating a master file
610@section Locating a master file
611@cindex Master file
612
613Master file is located in two steps.
614
5d028165
XF
615First, a list of possible master files is built. A simple name
616matching is used to find the files. For a C++ header @code{file.h},
4009494e
GM
617Flymake searches for all @code{.cpp} files in the directories whose relative paths are
618stored in a customizable variable @code{flymake-master-file-dirs}, which
5d028165 619usually contains something like @code{("." "./src")}. No more than
4009494e 620@code{flymake-master-file-count-limit} entries is added to the master file
5d028165 621list. The list is then sorted to move files with names @code{file.cpp} to
4009494e
GM
622the top.
623
624Next, each master file in a list is checked to contain the appropriate
5d028165 625include directives. No more than @code{flymake-check-file-limit} of each
4009494e
GM
626file are parsed.
627
628For @code{file.h}, the include directives to look for are
5d028165 629@code{#include "file.h"}, @code{#include "../file.h"}, etc. Each
4009494e
GM
630include is checked against a list of include directories
631(see @ref{Getting the include directories}) to be sure it points to the
632correct @code{file.h}.
633
5d028165
XF
634First matching master file found stops the search. The master file is then
635patched and saved to disk. In case no master file is found, syntax check is
4009494e
GM
636aborted, and corresponding status (!) is reported in the mode line.
637
638@node Getting the include directories
639@section Getting the include directories
640@cindex Include directories (C/C++ specific)
641
642Two sets of include directories are distinguished: system include directories
5d028165
XF
643and project include directories. The former is just the contents of the
644@code{INCLUDE} environment variable. The latter is not so easy to obtain,
4009494e
GM
645and the way it can be obtained can vary greatly for different projects.
646Therefore, a customizable variable
647@code{flymake-get-project-include-dirs-function} is used to provide the
648way to implement the desired behavior.
649
650The default implementation, @code{flymake-get-project-include-dirs-imp},
5d028165 651uses a @command{make} call. This requires a correct base directory, that is, a
8ae818e4 652directory containing a correct @file{Makefile}, to be determined.
4009494e
GM
653
654As obtaining the project include directories might be a costly operation, its
5d028165 655return value is cached in the hash table. The cache is cleared in the beginning
4009494e
GM
656of every syntax check attempt.
657
658@node Locating the buildfile
659@section Locating the buildfile
660@cindex Locating the buildfile
661@cindex buildfile, locating
662@cindex Makefile, locating
663
664Flymake can be configured to use different tools for performing syntax
5d028165 665checks. For example, it can use direct compiler call to syntax check a perl
8ae818e4 666script or a call to @command{make} for a more complicated case of a
5d028165 667@code{C/C++} source. The general idea is that simple files, like perl
4009494e 668scripts and html pages, can be checked by directly invoking a
5d028165 669corresponding tool. Files that are usually more complex and generally
4009494e
GM
670used as part of larger projects, might require non-trivial options to
671be passed to the syntax check tool, like include directories for
5d028165 672C++. The latter files are syntax checked using some build tool, like
8ae818e4 673Make or Ant.
4009494e 674
8ae818e4 675All Make configuration data is usually stored in a file called
5d028165 676@code{Makefile}. To allow for future extensions, flymake uses a notion of
4009494e
GM
677buildfile to reference the 'project configuration' file.
678
679Special function, @code{flymake-find-buildfile} is provided for locating buildfiles.
680Searching for a buildfile is done in a manner similar to that of searching
9b97b143
GM
681for possible master files.
682@ignore
683A customizable variable
4009494e 684@code{flymake-buildfile-dirs} holds a list of relative paths to the
5d028165 685buildfile. They are checked sequentially until a buildfile is found.
9b97b143
GM
686@end ignore
687In case there's no build file, syntax check is aborted.
4009494e
GM
688
689Buildfile values are also cached.
690
691@node Starting the syntax check process
692@section Starting the syntax check process
693@cindex Syntax check process
694
695The command line (command name and the list of arguments) for launching a process is returned by the
5d028165 696initialization function. Flymake then just calls @code{start-process}
4009494e
GM
697to start an asynchronous process and configures process filter and
698sentinel which is used for processing the output of the syntax check
699tool.
700
701@node Parsing the output
702@section Parsing the output
703@cindex Parsing the output
704
705The output generated by the syntax check tool is parsed in the process
706filter/sentinel using the error message patterns stored in the
5d028165 707@code{flymake-err-line-patterns} variable. This variable contains a
4009494e
GM
708list of items of the form @code{(regexp file-idx line-idx
709err-text-idx)}, used to determine whether a particular line is an
710error message and extract file name, line number and error text,
5d028165
XF
711respectively. Error type (error/warning) is also guessed by matching
712error text with the '@code{^[wW]arning}' pattern. Anything that was not
713classified as a warning is considered an error. Type is then used to
4009494e
GM
714sort error menu items, which shows error messages first.
715
716Flymake is also able to interpret error message patterns missing err-text-idx
5d028165
XF
717information. This is done by merely taking the rest of the matched line
718(@code{(substring line (match-end 0))}) as error text. This trick allows
4009494e 719to make use of a huge collection of error message line patterns from
5d028165 720@code{compile.el}. All these error patterns are appended to
4009494e
GM
721the end of @code{flymake-err-line-patterns}.
722
723The error information obtained is saved in a buffer local
5d028165 724variable. The buffer for which the process output belongs is
4009494e
GM
725determined from the process-id@w{}->@w{}buffer mapping updated
726after every process launch/exit.
727
728@node Highlighting erroneous lines
729@section Highlighting erroneous lines
730@cindex Erroneous lines, faces
731
732Highlighting is implemented with overlays and happens in the process
5d028165 733sentinel, after calling the cleanup function. Two customizable faces
176c6903
RS
734are used: @code{flymake-errline} and
735@code{flymake-warnline}. Errors belonging outside the current
4009494e
GM
736buffer are considered to belong to line 1 of the current buffer.
737
24c38527
GM
738@c This manual does not use vindex.
739@c @vindex flymake-fringe-indicator-position
740@c @vindex flymake-error-bitmap
741@c @vindex flymake-warning-bitmap
742If the option @code{flymake-fringe-indicator-position} is non-@code{nil},
743errors and warnings are also highlighted in the left or right fringe,
744using the bitmaps specified by @code{flymake-error-bitmap}
745and @code{flymake-warning-bitmap}.
746
4009494e
GM
747@node Interaction with other modes
748@section Interaction with other modes
749@cindex Interaction with other modes
750@cindex Interaction with compile mode
751
752The only mode flymake currently knows about is @code{compile}.
753
754Flymake can be configured to not start syntax check if it thinks the
5d028165 755compilation is in progress. The check is made by the
4009494e 756@code{flymake-compilation-is-running}, which tests the
5d028165 757@code{compilation-in-progress} variable. The reason why this might be
4009494e 758useful is saving CPU time in case both syntax check and compilation
5d028165
XF
759are very CPU intensive. The original reason for adding this feature,
760though, was working around a locking problem with MS Visual C++
761compiler.
4009494e
GM
762
763Flymake also provides an alternative command for starting compilation,
764@code{flymake-compile}:
765
766@lisp
767(defun flymake-compile ()
768 "Kill all flymake syntax checks then start compilation."
769 (interactive)
770 (flymake-stop-all-syntax-checks)
771 (call-interactively 'compile))
772@end lisp
773
774It just kills all the active syntax check processes before calling
775@code{compile}.
776
777@node GNU Free Documentation License
778@appendix GNU Free Documentation License
779@include doclicense.texi
780
781@node Index
782@unnumbered Index
783
784@printindex cp
785
786@bye