2.1 Customizing Flymake error types

To customize the appearance of error types, the user must set properties on the symbols associated with each diagnostic type.

The three standard diagnostic keyword symbols – :error, :warning and :note – have pre-configured appearances. However a backend may define more (see Backend functions).

The following properties can be set:

Three default diagnostic types are predefined: :error, :warning, and :note. By default, each one of them has a flymake-category property whose value is, respectively, the category symbol flymake-error, flymake-warning and flymake-note.

These category symbols’ plist 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 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 :note, but without an overlay face.

(put :low-priority-note 'flymake-overlay-control '((face . nil)))
(put :low-priority-note 'flymake-category 'flymake-note)

As you might have guessed, Flymake’s annotations are implemented as overlays (see Overlays in 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)))
          " " "+" (flymake-diagnostic-text topmost-diag)))

(dolist (type '(:warning :error))
  (push '(mouse-face . highlight) (get type 'flymake-overlay-control))
  (push `(keymap . ,(let ((map (make-sparse-keymap)))
                      (define-key map [mouse-2]
        (get type 'flymake-overlay-control)))