     [file docstyle.texi not included]

GNU Flymake
***********

This manual is for GNU Flymake (version 0.3, April 2004), which is a universal on-the-fly syntax checker for GNU Emacs.

Copyright © 2004--2018 Free Software Foundation, Inc.

     Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,'' and with the Back-Cover Texts as in (a) below.  A copy of the license is included in the section entitled ``GNU Free Documentation License''.

     (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and modify this GNU manual.''

Using Flymake
*************

Flymake is a universal on-the-fly buffer checker implemented as an Emacs minor mode.  To use Flymake, you must first activate flymake-mode by using the command flymake-mode.

When enabled, Flymake collects information about problems in the buffer, called diagnostics, from one or more different sources, or backends, and then visually annotates the buffer by highlighting problematic buffer regions with a special face.

It also displays an overall buffer status in the mode line containing totals for different types of diagnostics.

Syntax check is done ``on-the-fly''.  It is started whenever

  * flymake-mode is started, unless flymake-start-on-flymake-mode is nil;

  * a newline character is added to the buffer, unless flymake-start-syntax-check-on-newline is nil;

  * some changes were made to the buffer more than 0.5 seconds ago (the delay is configurable in flymake-no-changes-timeout).

Syntax check can also be started manually by typing the M-x flymake-start RET command.

flymake-goto-next-error and flymake-goto-prev-error are commands that allow easy navigation to the next/previous erroneous line, respectively.  If might be a good idea to map them to M-n and M-p in flymake-mode, by adding to your init file:

     (define-key flymake-mode-map (kbd "M-n") 'flymake-goto-next-error)
     (define-key flymake-mode-map (kbd "M-p") 'flymake-goto-prev-error)

Flymake is a universal syntax checker in the sense that it's easily extended to support new backends (see Extending Flymake).

Historically, Flymake used to accept diagnostics from a single backend, albeit a reasonably flexible one.

This backend isn't (yet) obsolete, and so is still available as a fallback and active by default (see The legacy Proc backend).  It works by selecting a syntax check tool from a preconfigured list (compiler for C++ files, perl for Perl files, etc.), and executing it in the background, passing it a temporary file which is a copy of the current buffer, and parsing the output for known error/warning message patterns.

Syntax check statuses
=====================

When enabled, Flymake displays its status in the mode line, which provides a visual summary of diagnostic collection.  It may also hint at certain exceptional situations encountered when communicating with backends.

The following statuses are defined:

[NERRORS NWARNINGS ...]
Normal operation. NERRORS and NWARNINGS are, respectively,
the total number of errors and warnings found during the last buffer
check, for all backends. They may be followed by other totals for
other types of diagnostics (see Flymake error types).

Wait
Some Flymake backends haven't reported since the last time they
where questioned.  It is reasonable to assume that this is a temporary
delay and Flymake will resume normal operation soon.

!
All the configured Flymake backends have disabled themselves: Flymake
cannot annotate the buffer and action from the user is needed to
investigate and remedy the situation (see Backend exceptions).

?
There are no applicable Flymake backends for this buffer, thus Flymake
cannot annotate it.  To fix this, a user may look to extending Flymake
and add a new backend (see Extending Flymake).

Backend exceptions
==================

Some backends may take longer than others to respond or complete, and some may decide to disable themselves if they are not suitable for the current buffer or encounter some unavoidable problem.  A disabled backend is not tried again for future checks of the current buffer.

The commands flymake-reporting-backends, flymake-running-backends and flymake-disabled-backends show the backends currently used and those which are disabled.

Toggling flymake-mode off and on again, or invoking flymake-start with a prefix argument is one way to reset the disabled backend list, so that they will be tried again in the next check.

Flymake also uses a simple logging facility for indicating important points in the control flow.  The logging facility sends logging messages to the *Flymake log* buffer.  The information logged can be used for resolving various problems related to Flymake.  For convenience, a shortcut to this buffer can be found in Flymake's menu, accessible from the top menu bar or just left of the status indicator.

Logging output is controlled by the Emacs warning-minimum-log-level and warning-minimum-level variables.

Customizable variables
======================

This section summarizes customization variables used for the configuration of the Flymake user interface.

flymake-no-changes-timeout
     If any changes are made to the buffer, syntax check is automatically started after this many seconds, unless the user makes another change, which resets the timer.

flymake-start-syntax-check-on-newline
     A boolean flag indicating whether to start syntax check immediately after a newline character is inserted into the buffer.

flymake-start-on-flymake-mode
     A boolean flag indicating whether to start syntax check immediately after enabling flymake-mode.

flymake-error
     A custom face for highlighting regions for which an error has been reported.

flymake-warning
     A custom face for highlighting regions for which a warning has been reported.

flymake-note
     A custom face for highlighting regions for which a note has been reported.

flymake-error-bitmap
     A bitmap used in the fringe to mark lines for which an error has been reported.

flymake-warning-bitmap
     A bitmap used in the fringe to mark lines for which a warning has been reported.

flymake-fringe-indicator-position
     Which fringe (if any) should show the warning/error bitmaps.

flymake-wrap-around
     If non-nil, moving to errors with flymake-goto-next-error and flymake-goto-prev-error wraps around buffer boundaries.

Extending Flymake
*****************

Flymake can primarily be extended in one of two ways:

 1. By changing the look and feel of the annotations produced by the different backends.

 2. By adding a new buffer-checking backend.

The following sections discuss each approach in detail.

Customizing Flymake error types
===============================

The variable flymake-diagnostic-types-alist is looked up by Flymake every time an annotation for a diagnostic is created in the buffer.  Specifically, this variable holds a table of correspondence between symbols designating diagnostic types and an additional sub-table of properties pertaining to each diagnostic type.

Both tables are laid out in association list (see Association Lists (The Emacs Lisp Reference Manual)) format, and thus can be conveniently accessed with the functions of the assoc family.

You can use any symbol-value association in the properties sub-table, but some symbols have special meaning as to where and how Flymake presents the diagnostic:

  * bitmap, an image displayed in the fringe according to flymake-fringe-indicator-position.  The value actually follows the syntax of flymake-error-bitmap (see Customizable variables).  It is overridden by any before-string overlay property.

  * severity is a non-negative integer specifying the diagnostic's severity.  The higher the value, the more serious is the error.  If the overlay property priority is not specified, severity is used to set it and help sort overlapping overlays.

  * Every property pertaining to overlays (see Overlay Properties (The Emacs Lisp Reference Manual)), except category and evaporate.  These properties are used to affect the appearance of Flymake annotations.

     As an example, here's how to make errors (diagnostics of the type :error) stand out even more prominently in the buffer, by raising the characters using a display overlay property.

          (push '(display . (raise 1.2))
                (cdr (assoc :error flymake-diagnostic-types-alist)))

  * flymake-category is a symbol whose property list is considered the default for missing values of any other properties.

Three default diagnostic types, :error, :warning and :note are predefined in flymake-diagnostic-types-alist.  By default each lists a single flymake-category property whose value is, respectively, the symbols flymake-error, flymake-warning and flymake-note.

These category symbols' plists is where the values of customizable variables and faces such as flymake-error-bitmap are found. Thus, if you change their plists, Flymake may stop honoring these user customizations.

The flymake-category special property is also especially useful for backends which create diagnostics objects with non-default types that differ from an existing type by only a few properties (see Flymake utility functions).

As an example, consider configuring a new diagnostic type :low-priority-note that behaves much like the :note priority but without an overlay face.

     (add-to-list
      'flymake-diagnostic-types-alist
      `(:low-priority-note . ((face . nil)
                              (flymake-category . flymake-note))))

As you might have guessed, Flymake's annotations are implemented as overlays (see Overlays (The Emacs Lisp Reference Manual)). Along with the properties that you specify for the specific type of diagnostic, Flymake adds the property flymake-diagnostic to these overlays, and sets it to the object that the backend created with flymake-make-diagnostic.

Since overlays also support arbitrary keymaps, you can use this along with the functions flymake-diagnostics and flymake-diagnostic-text (see Flymake utility functions) to create interactive annotations, such as in the following example of binding a mouse-3 event (middle mouse button click) to an Internet search for the text of a :warning or :error.

     (defun my-search-for-message (event)
       (interactive "e")
       (let* ((diags (flymake-diagnostics (posn-point (event-start event))))
              (topmost-diag (car diags)))
         (eww-browse-url
            (concat
             "https://duckduckgo.com/?q="
             (replace-regexp-in-string " "
                                       "+"
                                       (flymake-diagnostic-text topmost-diag)))
            t)))

     (dolist (type '(:warning :error))
       (let ((a (assoc type flymake-diagnostic-types-alist)))
         (setf (cdr a)
               (append `((mouse-face . highlight)
                         (keymap . ,(let ((map (make-sparse-keymap)))
                                      (define-key map [mouse-2]
                                        'my-search-for-message)
                                      map)))
                       (cdr a)))))

Backend functions
=================

Flymake backends are Lisp functions placed in the special hook flymake-diagnostic-functions.

A backend's responsibility is to diagnose the contents of a buffer for problems, registering the problem's positions, type, and summary description.  This information is collected in the form of diagnostic objects created by the function flymake-make-diagnostic (see Flymake utility functions), and then handed over to Flymake, which proceeds to annotate the buffer.

A request for a buffer check, and the subsequent delivery of diagnostics, are two key events of the interaction between Flymake and backend.  Each such event corresponds to a well-defined function calling convention: one for calls made by Flymake into the backend via the backend function, the other in the reverse direction via a callback.  To be usable, backends must adhere to both.

Backend functions must accept an arbitrary number of arguments:

  * the first argument is always REPORT-FN, a callback function detailed below;

  * the remaining arguments are keyword-value pairs of the form (:KEY VALUE :KEY2 VALUE2...).  Currently, Flymake provides no such arguments, but backend functions must be prepared to accept (and possibly ignore) any number of them.

Whenever Flymake or the user decide to re-check the buffer, backend functions are called as detailed above, and are expected to initiate this check, but aren't in any way required to complete it before exiting: if the computation involved is expensive, as is often the case with large buffers, that slower task should be scheduled for the future using asynchronous sub-processes (see Asynchronous Processes (The Emacs Lisp reference manual)) or other asynchronous mechanisms.

In any case, backend functions are expected to return quickly or signal an error, in which case the backend is disabled (see Backend exceptions).

If the function returns, Flymake considers the backend to be running.  If it has not done so already, the backend is expected to call the function REPORT-FN passed to it, at which point Flymake considers the backend to be reporting.  Backends call REPORT-FN by passing it a single argument REPORT-ACTION followed by an optional list of keyword-value pairs of the form (:REPORT-KEY VALUE :REPORT-KEY2 VALUE2...).

Currently accepted values for REPORT-ACTION are:

  * A (possibly empty) list of diagnostic objects created by flymake-make-diagnostic, causing Flymake to annotate the buffer with this information.

     A backend may call REPORT-FN repeatedly in this manner, but only until Flymake considers that the most recently requested buffer check is now obsolete, because, say, buffer contents have changed in the meantime.  The backend is only given notice of this via a renewed call to the backend function.  Thus, to prevent making obsolete reports and wasting resources, backend functions should first cancel any ongoing processing from previous calls.

  * The symbol :panic, signaling that the backend has encountered an exceptional situation and should be disabled.

Currently accepted REPORT-KEY arguments are:

  * :explanation, whose value should give user-readable details of the situation encountered, if any.

  * :force, whose value should be a boolean suggesting that Flymake consider the report even if it was somehow unexpected.

Flymake utility functions
-------------------------

Before delivering them to Flymake, backends create diagnostic objects by calling the function flymake-make-diagnostic.

 -- Function: flymake-make-diagnostic buffer beg end type text
     Make a Flymake diagnostic for BUFFER's region from BEG to END.  TYPE is a key to flymake-diagnostic-types-alist and TEXT is a description of the problem detected in this region.

These objects' properties can be accessed with the functions flymake-diagnostic-backend, flymake-diagnostic-buffer, flymake-diagnostic-text, flymake-diagnostic-beg, flymake-diagnostic-end and flymake-diagnostic-type.

Additionally, the function flymake-diagnostics will collect such objects in the region you specify.

 -- Function: flymake-diagnostics beg end
     Get a list of Flymake diagnostics in the region determined by BEG and END.  If neither BEG or END is supplied, use the whole buffer, otherwise if BEG is non-nil and END is nil, consider only diagnostics at BEG.

It is often the case with external syntax tools that a diagnostic's position is reported in terms of a line number, and sometimes a column number.  To convert this information into a buffer position, backends can use the following function:

 -- Function: flymake-diag-region buffer line &optional col
     Compute BUFFER's region (BEG .  END) corresponding to LINE and COL.  If COL is nil, return a region just for LINE.  Return nil if the region is invalid.

For troubleshooting purposes, backends may record arbitrary exceptional or erroneous situations into the Flymake log buffer (see Backend exceptions):

 -- Macro: flymake-log level msg &optional args
     Log, at level LEVEL, the message MSG formatted with ARGS.  LEVEL is passed to display-warning (see Warning Basics (The Emacs Lisp reference Manual)), which is used to display the warning in Flymake's log buffer.

An annotated example backend
----------------------------

This section presents an annotated example of a complete working Flymake backend.  The example illustrates the process of writing a backend as outlined above.

The backend in question is used for checking Ruby source files.  It uses asynchronous sub-processes (see Asynchronous Processes (The Emacs Lisp Reference Manual)), a common technique for performing parallel processing in Emacs.

The following code needs lexical binding (see Using Lexical Binding (The Emacs Lisp Reference Manual)) to be active.

     ;;; ruby-flymake.el --- A ruby Flymake backend  -*- lexical-binding: t; -*-
     (defvar-local ruby--flymake-proc nil)

     (defun ruby-flymake (report-fn &rest _args)
       ;; Not having a ruby interpreter is a serious problem which should cause
       ;; the backend to disable itself, so an error is signaled.
       ;;
       (unless (executable-find
                "ruby") (error "Cannot find a suitable ruby"))
       ;; If a live process launched in an earlier check was found, that
       ;; process is killed.  When that process's sentinel eventually runs,
       ;; it will notice its obsoletion, since it have since reset
       ;; `ruby-flymake-proc' to a different value
       ;;
       (when (process-live-p ruby--flymake-proc)
         (kill-process ruby--flymake-proc))

       ;; Save the current buffer, the narrowing restriction, remove any
       ;; narrowing restriction.
       ;;
       (let ((source (current-buffer)))
         (save-restriction
           (widen)
           ;; Reset the `ruby--flymake-proc' process to a new process
           ;; calling the ruby tool.
           ;;
           (setq
            ruby--flymake-proc
            (make-process
             :name "ruby-flymake" :noquery t :connection-type 'pipe
             ;; Make output go to a temporary buffer.
             ;;
             :buffer (generate-new-buffer " *ruby-flymake*")
             :command '("ruby" "-w" "-c")
             :sentinel
             (lambda (proc _event)
               ;; Check that the process has indeed exited, as it might
               ;; be simply suspended.
               ;;
               (when (eq 'exit (process-status proc))
                 (unwind-protect
                     ;; Only proceed if `proc' is the same as
                     ;; `ruby--flymake-proc', which indicates that
                     ;; `proc' is not an obsolete process.
                     ;;
                     (if (with-current-buffer source (eq proc ruby--flymake-proc))
                         (with-current-buffer (process-buffer proc)
                           (goto-char (point-min))
                           ;; Parse the output buffer for diagnostic's
                           ;; messages and locations, collect them in a list
                           ;; of objects, and call `report-fn'.
                           ;;
                           (cl-loop
                            while (search-forward-regexp
                                   "^\\(?:.*.rb\\|-\\):\\([0-9]+\\): \\(.*\\)$"
                                   nil t)
                            for msg = (match-string 2)
                            for (beg . end) = (flymake-diag-region
                                               source
                                               (string-to-number (match-string 1)))
                            for type = (if (string-match "^warning" msg)
                                           :warning
                                         :error)
                            collect (flymake-make-diagnostic source
                                                             beg
                                                             end
                                                             type
                                                             msg)
                            into diags
                            finally (funcall report-fn diags)))
                       (flymake-log :warning "Canceling obsolete check %s"
                                    proc))
                   ;; Cleanup the temporary buffer used to hold the
                   ;; check's output.
                   ;;
                   (kill-buffer (process-buffer proc)))))))
           ;; Send the buffer contents to the process's stdin, followed by
           ;; an EOF.
           ;;
           (process-send-region ruby--flymake-proc (point-min) (point-max))
           (process-send-eof ruby--flymake-proc))))

     (defun ruby-setup-flymake-backend ()
       (add-hook 'flymake-diagnostic-functions 'ruby-flymake nil t))

     (add-hook 'ruby-mode-hook 'ruby-setup-flymake-backend)

