help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Defining minor mode with minor-mode condition


From: Stefan Monnier
Subject: Re: Defining minor mode with minor-mode condition
Date: Tue, 04 May 2021 08:52:40 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> ;;;###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)))

[ Of course those `:foo nil` keyword arguments are redundant.  ]
I actually often find it convenient to unconditionally "disable" first:

    (define-minor-mode crucibulum-minor-mode
      "Minor mode for assisting with superior & inferior typeface."
      :lighter " Crucibulum"
      (disable-texcom-typeface)
      (disable-ricci-notation)
      (when crucibulum-minor-mode
        (enable-texcom-typeface)
        (enable-ricci-notation)))

the advantage is to avoid problems where, say, `enable-texcom-typeface`
is not idempotent, so if you call (crucibulum-minor-mode 1) several times
you might end up with multiple copies of the same thing added to a list.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]