aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXue Fuqiao2013-05-25 09:26:12 +0800
committerXue Fuqiao2013-05-25 09:26:12 +0800
commit5d028165eaee1c5d0e59859199f8c6a51230eb97 (patch)
treee9a4ea6772d628b7590faaf47f8728f896f5ea60
parent7a1d7ba7d22e9d82fdde0bc6e9fcc5152a7c9670 (diff)
downloademacs-5d028165eaee1c5d0e59859199f8c6a51230eb97.tar.gz
emacs-5d028165eaee1c5d0e59859199f8c6a51230eb97.zip
Refine the documentation of Flymake
* progmodes/flymake.el (flymake-save-buffer-in-file) (flymake-makehash, flymake-posn-at-point-as-event, flymake-nop) (flymake-selected-frame, flymake-log, flymake-ins-after) (flymake-set-at, flymake-get-buildfile-from-cache) (flymake-add-buildfile-to-cache, flymake-clear-buildfile-cache) (flymake-find-possible-master-files, flymake-save-buffer-in-file): Refine the doc string. (flymake-get-file-name-mode-and-masks): Reformat. (flymake-get-real-file-name-function): Fix a minor bug. * flymake.texi: Changing from one space between sentences to two.
-rw-r--r--doc/misc/ChangeLog4
-rw-r--r--doc/misc/flymake.texi163
-rw-r--r--lisp/ChangeLog12
-rw-r--r--lisp/progmodes/flymake.el61
4 files changed, 141 insertions, 99 deletions
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog
index 74b08c04714..e74926ea25c 100644
--- a/doc/misc/ChangeLog
+++ b/doc/misc/ChangeLog
@@ -1,3 +1,7 @@
12013-05-25 Xue Fuqiao <xfq.free@gmail.com>
2
3 * flymake.texi: Changing from one space between sentences to two.
4
12013-05-04 Stefan Monnier <monnier@iro.umontreal.ca> 52013-05-04 Stefan Monnier <monnier@iro.umontreal.ca>
2 6
3 * cl.texi (Obsolete Macros): Describe replacements for `flet' 7 * cl.texi (Obsolete Macros): Describe replacements for `flet'
diff --git a/doc/misc/flymake.texi b/doc/misc/flymake.texi
index 5dedda16ee1..f88bd95008c 100644
--- a/doc/misc/flymake.texi
+++ b/doc/misc/flymake.texi
@@ -63,13 +63,13 @@ modify this GNU manual.''
63@cindex Overview of Flymake 63@cindex Overview of Flymake
64 64
65Flymake is a universal on-the-fly syntax checker implemented as an 65Flymake is a universal on-the-fly syntax checker implemented as an
66Emacs minor mode. Flymake runs the pre-configured syntax check tool 66Emacs minor mode. Flymake runs the pre-configured syntax check tool
67(compiler for C++ files, @code{perl} for perl files, etc.)@: in the 67(compiler for C++ files, @code{perl} for perl files, etc.)@: in the
68background, passing it a temporary copy of the current buffer, and 68background, passing it a temporary copy of the current buffer, and
69parses the output for known error/warning message patterns. Flymake 69parses the output for known error/warning message patterns. Flymake
70then highlights erroneous lines (i.e., lines for which at least one 70then highlights erroneous lines (i.e., lines for which at least one
71error or warning has been reported by the syntax check tool), and 71error or warning has been reported by the syntax check tool), and
72displays an overall buffer status in the mode line. Status information 72displays an overall buffer status in the mode line. Status information
73displayed by Flymake contains total number of errors and warnings 73displayed by Flymake contains total number of errors and warnings
74reported for the buffer during the last syntax check. 74reported for the buffer during the last syntax check.
75 75
@@ -79,14 +79,14 @@ line, respectively.
79 79
80Calling @code{flymake-display-err-menu-for-current-line} will popup a 80Calling @code{flymake-display-err-menu-for-current-line} will popup a
81menu containing error messages reported by the syntax check tool for 81menu containing error messages reported by the syntax check tool for
82the current line. Errors/warnings belonging to another file, such as a 82the current line. Errors/warnings belonging to another file, such as a
83@code{.h} header file included by a @code{.c} file, are shown in the 83@code{.h} header file included by a @code{.c} file, are shown in the
84current buffer as belonging to the first line. Menu items for such 84current buffer as belonging to the first line. Menu items for such
85messages also contain a filename and a line number. Selecting such a 85messages also contain a filename and a line number. Selecting such a
86menu item will automatically open the file and jump to the line with 86menu item will automatically open the file and jump to the line with
87error. 87error.
88 88
89Syntax check is done 'on-the-fly'. It is started whenever 89Syntax check is done 'on-the-fly'. It is started whenever
90 90
91@itemize @bullet 91@itemize @bullet
92@item buffer is loaded 92@item buffer is loaded
@@ -97,7 +97,7 @@ delay is configurable).
97 97
98Flymake is a universal syntax checker in the sense that it's easily 98Flymake is a universal syntax checker in the sense that it's easily
99extended to support new syntax check tools and error message 99extended to support new syntax check tools and error message
100patterns. @xref{Configuring Flymake}. 100patterns. @xref{Configuring Flymake}.
101 101
102@node Installing Flymake 102@node Installing Flymake
103@chapter Installing 103@chapter Installing
@@ -107,7 +107,7 @@ patterns. @xref{Configuring Flymake}.
107Flymake is packaged in a single file, @code{flymake.el}. 107Flymake is packaged in a single file, @code{flymake.el}.
108 108
109To install/update Flymake, place @code{flymake.el} to a directory 109To install/update Flymake, place @code{flymake.el} to a directory
110somewhere on Emacs load path. You might also want to byte-compile 110somewhere on Emacs load path. You might also want to byte-compile
111@code{flymake.el} to improve performance. 111@code{flymake.el} to improve performance.
112 112
113Also, place the following line in the @code{.emacs} file. 113Also, place the following line in the @code{.emacs} file.
@@ -141,13 +141,13 @@ You might also map the most frequently used Flymake functions, such as
141@section Flymake mode 141@section Flymake mode
142@cindex flymake-mode 142@cindex flymake-mode
143 143
144Flymake is an Emacs minor mode. To use Flymake, you 144Flymake is an Emacs minor mode. To use Flymake, you
145must first activate @code{flymake-mode} by using the 145must first activate @code{flymake-mode} by using the
146@code{flymake-mode} function. 146@code{flymake-mode} function.
147 147
148Instead of manually activating @code{flymake-mode}, you can configure 148Instead of manually activating @code{flymake-mode}, you can configure
149Flymake to automatically enable @code{flymake-mode} upon opening any 149Flymake to automatically enable @code{flymake-mode} upon opening any
150file for which syntax check is possible. To do so, place the following 150file for which syntax check is possible. To do so, place the following
151line in @code{.emacs}: 151line in @code{.emacs}:
152 152
153@lisp 153@lisp
@@ -159,9 +159,9 @@ line in @code{.emacs}:
159@cindex Manually starting the syntax check 159@cindex Manually starting the syntax check
160 160
161When @code{flymake-mode} is active, syntax check is started 161When @code{flymake-mode} is active, syntax check is started
162automatically on any of the three conditions mentioned above. Syntax 162automatically on any of the three conditions mentioned above. Syntax
163check can also be started manually by using the 163check can also be started manually by using the
164@code{flymake-start-syntax-check-for-current-buffer} function. This 164@code{flymake-start-syntax-check-for-current-buffer} function. This
165can be used, for example, when changes were made to some other buffer 165can be used, for example, when changes were made to some other buffer
166affecting the current buffer. 166affecting the current buffer.
167 167
@@ -171,7 +171,7 @@ affecting the current buffer.
171 171
172After syntax check is completed, lines for which at least one error or 172After syntax check is completed, lines for which at least one error or
173warning has been reported are highlighted, and total number of errors 173warning has been reported are highlighted, and total number of errors
174and warning is shown in the mode line. Use the following functions to 174and warning is shown in the mode line. Use the following functions to
175navigate the highlighted lines. 175navigate the highlighted lines.
176 176
177@multitable @columnfractions 0.25 0.75 177@multitable @columnfractions 0.25 0.75
@@ -184,7 +184,7 @@ navigate the highlighted lines.
184 184
185@end multitable 185@end multitable
186 186
187These functions treat erroneous lines as a linked list. Therefore, 187These functions treat erroneous lines as a linked list. Therefore,
188@code{flymake-goto-next-error} will go to the first erroneous line 188@code{flymake-goto-next-error} will go to the first erroneous line
189when invoked in the end of the buffer. 189when invoked in the end of the buffer.
190 190
@@ -193,7 +193,7 @@ when invoked in the end of the buffer.
193@cindex Viewing error messages 193@cindex Viewing error messages
194 194
195To view error messages belonging to the current line, use the 195To view error messages belonging to the current line, use the
196@code{flymake-display-err-menu-for-current-line} function. If there's 196@code{flymake-display-err-menu-for-current-line} function. If there's
197at least one error or warning reported for the current line, this 197at least one error or warning reported for the current line, this
198function will display a popup menu with error/warning texts. 198function will display a popup menu with error/warning texts.
199Selecting the menu item whose error belongs to another file brings 199Selecting the menu item whose error belongs to another file brings
@@ -209,12 +209,12 @@ The following statuses are defined.
209 209
210@multitable @columnfractions 0.25 0.75 210@multitable @columnfractions 0.25 0.75
211@item Flymake* or Flymake:E/W* 211@item Flymake* or Flymake:E/W*
212@tab Flymake is currently running. For the second case, E/W contains the 212@tab Flymake is currently running. For the second case, E/W contains the
213error and warning count for the previous run. 213error and warning count for the previous run.
214 214
215@item Flymake 215@item Flymake
216@tab Syntax check is not running. Usually this means syntax check was 216@tab Syntax check is not running. Usually this means syntax check was
217successfully passed (no errors, no warnings). Other possibilities are: 217successfully passed (no errors, no warnings). Other possibilities are:
218syntax check was killed as a result of executing 218syntax check was killed as a result of executing
219@code{flymake-compile}, or syntax check cannot start as compilation 219@code{flymake-compile}, or syntax check cannot start as compilation
220is currently in progress. 220is currently in progress.
@@ -232,7 +232,7 @@ OFF for the buffer.
232@multitable @columnfractions 0.25 0.75 232@multitable @columnfractions 0.25 0.75
233@item CFGERR 233@item CFGERR
234@tab Syntax check process returned nonzero exit code, but no 234@tab Syntax check process returned nonzero exit code, but no
235errors/warnings were reported. This indicates a possible configuration 235errors/warnings were reported. This indicates a possible configuration
236error (for example, no suitable error message patterns for the 236error (for example, no suitable error message patterns for the
237syntax check tool). 237syntax check tool).
238 238
@@ -253,12 +253,12 @@ syntax check tool).
253@cindex Troubleshooting 253@cindex Troubleshooting
254 254
255Flymake uses a simple logging facility for indicating important points 255Flymake uses a simple logging facility for indicating important points
256in the control flow. The logging facility sends logging messages to 256in the control flow. The logging facility sends logging messages to
257the @code{*Messages*} buffer. The information logged can be used for 257the @code{*Messages*} buffer. The information logged can be used for
258resolving various problems related to Flymake. 258resolving various problems related to Flymake.
259 259
260Logging output is controlled by the @code{flymake-log-level} 260Logging output is controlled by the @code{flymake-log-level}
261variable. @code{3} is the most verbose level, and @code{-1} switches 261variable. @code{3} is the most verbose level, and @code{-1} switches
262logging off. 262logging off.
263 263
264@node Configuring Flymake 264@node Configuring Flymake
@@ -286,30 +286,30 @@ Controls logging output, see @ref{Troubleshooting}.
286 286
287@item flymake-allowed-file-name-masks 287@item flymake-allowed-file-name-masks
288A list of @code{(filename-regexp, init-function, cleanup-function 288A list of @code{(filename-regexp, init-function, cleanup-function
289getfname-function)} for configuring syntax check tools. @xref{Adding 289getfname-function)} for configuring syntax check tools. @xref{Adding
290support for a new syntax check tool}. 290support for a new syntax check tool}.
291 291
292@ignore 292@ignore
293@item flymake-buildfile-dirs 293@item flymake-buildfile-dirs
294A list of directories (relative paths) for searching a 294A list of directories (relative paths) for searching a
295buildfile. @xref{Locating the buildfile}. 295buildfile. @xref{Locating the buildfile}.
296@end ignore 296@end ignore
297 297
298@item flymake-master-file-dirs 298@item flymake-master-file-dirs
299A list of directories for searching a master file. @xref{Locating a 299A list of directories for searching a master file. @xref{Locating a
300master file}. 300master file}.
301 301
302@item flymake-get-project-include-dirs-function 302@item flymake-get-project-include-dirs-function
303A function used for obtaining a list of project include dirs (C/C++ 303A function used for obtaining a list of project include dirs (C/C++
304specific). @xref{Getting the include directories}. 304specific). @xref{Getting the include directories}.
305 305
306@item flymake-master-file-count-limit 306@item flymake-master-file-count-limit
307@itemx flymake-check-file-limit 307@itemx flymake-check-file-limit
308Used when looking for a master file. @xref{Locating a master file}. 308Used when looking for a master file. @xref{Locating a master file}.
309 309
310@item flymake-err-line-patterns 310@item flymake-err-line-patterns
311Patterns for error/warning messages in the form @code{(regexp file-idx 311Patterns for error/warning messages in the form @code{(regexp file-idx
312line-idx col-idx err-text-idx)}. @xref{Parsing the output}. 312line-idx col-idx err-text-idx)}. @xref{Parsing the output}.
313 313
314@item flymake-compilation-prevents-syntax-check 314@item flymake-compilation-prevents-syntax-check
315A flag indicating whether compilation and syntax check of the same 315A flag indicating whether compilation and syntax check of the same
@@ -321,7 +321,7 @@ started after @code{flymake-no-changes-timeout} seconds.
321 321
322@item flymake-gui-warnings-enabled 322@item flymake-gui-warnings-enabled
323A boolean flag indicating whether Flymake will show message boxes for 323A boolean flag indicating whether Flymake will show message boxes for
324non-recoverable errors. If @code{flymake-gui-warnings-enabled} is 324non-recoverable errors. If @code{flymake-gui-warnings-enabled} is
325@code{nil}, these errors will only be logged to the @code{*Messages*} 325@code{nil}, these errors will only be logged to the @code{*Messages*}
326buffer. 326buffer.
327 327
@@ -360,7 +360,7 @@ Which fringe (if any) should show the warning/error bitmaps.
360@end menu 360@end menu
361 361
362Syntax check tools are configured using the 362Syntax check tools are configured using the
363@code{flymake-allowed-file-name-masks} list. Each item of this list 363@code{flymake-allowed-file-name-masks} list. Each item of this list
364has the following format: 364has the following format:
365 365
366@lisp 366@lisp
@@ -371,14 +371,14 @@ has the following format:
371@item filename-regexp 371@item filename-regexp
372This field is used as a key for locating init/cleanup/getfname 372This field is used as a key for locating init/cleanup/getfname
373functions for the buffer. Items in 373functions for the buffer. Items in
374@code{flymake-allowed-file-name-masks} are searched sequentially. The 374@code{flymake-allowed-file-name-masks} are searched sequentially. The
375first item with @code{filename-regexp} matching buffer filename is 375first item with @code{filename-regexp} matching buffer filename is
376selected. If no match is found, @code{flymake-mode} is switched off. 376selected. If no match is found, @code{flymake-mode} is switched off.
377 377
378@item init-function 378@item init-function
379@code{init-function} is required to initialize the syntax check, 379@code{init-function} is required to initialize the syntax check,
380usually by creating a temporary copy of the buffer contents. The 380usually by creating a temporary copy of the buffer contents. The
381function must return @code{(list cmd-name arg-list)}. If 381function must return @code{(list cmd-name arg-list)}. If
382@code{init-function} returns null, syntax check is aborted, by 382@code{init-function} returns null, syntax check is aborted, by
383@code{flymake-mode} is not switched off. 383@code{flymake-mode} is not switched off.
384 384
@@ -389,7 +389,7 @@ usually deleting a temporary copy created by the @code{init-function}.
389 389
390@item getfname-function 390@item getfname-function
391This function is used for translating filenames reported by the syntax 391This function is used for translating filenames reported by the syntax
392check tool into ``real'' filenames. Filenames reported by the tool 392check tool into ``real'' filenames. Filenames reported by the tool
393will be different from the real ones, as actually the tool works with 393will be different from the real ones, as actually the tool works with
394the temporary copy. In most cases, the default implementation 394the temporary copy. In most cases, the default implementation
395provided by Flymake, @code{flymake-get-real-file-name}, can be used as 395provided by Flymake, @code{flymake-get-real-file-name}, can be used as
@@ -411,7 +411,7 @@ support for various syntax check tools.
411@cindex Adding support for perl 411@cindex Adding support for perl
412 412
413In this example, we will add support for @code{perl} as a syntax check 413In this example, we will add support for @code{perl} as a syntax check
414tool. @code{perl} supports the @code{-c} option which does syntax 414tool. @code{perl} supports the @code{-c} option which does syntax
415checking. 415checking.
416 416
417First, we write the @code{init-function}: 417First, we write the @code{init-function}:
@@ -463,7 +463,7 @@ In this example we will add support for C files syntax checked by
463@command{gcc} called via @command{make}. 463@command{gcc} called via @command{make}.
464 464
465We're not required to write any new functions, as Flymake already has 465We're not required to write any new functions, as Flymake already has
466functions for @command{make}. We just add a new entry to the 466functions for @command{make}. We just add a new entry to the
467@code{flymake-allowed-file-name-masks}: 467@code{flymake-allowed-file-name-masks}:
468 468
469@lisp 469@lisp
@@ -489,7 +489,7 @@ command line:
489 489
490@code{base-dir} is a directory containing @code{Makefile}, see @ref{Locating the buildfile}. 490@code{base-dir} is a directory containing @code{Makefile}, see @ref{Locating the buildfile}.
491 491
492Thus, @code{Makefile} must contain the @code{check-syntax} target. In 492Thus, @code{Makefile} must contain the @code{check-syntax} target. In
493our case this target might look like this: 493our case this target might look like this:
494 494
495@verbatim 495@verbatim
@@ -527,12 +527,12 @@ check-syntax:
527 527
528Syntax check is started by calling @code{flymake-start-syntax-check-for-current-buffer}. 528Syntax check is started by calling @code{flymake-start-syntax-check-for-current-buffer}.
529Flymake first determines whether it is able to do syntax 529Flymake first determines whether it is able to do syntax
530check. It then saves a copy of the buffer in a temporary file in the 530check. It then saves a copy of the buffer in a temporary file in the
531buffer's directory (or in the system temp directory, for java 531buffer's directory (or in the system temp directory, for java
532files), creates a syntax check command and launches a process with 532files), creates a syntax check command and launches a process with
533this command. The output is parsed using a list of error message patterns, 533this command. The output is parsed using a list of error message patterns,
534and error information (file name, line number, type and text) is 534and error information (file name, line number, type and text) is
535saved. After the process has finished, Flymake highlights erroneous 535saved. After the process has finished, Flymake highlights erroneous
536lines in the buffer using the accumulated error information. 536lines in the buffer using the accumulated error information.
537 537
538@node Determining whether syntax check is possible 538@node Determining whether syntax check is possible
@@ -551,14 +551,14 @@ Two syntax check modes are distinguished:
551@item 551@item
552Buffer can be syntax checked in a standalone fashion, that is, the 552Buffer can be syntax checked in a standalone fashion, that is, the
553file (its temporary copy, in fact) can be passed over to the compiler to 553file (its temporary copy, in fact) can be passed over to the compiler to
554do the syntax check. Examples are C/C++ (.c, .cpp) and Java (.java) 554do the syntax check. Examples are C/C++ (.c, .cpp) and Java (.java)
555sources. 555sources.
556 556
557@item 557@item
558Buffer can be syntax checked, but additional file, called master file, 558Buffer can be syntax checked, but additional file, called master file,
559is required to perform this operation. A master file is a file that 559is required to perform this operation. A master file is a file that
560includes the current file, so that running a syntax check tool on it 560includes the current file, so that running a syntax check tool on it
561will also check syntax in the current file. Examples are C/C++ (.h, 561will also check syntax in the current file. Examples are C/C++ (.h,
562.hpp) headers. 562.hpp) headers.
563 563
564@end enumerate 564@end enumerate
@@ -579,7 +579,7 @@ copies, finding master files, etc.), as well as some tool-specific
579 579
580After the possibility of the syntax check has been determined, a 580After the possibility of the syntax check has been determined, a
581temporary copy of the current buffer is made so that the most recent 581temporary copy of the current buffer is made so that the most recent
582unsaved changes could be seen by the syntax check tool. Making a copy 582unsaved changes could be seen by the syntax check tool. Making a copy
583is quite straightforward in a standalone case (mode @code{1}), as it's 583is quite straightforward in a standalone case (mode @code{1}), as it's
584just saving buffer contents to a temporary file. 584just saving buffer contents to a temporary file.
585 585
@@ -595,11 +595,11 @@ name.
595Locating a master file is discussed in the following section. 595Locating a master file is discussed in the following section.
596 596
597Patching just changes all appropriate lines of the master file so that they 597Patching just changes all appropriate lines of the master file so that they
598use the new (temporary) name of the current file. For example, suppose current 598use the new (temporary) name of the current file. For example, suppose current
599file name is @code{file.h}, the master file is @code{file.cpp}, and 599file name is @code{file.h}, the master file is @code{file.cpp}, and
600it includes current file via @code{#include "file.h"}. Current file's copy 600it includes current file via @code{#include "file.h"}. Current file's copy
601is saved to file @code{file_flymake.h}, so the include line must be 601is saved to file @code{file_flymake.h}, so the include line must be
602changed to @code{#include "file_flymake.h"}. Finally, patched master file 602changed to @code{#include "file_flymake.h"}. Finally, patched master file
603is saved to @code{file_flymake_master.cpp}, and the last one is passed to 603is saved to @code{file_flymake_master.cpp}, and the last one is passed to
604the syntax check tool. 604the syntax check tool.
605 605
@@ -609,27 +609,27 @@ the syntax check tool.
609 609
610Master file is located in two steps. 610Master file is located in two steps.
611 611
612First, a list of possible master files is built. A simple name 612First, a list of possible master files is built. A simple name
613matching is used to find the files. For a C++ header @code{file.h}, 613matching is used to find the files. For a C++ header @code{file.h},
614Flymake searches for all @code{.cpp} files in the directories whose relative paths are 614Flymake searches for all @code{.cpp} files in the directories whose relative paths are
615stored in a customizable variable @code{flymake-master-file-dirs}, which 615stored in a customizable variable @code{flymake-master-file-dirs}, which
616usually contains something like @code{("." "./src")}. No more than 616usually contains something like @code{("." "./src")}. No more than
617@code{flymake-master-file-count-limit} entries is added to the master file 617@code{flymake-master-file-count-limit} entries is added to the master file
618list. The list is then sorted to move files with names @code{file.cpp} to 618list. The list is then sorted to move files with names @code{file.cpp} to
619the top. 619the top.
620 620
621Next, each master file in a list is checked to contain the appropriate 621Next, each master file in a list is checked to contain the appropriate
622include directives. No more than @code{flymake-check-file-limit} of each 622include directives. No more than @code{flymake-check-file-limit} of each
623file are parsed. 623file are parsed.
624 624
625For @code{file.h}, the include directives to look for are 625For @code{file.h}, the include directives to look for are
626@code{#include "file.h"}, @code{#include "../file.h"}, etc. Each 626@code{#include "file.h"}, @code{#include "../file.h"}, etc. Each
627include is checked against a list of include directories 627include is checked against a list of include directories
628(see @ref{Getting the include directories}) to be sure it points to the 628(see @ref{Getting the include directories}) to be sure it points to the
629correct @code{file.h}. 629correct @code{file.h}.
630 630
631First matching master file found stops the search. The master file is then 631First matching master file found stops the search. The master file is then
632patched and saved to disk. In case no master file is found, syntax check is 632patched and saved to disk. In case no master file is found, syntax check is
633aborted, and corresponding status (!) is reported in the mode line. 633aborted, and corresponding status (!) is reported in the mode line.
634 634
635@node Getting the include directories 635@node Getting the include directories
@@ -637,19 +637,19 @@ aborted, and corresponding status (!) is reported in the mode line.
637@cindex Include directories (C/C++ specific) 637@cindex Include directories (C/C++ specific)
638 638
639Two sets of include directories are distinguished: system include directories 639Two sets of include directories are distinguished: system include directories
640and project include directories. The former is just the contents of the 640and project include directories. The former is just the contents of the
641@code{INCLUDE} environment variable. The latter is not so easy to obtain, 641@code{INCLUDE} environment variable. The latter is not so easy to obtain,
642and the way it can be obtained can vary greatly for different projects. 642and the way it can be obtained can vary greatly for different projects.
643Therefore, a customizable variable 643Therefore, a customizable variable
644@code{flymake-get-project-include-dirs-function} is used to provide the 644@code{flymake-get-project-include-dirs-function} is used to provide the
645way to implement the desired behavior. 645way to implement the desired behavior.
646 646
647The default implementation, @code{flymake-get-project-include-dirs-imp}, 647The default implementation, @code{flymake-get-project-include-dirs-imp},
648uses a @command{make} call. This requires a correct base directory, that is, a 648uses a @command{make} call. This requires a correct base directory, that is, a
649directory containing a correct @file{Makefile}, to be determined. 649directory containing a correct @file{Makefile}, to be determined.
650 650
651As obtaining the project include directories might be a costly operation, its 651As obtaining the project include directories might be a costly operation, its
652return value is cached in the hash table. The cache is cleared in the beginning 652return value is cached in the hash table. The cache is cleared in the beginning
653of every syntax check attempt. 653of every syntax check attempt.
654 654
655@node Locating the buildfile 655@node Locating the buildfile
@@ -659,18 +659,18 @@ of every syntax check attempt.
659@cindex Makefile, locating 659@cindex Makefile, locating
660 660
661Flymake can be configured to use different tools for performing syntax 661Flymake can be configured to use different tools for performing syntax
662checks. For example, it can use direct compiler call to syntax check a perl 662checks. For example, it can use direct compiler call to syntax check a perl
663script or a call to @command{make} for a more complicated case of a 663script or a call to @command{make} for a more complicated case of a
664@code{C/C++} source. The general idea is that simple files, like perl 664@code{C/C++} source. The general idea is that simple files, like perl
665scripts and html pages, can be checked by directly invoking a 665scripts and html pages, can be checked by directly invoking a
666corresponding tool. Files that are usually more complex and generally 666corresponding tool. Files that are usually more complex and generally
667used as part of larger projects, might require non-trivial options to 667used as part of larger projects, might require non-trivial options to
668be passed to the syntax check tool, like include directories for 668be passed to the syntax check tool, like include directories for
669C++. The latter files are syntax checked using some build tool, like 669C++. The latter files are syntax checked using some build tool, like
670Make or Ant. 670Make or Ant.
671 671
672All Make configuration data is usually stored in a file called 672All Make configuration data is usually stored in a file called
673@code{Makefile}. To allow for future extensions, flymake uses a notion of 673@code{Makefile}. To allow for future extensions, flymake uses a notion of
674buildfile to reference the 'project configuration' file. 674buildfile to reference the 'project configuration' file.
675 675
676Special function, @code{flymake-find-buildfile} is provided for locating buildfiles. 676Special function, @code{flymake-find-buildfile} is provided for locating buildfiles.
@@ -679,7 +679,7 @@ for possible master files.
679@ignore 679@ignore
680A customizable variable 680A customizable variable
681@code{flymake-buildfile-dirs} holds a list of relative paths to the 681@code{flymake-buildfile-dirs} holds a list of relative paths to the
682buildfile. They are checked sequentially until a buildfile is found. 682buildfile. They are checked sequentially until a buildfile is found.
683@end ignore 683@end ignore
684In case there's no build file, syntax check is aborted. 684In case there's no build file, syntax check is aborted.
685 685
@@ -690,7 +690,7 @@ Buildfile values are also cached.
690@cindex Syntax check process 690@cindex Syntax check process
691 691
692The command line (command name and the list of arguments) for launching a process is returned by the 692The command line (command name and the list of arguments) for launching a process is returned by the
693initialization function. Flymake then just calls @code{start-process} 693initialization function. Flymake then just calls @code{start-process}
694to start an asynchronous process and configures process filter and 694to start an asynchronous process and configures process filter and
695sentinel which is used for processing the output of the syntax check 695sentinel which is used for processing the output of the syntax check
696tool. 696tool.
@@ -701,24 +701,24 @@ tool.
701 701
702The output generated by the syntax check tool is parsed in the process 702The output generated by the syntax check tool is parsed in the process
703filter/sentinel using the error message patterns stored in the 703filter/sentinel using the error message patterns stored in the
704@code{flymake-err-line-patterns} variable. This variable contains a 704@code{flymake-err-line-patterns} variable. This variable contains a
705list of items of the form @code{(regexp file-idx line-idx 705list of items of the form @code{(regexp file-idx line-idx
706err-text-idx)}, used to determine whether a particular line is an 706err-text-idx)}, used to determine whether a particular line is an
707error message and extract file name, line number and error text, 707error message and extract file name, line number and error text,
708respectively. Error type (error/warning) is also guessed by matching 708respectively. Error type (error/warning) is also guessed by matching
709error text with the '@code{^[wW]arning}' pattern. Anything that was not 709error text with the '@code{^[wW]arning}' pattern. Anything that was not
710classified as a warning is considered an error. Type is then used to 710classified as a warning is considered an error. Type is then used to
711sort error menu items, which shows error messages first. 711sort error menu items, which shows error messages first.
712 712
713Flymake is also able to interpret error message patterns missing err-text-idx 713Flymake is also able to interpret error message patterns missing err-text-idx
714information. This is done by merely taking the rest of the matched line 714information. This is done by merely taking the rest of the matched line
715(@code{(substring line (match-end 0))}) as error text. This trick allows 715(@code{(substring line (match-end 0))}) as error text. This trick allows
716to make use of a huge collection of error message line patterns from 716to make use of a huge collection of error message line patterns from
717@code{compile.el}. All these error patterns are appended to 717@code{compile.el}. All these error patterns are appended to
718the end of @code{flymake-err-line-patterns}. 718the end of @code{flymake-err-line-patterns}.
719 719
720The error information obtained is saved in a buffer local 720The error information obtained is saved in a buffer local
721variable. The buffer for which the process output belongs is 721variable. The buffer for which the process output belongs is
722determined from the process-id@w{}->@w{}buffer mapping updated 722determined from the process-id@w{}->@w{}buffer mapping updated
723after every process launch/exit. 723after every process launch/exit.
724 724
@@ -727,7 +727,7 @@ after every process launch/exit.
727@cindex Erroneous lines, faces 727@cindex Erroneous lines, faces
728 728
729Highlighting is implemented with overlays and happens in the process 729Highlighting is implemented with overlays and happens in the process
730sentinel, after calling the cleanup function. Two customizable faces 730sentinel, after calling the cleanup function. Two customizable faces
731are used: @code{flymake-errline} and 731are used: @code{flymake-errline} and
732@code{flymake-warnline}. Errors belonging outside the current 732@code{flymake-warnline}. Errors belonging outside the current
733buffer are considered to belong to line 1 of the current buffer. 733buffer are considered to belong to line 1 of the current buffer.
@@ -749,12 +749,13 @@ and @code{flymake-warning-bitmap}.
749The only mode flymake currently knows about is @code{compile}. 749The only mode flymake currently knows about is @code{compile}.
750 750
751Flymake can be configured to not start syntax check if it thinks the 751Flymake can be configured to not start syntax check if it thinks the
752compilation is in progress. The check is made by the 752compilation is in progress. The check is made by the
753@code{flymake-compilation-is-running}, which tests the 753@code{flymake-compilation-is-running}, which tests the
754@code{compilation-in-progress} variable. The reason why this might be 754@code{compilation-in-progress} variable. The reason why this might be
755useful is saving CPU time in case both syntax check and compilation 755useful is saving CPU time in case both syntax check and compilation
756are very CPU intensive. The original reason for adding this feature, 756are very CPU intensive. The original reason for adding this feature,
757though, was working around a locking problem with MS Visual C++ compiler. 757though, was working around a locking problem with MS Visual C++
758compiler.
758 759
759Flymake also provides an alternative command for starting compilation, 760Flymake also provides an alternative command for starting compilation,
760@code{flymake-compile}: 761@code{flymake-compile}:
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index e12652e7cbd..3cb0535ce5e 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,15 @@
12013-05-25 Xue Fuqiao <xfq.free@gmail.com>
2
3 * progmodes/flymake.el (flymake-save-buffer-in-file)
4 (flymake-makehash, flymake-posn-at-point-as-event, flymake-nop)
5 (flymake-selected-frame, flymake-log, flymake-ins-after)
6 (flymake-set-at, flymake-get-buildfile-from-cache)
7 (flymake-add-buildfile-to-cache, flymake-clear-buildfile-cache)
8 (flymake-find-possible-master-files, flymake-save-buffer-in-file):
9 Refine the doc string.
10 (flymake-get-file-name-mode-and-masks): Reformat.
11 (flymake-get-real-file-name-function): Fix a minor bug.
12
12013-05-24 Juri Linkov <juri@jurta.org> 132013-05-24 Juri Linkov <juri@jurta.org>
2 14
3 * progmodes/grep.el (grep-mode-font-lock-keywords): 15 * progmodes/grep.el (grep-mode-font-lock-keywords):
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index 79bccd138ee..aed62b27450 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -1,4 +1,4 @@
1;;; flymake.el -- a universal on-the-fly syntax checker 1;;; flymake.el --- a universal on-the-fly syntax checker
2 2
3;; Copyright (C) 2003-2013 Free Software Foundation, Inc. 3;; Copyright (C) 2003-2013 Free Software Foundation, Inc.
4 4
@@ -68,6 +68,9 @@
68 68
69;;;; [[ cross-emacs compatibility routines 69;;;; [[ cross-emacs compatibility routines
70(defsubst flymake-makehash (&optional test) 70(defsubst flymake-makehash (&optional test)
71 "Create and return a new hash table using TEST to compare keys.
72It uses the function `make-hash-table' to make a hash-table if
73you use GNU Emacs, otherwise it uses `makehash'."
71 (if (fboundp 'make-hash-table) 74 (if (fboundp 'make-hash-table)
72 (if test (make-hash-table :test test) (make-hash-table)) 75 (if test (make-hash-table :test test) (make-hash-table))
73 (with-no-warnings 76 (with-no-warnings
@@ -106,10 +109,12 @@ Zero-length substrings at the beginning and end of the list are omitted."
106 (lambda () temporary-file-directory))) 109 (lambda () temporary-file-directory)))
107 110
108(defun flymake-posn-at-point-as-event (&optional position window dx dy) 111(defun flymake-posn-at-point-as-event (&optional position window dx dy)
109 "Return pixel position of top left corner of glyph at POSITION, 112 "Return pixel position of top left corner of glyph at POSITION.
110relative to top left corner of WINDOW, as a mouse-1 click 113
111event (identical to the event that would be triggered by clicking 114The position is relative to top left corner of WINDOW, as a
112mouse button 1 at the top left corner of the glyph). 115mouse-1 click event (identical to the event that would be
116triggered by clicking mouse button 1 at the top left corner of
117the glyph).
113 118
114POSITION and WINDOW default to the position of point in the 119POSITION and WINDOW default to the position of point in the
115selected window. 120selected window.
@@ -164,7 +169,8 @@ See `x-popup-menu' for the menu specifier format."
164 169
165(if (featurep 'xemacs) (progn 170(if (featurep 'xemacs) (progn
166 171
167(defun flymake-nop ()) 172(defun flymake-nop ()
173 "Do nothing.")
168 174
169(defun flymake-make-xemacs-menu (menu-data) 175(defun flymake-make-xemacs-menu (menu-data)
170 "Return a menu specifier using MENU-DATA." 176 "Return a menu specifier using MENU-DATA."
@@ -187,6 +193,7 @@ See `x-popup-menu' for the menu specifier format."
187 (count-lines (window-start) (point)))) 193 (count-lines (window-start) (point))))
188 194
189(defun flymake-selected-frame () 195(defun flymake-selected-frame ()
196 "Return the frame that is now selected."
190 (if (fboundp 'window-edges) 197 (if (fboundp 'window-edges)
191 (selected-frame) 198 (selected-frame)
192 (selected-window))) 199 (selected-window)))
@@ -217,31 +224,42 @@ See `x-popup-menu' for the menu specifier format."
217 :group 'flymake 224 :group 'flymake
218 :type 'integer) 225 :type 'integer)
219 226
227
228;; (defcustom flymake-log-file-name "~/flymake.log"
229;; "Where to put the flymake log if logging is enabled.
230;;
231;; See `flymake-log-level' if you want to control what is logged."
232;; :group 'flymake
233;; :type 'string)
234
220(defun flymake-log (level text &rest args) 235(defun flymake-log (level text &rest args)
221 "Log a message at level LEVEL. 236 "Log a message at level LEVEL.
222If LEVEL is higher than `flymake-log-level', the message is 237If LEVEL is higher than `flymake-log-level', the message is
223ignored. Otherwise, it is printed using `message'. 238ignored. Otherwise, it is printed using `message'.
224TEXT is a format control string, and the remaining arguments ARGS 239TEXT is a format control string, and the remaining arguments ARGS
225are the string substitutions (see `format')." 240are the string substitutions (see the function `format')."
226 (if (<= level flymake-log-level) 241 (if (<= level flymake-log-level)
227 (let* ((msg (apply 'format text args))) 242 (let* ((msg (apply 'format text args)))
228 (message "%s" msg) 243 (message "%s" msg)
229 ;;(with-temp-buffer 244 ;;(with-temp-buffer
230 ;; (insert msg) 245 ;; (insert msg)
231 ;; (insert "\n") 246 ;; (insert "\n")
232 ;; (flymake-save-buffer-in-file "d:/flymake.log" t) ; make log file name customizable 247 ;; (flymake-save-buffer-in-file "~/flymake.log") ; make log file name customizable
233 ;;) 248 ;;)
234 ))) 249 )))
235 250
236(defun flymake-ins-after (list pos val) 251(defun flymake-ins-after (list pos val)
237 "Insert VAL into LIST after position POS." 252 "Insert VAL into LIST after position POS.
238 (let ((tmp (copy-sequence list))) ; (???) 253POS counts from zero."
254 (let ((tmp (copy-sequence list))) ; Bind `tmp' to a copy of LIST
239 (setcdr (nthcdr pos tmp) (cons val (nthcdr (1+ pos) tmp))) 255 (setcdr (nthcdr pos tmp) (cons val (nthcdr (1+ pos) tmp)))
240 tmp)) 256 tmp))
241 257
242(defun flymake-set-at (list pos val) 258(defun flymake-set-at (list pos val)
243 "Set VAL at position POS in LIST." 259)
244 (let ((tmp (copy-sequence list))) ; (???) 260"Set VAL at position POS in LIST.
261POS counts from zero."
262(let ((tmp (copy-sequence list))) ; Bind `tmp' to a copy of LIST
245 (setcar (nthcdr pos tmp) val) 263 (setcar (nthcdr pos tmp) val)
246 tmp)) 264 tmp))
247 265
@@ -249,7 +267,6 @@ are the string substitutions (see `format')."
249 "List of currently active flymake processes.") 267 "List of currently active flymake processes.")
250 268
251(defvar flymake-output-residual nil) 269(defvar flymake-output-residual nil)
252
253(make-variable-buffer-local 'flymake-output-residual) 270(make-variable-buffer-local 'flymake-output-residual)
254 271
255(defgroup flymake nil 272(defgroup flymake nil
@@ -310,7 +327,7 @@ NAME is the file name function to use, default `flymake-get-real-file-name'."
310 (unless (stringp file-name) 327 (unless (stringp file-name)
311 (error "Invalid file-name")) 328 (error "Invalid file-name"))
312 (let ((fnm flymake-allowed-file-name-masks) 329 (let ((fnm flymake-allowed-file-name-masks)
313 (mode-and-masks nil)) 330 (mode-and-masks nil))
314 (while (and (not mode-and-masks) fnm) 331 (while (and (not mode-and-masks) fnm)
315 (if (string-match (car (car fnm)) file-name) 332 (if (string-match (car (car fnm)) file-name)
316 (setq mode-and-masks (cdr (car fnm)))) 333 (setq mode-and-masks (cdr (car fnm))))
@@ -336,18 +353,22 @@ Return nil if we cannot, non-nil if we can."
336 'flymake-simple-cleanup)) 353 'flymake-simple-cleanup))
337 354
338(defun flymake-get-real-file-name-function (file-name) 355(defun flymake-get-real-file-name-function (file-name)
339 (or (nth 2 (flymake-get-file-name-mode-and-masks file-name)) 356 (or (nth 4 (flymake-get-file-name-mode-and-masks file-name))
340 'flymake-get-real-file-name)) 357 'flymake-get-real-file-name))
341 358
342(defvar flymake-find-buildfile-cache (flymake-makehash 'equal)) 359(defvar flymake-find-buildfile-cache (flymake-makehash 'equal))
343 360
344(defun flymake-get-buildfile-from-cache (dir-name) 361(defun flymake-get-buildfile-from-cache (dir-name)
362 "Look up DIR-NAME in cache and return its associated value.
363If DIR-NAME is not found, return nil."
345 (gethash dir-name flymake-find-buildfile-cache)) 364 (gethash dir-name flymake-find-buildfile-cache))
346 365
347(defun flymake-add-buildfile-to-cache (dir-name buildfile) 366(defun flymake-add-buildfile-to-cache (dir-name buildfile)
367 "Associate DIR-NAME with BUILDFILE in the buildfile cache."
348 (puthash dir-name buildfile flymake-find-buildfile-cache)) 368 (puthash dir-name buildfile flymake-find-buildfile-cache))
349 369
350(defun flymake-clear-buildfile-cache () 370(defun flymake-clear-buildfile-cache ()
371 "Clear the buildfile cache."
351 (clrhash flymake-find-buildfile-cache)) 372 (clrhash flymake-find-buildfile-cache))
352 373
353(defun flymake-find-buildfile (buildfile-name source-dir-name) 374(defun flymake-find-buildfile (buildfile-name source-dir-name)
@@ -394,9 +415,11 @@ Return t if so, nil if not."
394 415
395(defun flymake-find-possible-master-files (file-name master-file-dirs masks) 416(defun flymake-find-possible-master-files (file-name master-file-dirs masks)
396 "Find (by name and location) all possible master files. 417 "Find (by name and location) all possible master files.
397Master files include .cpp and .c for .h. Files are searched for 418
398starting from the .h directory and max max-level parent dirs. 419Name is specified by FILE-NAME and location is specified by
399File contents are not checked." 420MASTER-FILE-DIRS. Master files include .cpp and .c for .h.
421Files are searched for starting from the .h directory and max
422max-level parent dirs. File contents are not checked."
400 (let* ((dirs master-file-dirs) 423 (let* ((dirs master-file-dirs)
401 (files nil) 424 (files nil)
402 (done nil)) 425 (done nil))
@@ -593,6 +616,8 @@ Find master file, patch and save it."
593 nil)))) 616 nil))))
594 617
595(defun flymake-save-buffer-in-file (file-name) 618(defun flymake-save-buffer-in-file (file-name)
619 "Save the entire buffer contents into file FILE-NAME.
620Create parent directories as needed."
596 (make-directory (file-name-directory file-name) 1) 621 (make-directory (file-name-directory file-name) 1)
597 (write-region nil nil file-name nil 566) 622 (write-region nil nil file-name nil 566)
598 (flymake-log 3 "saved buffer %s in file %s" (buffer-name) file-name)) 623 (flymake-log 3 "saved buffer %s in file %s" (buffer-name) file-name))