The legacy ``Proc'' backend
***************************

The backend flymake-proc-legacy-backend was originally designed to be extended for supporting new syntax check tools and error message patterns.  It is also controlled by its own set of customization variables

Customization variables for the Proc backend
============================================

flymake-proc-allowed-file-name-masks
     A list of (filename-regexp, init-function, cleanup-function getfname-function) for configuring syntax check tools.  See Adding support for a new syntax check tool.

flymake-proc-master-file-dirs
     A list of directories for searching a master file.  See Locating a master file.

flymake-proc-get-project-include-dirs-function
     A function used for obtaining a list of project include dirs (C/C++ specific).  See Getting the include directories.

flymake-proc-master-file-count-limit
flymake-proc-check-file-limit
     Used when looking for a master file.  See Locating a master file.

flymake-proc-err-line-patterns
     Patterns for error/warning messages in the form (regexp file-idx line-idx col-idx err-text-idx).  See Parsing the output.

flymake-proc-diagnostic-type-pred
     A function to classify a diagnostic text as particular type of error.  Should be a function taking an error text and returning one of the symbols indexing flymake-diagnostic-types-alist.  If non-nil is returned but there is no such symbol in that table, a warning is assumed.  If nil is returned, an error is assumed.  Can also be a regular expression that should match only warnings.  This variable replaces the old flymake-warning-re and flymake-warning-predicate.

