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: Christopher Dimech
Subject: Re: Defining minor mode with minor-mode condition
Date: Tue, 4 May 2021 15:03:44 +0200

> Sent: Wednesday, May 05, 2021 at 12:52 AM
> From: "Stefan Monnier" <monnier@iro.umontreal.ca>
> To: help-gnu-emacs@gnu.org
> Subject: Re: Defining minor mode with minor-mode condition
>
> > ;;;###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

You make a very good point

>
>
>



reply via email to

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