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)
(when (and (eq flymake-indicator-type 'fringes)
(not (cl-case flymake-fringe-indicator-position
(left-fringe (< 0 (nth 0 (window-fringes))))
(right-fringe (< 0 (nth 1 (window-fringes)))))))
;; There are no fringes in the buffer, fallback to margins.
(setq-local flymake-indicator-type 'margins))
;; AutoResize margins.
(flymake--resize-margins)
;; If Flymake happened to be already ON, we must cleanup
;; existing diagnostic overlays, lest we forget them by blindly
;; reinitializing `flymake--state' in the next line.
;; See https://github.com/joaotavora/eglot/issues/223.
(mapc #'flymake--delete-overlay (flymake--really-all-overlays))
(setq flymake--state (make-hash-table))
(setq flymake--recent-changes nil)
(when flymake-start-on-flymake-mode (flymake-start t))
;; Other diagnostic sources may already target this buffer's file
;; before we turned on: these sources may be of two types...
(let ((source (current-buffer))
(bfn buffer-file-name))
;; 1. For `flymake-list-only-diagnostics': here, we do nothing.
;; FIXME: We could remove the corresponding entry from that
;; variable, as we assume that new diagnostics will come in soon
;; via the brand new `flymake-mode' setup. For simplicity's
;; sake, we have opted to leave the backend for now.
nil
;; 2. other buffers where a backend has created "foreign"
;; diagnostics and pointed them here. We must highlight them in
;; this buffer, i.e. create overlays for them. Those other
;; buffers and backends are still responsible for them, i.e. the
;; current buffer does not "own" these foreign diags.
(dolist (buffer (buffer-list))
(with-current-buffer buffer
(when (and flymake-mode flymake--state)
(maphash (lambda (_backend state)
(maphash (lambda (file diags)
(when (or (eq file source)
(string= bfn (expand-file-name file)))
(with-current-buffer source
(mapc (lambda (diag)
(flymake--highlight-line diag
'foreign))
diags))))
(flymake--state-foreign-diags state)))
flymake--state))))))
;; 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 margin to original size
(flymake--resize-margins t)
(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)))