flymake-proc-compilation-prevents-syntax-check
     A flag indicating whether compilation and syntax check of the same file cannot be run simultaneously.  See Interaction with other modes.

Adding support for a new syntax check tool
==========================================

Syntax check tools are configured using the flymake-proc-allowed-file-name-masks list.  Each item of this list has the following format:

     (filename-regexp, init-function, cleanup-function, getfname-function)

filename-regexp
     This field is used as a key for locating init/cleanup/getfname functions for the buffer.  Items in flymake-proc-allowed-file-name-masks are searched sequentially. The first item with filename-regexp matching buffer filename is selected.  If no match is found, flymake-mode is switched off.

init-function
     init-function is required to initialize the syntax check, usually by creating a temporary copy of the buffer contents.  The function must return (list cmd-name arg-list).  If init-function returns null, syntax check is aborted, but flymake-mode is not switched off.

cleanup-function
     cleanup-function is called after the syntax check process is complete and should take care of proper deinitialization, which is usually deleting a temporary copy created by the init-function.

getfname-function
     This function is used for translating filenames reported by the syntax check tool into ``real'' filenames.  Filenames reported by the tool will be different from the real ones, as actually the tool works with the temporary copy.  In most cases, the default implementation provided by Flymake, flymake-proc-get-real-file-name, can be used as getfname-function.

