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)?

  • Enabling a major mode normally begins by disabling all buffer-local minor modes. So please be more specific.
    – Stefan
    Jun 25, 2018 at 20:34
  • 2
    I am guessing that you only want to disable the buffer-local minor modes (and not the global minor modes). To my knowledge Emacs does not provide a convenient way to identify an active mode as either buffer-local or global, but you could likely use (buffer-local-variables &optional BUFFER) and check each of the minor-mode-list values against that list. Note that globalized modes act in after-change-major-mode-hook so you can't simply disable minor modes in the major mode hook, as that will be too early.
    – phils
    Jun 25, 2018 at 20:59

1 Answer 1


You can use a function like this:

(defun disable-all-minor-modes ()
   (lambda (mode-symbol)
     (when (functionp mode-symbol)
       ;; some symbols are functions which aren't normal mode functions
         (funcall mode-symbol -1))))

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.

  • 4
    Disabling 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)
    – phils
    Jun 25, 2018 at 21:00
  • I haven't thought about that. Thanks, @phils.
    – user12563
    Jun 26, 2018 at 16:12
  • This function can disable some modes globally.
    – HappyFace
    Mar 13, 2022 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.