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