To add support for a new syntax check tool, write the corresponding init-function and, optionally, cleanup-function and getfname-function.  If the format of error messages reported by the new tool is not yet supported by Flymake, add a new entry to the flymake-proc-err-line-patterns list.

The following sections contain some examples of configuring Flymake support for various syntax check tools.

Example---Configuring a tool called directly
--------------------------------------------

In this example, we will add support for perl as a syntax check tool.  perl supports the -c option which does syntax checking.

First, we write the init-function:

     (defun flymake-proc-perl-init ()
       (let* ((temp-file (flymake-proc-init-create-temp-buffer-copy
                          'flymake-proc-create-temp-inplace))
              (local-file (file-relative-name
                           temp-file
                           (file-name-directory buffer-file-name))))
         (list "perl" (list "-wc " local-file))))

flymake-proc-perl-init creates a temporary copy of the buffer contents with the help of flymake-proc-init-create-temp-buffer-copy, and builds an appropriate command line.

Next, we add a new entry to the flymake-proc-allowed-file-name-masks:

     (setq flymake-proc-allowed-file-name-masks
           (cons '(".+\\.pl$"
                   flymake-proc-perl-init
                   flymake-proc-simple-cleanup
                   flymake-proc-get-real-file-name)
                 flymake-proc-allowed-file-name-masks))

Note that we use standard cleanup-function and getfname-function.

Finally, we add an entry to flymake-proc-err-line-patterns:

     (setq flymake-proc-err-line-patterns
           (cons '("\\(.*\\) at \\([^ \n]+\\) line \\([0-9]+\\)[,.\n]"
                   2 3 nil 1)
                 flymake-proc-err-line-patterns))

