0

I am working on a minor-mode and I'd like it to be active only for major modes derived from prog-mode.

So far I know that the macro define-minor-mode takes a argument :global to decide whether or not the mode should be global. But this is too general.

And I'd like not requiring the user to set-up the mode itself with a hook à la: (add-hook 'prog-mode-hook (lambda () (my-minor-mode t)))

Thanks

3
  • 1
    This can be shortened to (add-hook 'prog-mode-hook 'my-minor-mode) thanks to define-minor-mode.
    – wasamasa
    Oct 8, 2017 at 10:09
  • 1
    "I'd like not requiring the user to set-up the mode itself with a hook" just sounds silly, because that's precisely how one expects to do this in Emacs. Any users who aren't already familiar with that pattern need to become familiar with it, because it's standard practice. Which perceived problem are you trying to circumvent here?
    – phils
    Oct 8, 2017 at 11:31
  • 1
    If you are determined to not do that, then it sounds like you should define an additional globalized minor mode, such that the (new) global mode controls your (existing) buffer-local minor mode, and switches it on in a buffer if (derived-mode-p 'prog-mode). See define-globalized-minor-mode
    – phils
    Oct 8, 2017 at 11:38

0

Your Answer

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

Browse other questions tagged or ask your own question.