From: Joost Kremers <joostkremers@fastmail.fm>
To: Christopher Dimech <dimech@gmx.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Defining minor mode with minor-mode condition
Date: Tue, 04 May 2021 09:01:20 +0200 [thread overview]
Message-ID: <87lf8v560d.fsf@fastmail.fm> (raw)
In-Reply-To: <trinity-ccd2b4c6-ef47-40a3-9640-04c6e8789fb6-1620100355671@3c-app-mailcom-bs09>
On Tue, May 04 2021, Christopher Dimech wrote:
> Is it valid to define a minor mode "crucibulum-minor-mode" and then
> have a "when" condition using crucibulum-minor-mode inside of it?
>
> Regards
> Christopher
>
> ;;;###autoload
> (define-minor-mode crucibulum-minor-mode
> "Minor mode for assisting with superior & inferior typeface."
> :init-value nil
> :global nil
> :lighter " Crucibulum"
>
> (when crucibulum-minor-mode
> (enable-texcom-typeface)
> (enable-ricci-notation)) )
Yes, AFAIK it's the normal way of doing this. Note that what you're defining
with `define-minor-mode` is a function with the name `crucibulum-minor-mode`
*plus* a variable of the same name.
When executed, the function `crucibulum-minor-mode` runs the code in the body of
the `define-minor-mode`, but before that, it does some other stuff, among which
is setting the variable `crucibulum-minor-mode`. So that's why this code works.
Note that when `define-minor-mode` is executed, it does *not* run the code in
its body. It just uses it to construct the function `crucibulum-minor-mode`.
Note also that the normal form is not with a `when` but with an `if`, since
normally you'll also want to add code to disable the minor mode. So it would
look something like:
```
;;;###autoload
(define-minor-mode crucibulum-minor-mode
"Minor mode for assisting with superior & inferior typeface."
:init-value nil
:global nil
:lighter " Crucibulum"
(if crucibulum-minor-mode
(progn
(enable-texcom-typeface)
(enable-ricci-notation))
(disable-texcom-typeface)
(disable-ricci-notation)))
```
--
Joost Kremers
Life has its moments
next prev parent reply other threads:[~2021-05-04 7:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-04 3:52 Defining minor mode with minor-mode condition Christopher Dimech
2021-05-04 4:12 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-04 7:01 ` Joost Kremers [this message]
2021-05-04 7:20 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-04 12:52 ` Stefan Monnier
2021-05-04 13:01 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-04 13:03 ` Christopher Dimech
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lf8v560d.fsf@fastmail.fm \
--to=joostkremers@fastmail.fm \
--cc=dimech@gmx.com \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.