Example---Configuring a tool called via make
--------------------------------------------

In this example we will add support for C files syntax checked by gcc called via make.

We're not required to write any new functions, as Flymake already has functions for make.  We just add a new entry to the flymake-proc-allowed-file-name-masks:

     (setq flymake-proc-allowed-file-name-masks
           (cons '(".+\\.c$"
                   flymake-proc-simple-make-init
                   flymake-proc-simple-cleanup
                   flymake-proc-get-real-file-name)
                 flymake-proc-allowed-file-name-masks))

flymake-proc-simple-make-init builds the following make command line:

     (list "make"
           (list "-s" "-C"
                 base-dir
                 (concat "CHK_SOURCES=" source)
                 "SYNTAX_CHECK_MODE=1"
                 "check-syntax"))

base-dir is a directory containing the Makefile, see Locating the buildfile.

Thus, Makefile must contain the check-syntax target.  In our case this target might look like this:

check-syntax:
	gcc -o /dev/null -S ${CHK_SOURCES} || true

The format of error messages reported by gcc is already supported by Flymake, so we don't have to add a new entry to flymake-err-line-patterns.  Note that if you are using Automake, you may want to replace gcc with the standard Automake variable COMPILE:

check-syntax:
	$(COMPILE) -o /dev/null -S ${CHK_SOURCES} || true

