How to check if a minor mode is active?
Test the value of the mode variable. Example:
(if delete-selection-mode ...)
The mode variable might not be known, so you can add this protection:
(if (bound-and-true-p unknown-mode) ...)
But some minor modes don’t have a variable, e.g., auto-fill-mode. – rubikitch
True. I was going to say “File a bug”, but checking the code defining
‘auto-fill-mode’ I see this comment:
(put 'auto-fill-function :minor-mode-function 'auto-fill-mode) ;; FIXME: turn into a proper minor mode. ;; Add a global minor mode version of it. (defun auto-fill-mode (&optional arg) ...
So I guess the answer is: (1) file a bug, (2) volunteer to fix the code. ;-) – DrewAdams
How do I ensure that a mode is always active/enabled? For example, I’d like electric-pair-mode to always be on.
– wickedjargon 2017-12-20 05:10 UTC
From the manual: “Some minor modes are global: while enabled, they affect everything you do in the Emacs session, in all buffers. Other minor modes are buffer-local; they apply only to the current buffer, so you can enable the mode in certain buffers and not others.”
Some modes offer both,
global-some-mode. If the minor mode you are interested in does not offer that, you could still add it to a hook. One very generic hook would be
find-file-hook, for example.
– Alex Schroeder 2017-12-20 06:23 UTC