Is there any function do disable all the minor modes if I enable a specific major mode (let's take the text-mode
as an example)?
1 Answer
You can use a function like this:
(defun disable-all-minor-modes ()
(interactive)
(mapc
(lambda (mode-symbol)
(when (functionp mode-symbol)
;; some symbols are functions which aren't normal mode functions
(ignore-errors
(funcall mode-symbol -1))))
minor-mode-list))
Note that this will probably disable more functionality than you think.
If you want to disable minor modes when you in a specific mode, you can just hook this function like this:
(add-hook 'lisp-mode-hook #'disable-all-minor-modes)
Simply replace lisp-mode
with the major mode you want to use, and keep in mind that this will run in derived major modes as well.
-
4Disabling modes in the major mode hook is too early. Globalized minor modes enable their buffer-local mode in
after-change-major-mode-hook
, which runs later. You can instead use the major mode hook to(add-hook 'after-change-major-mode-hook 'FUNC :append :local)
– philsCommented Jun 25, 2018 at 21:00 -
I haven't thought about that. Thanks, @phils.– user12563Commented Jun 26, 2018 at 16:12
-
(buffer-local-variables &optional BUFFER)
and check each of theminor-mode-list
values against that list. Note that globalized modes act inafter-change-major-mode-hook
so you can't simply disable minor modes in the major mode hook, as that will be too early.