Implementation overview
=======================

flymake-proc-legacy-backend saves a copy of the buffer in a temporary file in the buffer's directory (or in the system temporary directory, for Java files), creates a syntax check command and launches a process with this command.  The output is parsed using a list of error message patterns, and error information (file name, line number, type and text) is saved.  After the process has finished, Flymake highlights erroneous lines in the buffer using the accumulated error information.

Syntax check is considered possible if there's an entry in flymake-proc-allowed-file-name-masks matching buffer's filename and its init-function returns non-nil value.

Two syntax check modes are distinguished:

 1. Buffer can be syntax checked in a standalone fashion, that is, the file (its temporary copy, in fact) can be passed over to the compiler to do the syntax check.  Examples are C/C++ sources (.c, .cpp) and Java (.java).

 2. Buffer can be syntax checked, but additional file, called master file, is required to perform this operation.  A master file is a file that includes the current file, so that running a syntax check tool on it will also check syntax in the current file.  Examples are C/C++ headers (.h, .hpp).

These modes are handled inside init/cleanup/getfname functions, see Adding support for a new syntax check tool.

The Proc backend contains implementations of all functionality required to support different syntax check modes described above (making temporary copies, finding master files, etc.), as well as some tool-specific (routines for Make, Ant, etc.) code.

Making a temporary copy
=======================

After the possibility of the syntax check has been determined, a temporary copy of the current buffer is made so that the most recent unsaved changes could be seen by the syntax check tool.  Making a copy is quite straightforward in a standalone case (mode 1), as it's just saving buffer contents to a temporary file.

Things get trickier, however, when master file is involved, as it requires to

  * locate a master file

  * patch it to include the current file using its new (temporary) name.

Locating a master file is discussed in the following section.

Patching just changes all appropriate lines of the master file so that they use the new (temporary) name of the current file.  For example, suppose current file name is file.h, the master file is file.cpp, and it includes current file via #include "file.h".  Current file's copy is saved to file file_flymake.h, so the include line must be changed to #include "file_flymake.h".  Finally, patched master file is saved to file_flymake_master.cpp, and the last one is passed to the syntax check tool.

Locating a master file
======================

Master file is located in two steps.

