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