Function: flymake-mode

flymake-mode is an autoloaded, interactive and byte-compiled function defined in flymake.el.gz.

Signature

(flymake-mode &optional ARG)

Documentation

Toggle Flymake mode on or off.

Flymake is an Emacs minor mode for on-the-fly syntax checking. Flymake collects diagnostic information from multiple sources, called backends, and visually annotates the buffer with the results.

Flymake performs these checks while the user is editing. The customization variables flymake-start-on-flymake-mode, flymake-no-changes-timeout determine the exact circumstances whereupon Flymake decides to initiate a check of the buffer.

The commands flymake-goto-next-error and flymake-goto-prev-error can be used to navigate among Flymake diagnostics annotated in the buffer.

By default, flymake-mode(var)/flymake-mode(fun) doesn't override the C-x ` (next-error) command, but if you're using Flymake a lot (and don't use the regular compilation mechanisms that often), it can be useful to put something like the following in your init file:

  (setq next-error-function 'flymake-goto-next-error)

The visual appearance of each type of diagnostic can be changed by setting properties flymake-overlay-control, flymake-bitmap and flymake-severity on the symbols of diagnostic types (like
:error, :warning and :note).

Activation or deactivation of backends used by Flymake in each buffer happens via the special hook flymake-diagnostic-functions.

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. The commands flymake-running-backends, flymake-disabled-backends and flymake-reporting-backends summarize the situation, as does the special *Flymake log* buffer.

This is a minor mode. If called interactively, toggle the Flymake mode mode. If the prefix argument is positive, enable the mode, and if it is zero or negative, disable the mode.

If called from Lisp, toggle the mode if ARG is toggle. Enable the mode if ARG is nil, omitted, or is a positive number. Disable the mode if ARG is a negative number.

To check whether the minor mode is enabled in the current buffer, evaluate the variable flymake-mode(var)/flymake-mode(fun).

The mode's hook is called both when the mode is enabled and when it is disabled.

Probably introduced at or before Emacs version 30.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/flymake.el.gz
;;;###autoload
(define-minor-mode flymake-mode
  "Toggle Flymake mode on or off.

Flymake is an Emacs minor mode for on-the-fly syntax checking.
Flymake collects diagnostic information from multiple sources,
called backends, and visually annotates the buffer with the
results.

Flymake performs these checks while the user is editing.
The customization variables `flymake-start-on-flymake-mode',
`flymake-no-changes-timeout' determine the exact circumstances
whereupon Flymake decides to initiate a check of the buffer.

The commands `flymake-goto-next-error' and
`flymake-goto-prev-error' can be used to navigate among Flymake
diagnostics annotated in the buffer.

By default, `flymake-mode' doesn't override the \\[next-error] command, but
if you're using Flymake a lot (and don't use the regular compilation
mechanisms that often), it can be useful to put something like
the following in your init file:

  (setq next-error-function \\='flymake-goto-next-error)

The visual appearance of each type of diagnostic can be changed
by setting properties `flymake-overlay-control', `flymake-bitmap'
and `flymake-severity' on the symbols of diagnostic types (like
`:error', `:warning' and `:note').

Activation or deactivation of backends used by Flymake in each
buffer happens via the special hook
`flymake-diagnostic-functions'.

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.  The commands
`flymake-running-backends', `flymake-disabled-backends' and
`flymake-reporting-backends' summarize the situation, as does the
special *Flymake log* buffer."  :group 'flymake :lighter
  flymake-mode-line-format :keymap flymake-mode-map
  (cond
   ;; Turning the mode ON.
   (flymake-mode
    (add-hook 'after-change-functions 'flymake-after-change-function nil t)
    (add-hook 'after-save-hook 'flymake-after-save-hook nil t)
    (add-hook 'kill-buffer-hook 'flymake-kill-buffer-hook nil t)
    (add-hook 'eldoc-documentation-functions 'flymake-eldoc-function t t)

    ;; Maybe auto-resize margins
    (when (and (eq flymake-indicator-type 'margins) flymake-autoresize-margins)
      (flymake--resize-margins))

    ;; We can't just `clrhash' `flymake--state': there may be in
    ;; in-transit requests from other backends if `flymake-mode' was
    ;; already active.  I.e. `flymake-mode' function should be as
    ;; idempotent as possible.  See bug#69809.
    (unless flymake--state (setq flymake--state (make-hash-table)))
    (setq flymake--recent-changes nil)
    (when flymake-start-on-flymake-mode (flymake-start t)))

   ;; Turning the mode OFF.
   (t
    (remove-hook 'after-change-functions 'flymake-after-change-function t)
    (remove-hook 'after-save-hook 'flymake-after-save-hook t)
    (remove-hook 'kill-buffer-hook 'flymake-kill-buffer-hook t)
    ;;+(remove-hook 'find-file-hook (function flymake-find-file-hook) t)
    (remove-hook 'eldoc-documentation-functions 'flymake-eldoc-function t)

    ;; return any resized margin to original size
    (flymake--restore-margins)

    (when flymake-timer
      (cancel-timer flymake-timer)
      (setq flymake-timer nil))
    (mapc #'flymake--delete-overlay (flymake--really-all-overlays))
    (when flymake--state
      (maphash (lambda (_backend state)
                 (flymake--clear-foreign-diags state))
               flymake--state))))
   ;; turning Flymake on or off has consequences for listings
   (flymake--update-diagnostics-listings (current-buffer)))