First, a list of possible master files is built.  A simple name matching is used to find the files.  For a C++ header file.h, the Proc backend searches for all .cpp files in the directories whose relative paths are stored in a customizable variable flymake-proc-master-file-dirs, which usually contains something like ("." "./src").  No more than flymake-proc-master-file-count-limit entries is added to the master file list.  The list is then sorted to move files with names file.cpp to the top.

Next, each master file in a list is checked to contain the appropriate include directives.  No more than flymake-proc-check-file-limit of each file are parsed.

For file.h, the include directives to look for are #include "file.h", #include "../file.h", etc.  Each include is checked against a list of include directories (see Getting the include directories) to be sure it points to the correct file.h.

First matching master file found stops the search.  The master file is then patched and saved to disk.  In case no master file is found, syntax check is aborted, and corresponding status (!) is reported in the mode line. See Syntax check statuses.

Getting the include directories
===============================

Two sets of include directories are distinguished: system include directories and project include directories.  The former is just the contents of the INCLUDE environment variable.  The latter is not so easy to obtain, and the way it can be obtained can vary greatly for different projects. Therefore, a customizable variable flymake-proc-get-project-include-dirs-function is used to provide the way to implement the desired behavior.

The default implementation, flymake-proc-get-project-include-dirs-imp, uses a make call.  This requires a correct base directory, that is, a directory containing a correct Makefile, to be determined.

As obtaining the project include directories might be a costly operation, its return value is cached in the hash table.  The cache is cleared in the beginning of every syntax check attempt.

Locating the buildfile
======================

The Proc backend can be configured to use different tools for performing syntax checks.  For example, it can use direct compiler call to syntax check a perl script or a call to make for a more complicated case of a C/C++ source.  The general idea is that simple files, like Perl scripts and HTML pages, can be checked by directly invoking a corresponding tool.  Files that are usually more complex and generally used as part of larger projects, might require non-trivial options to be passed to the syntax check tool, like include directories for C++.  The latter files are syntax checked using some build tool, like Make or Ant.

All Make configuration data is usually stored in a file called Makefile.  To allow for future extensions, Flymake uses a notion of buildfile to reference the project configuration file.

Special function, flymake-proc-find-buildfile is provided for locating buildfiles. Searching for a buildfile is done in a manner similar to that of searching for possible master files. In case there's no build file, the syntax check is aborted.

Buildfile values are also cached.

Starting the syntax check process
=================================

The command line (command name and the list of arguments) for launching a process is returned by the initialization function.  The Proc backend then just starts an asynchronous process and configures a process filter and sentinel, which are used for processing the output of the syntax check tool.  When exiting Emacs, running processes will be killed without prompting the user.

Parsing the output
==================

The output generated by the syntax check tool is parsed in the process filter/sentinel using the error message patterns stored in the flymake-proc-err-line-patterns variable.  This variable contains a list of items of the form (regexp file-idx line-idx err-text-idx), used to determine whether a particular line is an error message and extract file name, line number and error text, respectively.  Error type (error/warning) is also guessed by matching error text with the ^[wW]arning pattern.  Anything that was not classified as a warning is considered an error.  Type is then used to sort error menu items, which shows error messages first.

The Proc backend is also able to interpret error message patterns missing err-text-idx information.  This is done by merely taking the rest of the matched line ((substring line (match-end 0))) as error text.  This trick allows making use of a huge collection of error message line patterns from compile.el.  All these error patterns are appended to the end of flymake-proc-err-line-patterns.

The error information obtained is saved in a buffer local variable.  The buffer for which the process output belongs is determined from the process-id->buffer mapping updated after every process launch/exit.

Interaction with other modes
============================

The only mode the Proc backend currently knows about is compile.

The Proc backend can be configured to not start syntax check if it thinks the compilation is in progress, by testing the compilation-in-progress variable.  The reason why this might be useful is saving CPU time in case both syntax check and compilation are very CPU intensive.  The original reason for adding this feature, though, was working around a locking problem with MS Visual C++ compiler.  The variable in question is flymake-proc-compilation-prevents-syntax-check.

The Proc backend also provides an alternative command for starting compilation, flymake-proc-compile.  It just kills all the active syntax check processes before calling compile.

GNU Free Documentation License
******************************

     [file doclicense.texi not included]