How to check whether a minor mode(.e.g flymake-mode) is on?

Most minor modes are defined using the define-minor-mode macro. For buffer-local modes, that macro creates a buffer-local variable of the same name as the mode itself1. The variable is non-nil when the mode is enabled for the current buffer.

Therefore to check whether flymake-mode is enabled, you can test the variable flymake-mode (noting that this variable might not be defined at all if the mode has not been enabled):

(and (boundp 'flymake-mode) flymake-mode)

Which, as Thom point out in the comments, can be expressed using the convenient macro:

(bound-and-true-p flymake-mode)

Which we can use as the condition for an if or when or unless expression:

(if (bound-and-true-p flymake-mode)
    (message "flymake-mode is on")
  (message "flymake-mode is off"))

1 For global minor modes, the corresponding variable is global; but flymake-mode is buffer-local.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)