2.2.1 Flymake utility functions

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

Function: flymake-make-diagnostic locus beg end type text &optional data

Make a Flymake diagnostic for the region of text in locus’s delimited by beg and end. type is a diagnostic symbol (see Customizing Flymake error types), and text is a description of the problem detected in this region. Most commonly locus is the buffer object designating for the current buffer being syntax-checked. However, it may be a string naming a file relative to the current working directory. See Foreign and list-only diagnostics, for when this may be useful. Depending on the type of locus, beg and end are both either buffer positions or conses (line . col) which specify the line and column of the diagnostic’s start and end positions, respectively.

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

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. This function saves match data (see Saving Match Data in The Emacs Lisp Reference Manual).

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

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 in The Emacs Lisp reference Manual), which is used to display the warning in Flymake’s log buffer.