I have a minor mode called tematika-minor-mode
. When I turn it on, I want to enable outline-minor-mode
automatically. And turn it off when tematika-minor-mode
is disabled.
1 Answer
I'm assuming that tematika-minor-mode
is a buffer-local minor mode, not a global minor mode.
Adapting my answer from your earlier related question: https://emacs.stackexchange.com/a/77495/454 you can do the following. The difference is that this time we're adding to the global value of the minor mode hook (because you don't care what kind of buffer the minor mode is being enabled in), whereas in the earlier question we were restricting the cases where we triggered the behaviour by using the buffer-local value of the minor mode hook (because you only wanted it if the minor mode was enabled in an elisp buffer).
(add-hook 'tematika-minor-mode-hook 'my-outline-toggle-with-tematika-minor-mode)
(defun my-outline-toggle-with-tematika-minor-mode ()
"Toggle `outline-minor-mode' with `tematika-minor-mode' buffer-locally."
(outline-minor-mode (if tematika-minor-mode 1 0)))
Or if tematika-minor-mode
is your own custom code, you could simply update the mode definition:
(define-minor-mode tematika-minor-mode
...
(if tematika-minor-mode
(progn
...
(outline-minor-mode 1))
...
(outline-minor-mode 0)))
-
T like the second version as it avoids the hook. I find using hooks somewhat complicated.– DilnaCommented Jun 9, 2023 at 11:54
-
If you're writing custom code for your own use and you don't need to use a hook, then there's probably very little reason to consider doing so. Hooks are extremely useful, but for the most part they are for interacting with code written by other people.– philsCommented Jun 9, 2023 at 12:21
foo-mode
andoutline-minor-mode
are both minor modes, and one mode is made to track the other in the exact way you're asking for here. (The difference between that question and this is only the interaction withemacs-lisp-mode
which you don't need here.)