Next: , Up: Extending Flymake

2.1 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) 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:

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.

      `(:low-priority-note . ((face . nil)
                              (flymake-category . flymake-note))))

As you might have guessed, Flymake's annotations are implemented as overlays (see Overlays). 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)))
             (replace-regexp-in-string " "
                                       (flymake-diagnostic-text topmost-diag)))
     (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]
                       (cdr a)))))