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