[Top][All Lists]

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

RE: Should mode commands be idempotent?

From: Drew Adams
Subject: RE: Should mode commands be idempotent?
Date: Wed, 20 Sep 2017 16:05:35 -0700 (PDT)

> > Also, is there a motivation for introducing this new requirement, seeing
> > as how we've never had such a restriction in the past?
> In the case of minor modes, I think a good implementation of a minor
> mode should be idempotent, because it can easily happen that a minor
> mode is enabled twice via different hooks, e.g.:
>     (add-hook 'text-mode-hook #'visual-line-mode)
>     (add-hook 'xml-mode-hook  #'visual-line-mode)
> If you know that xml-mode runs text-mode-hook, you can drop the second
> line, but it's good if the second line is just redundant rather
> than harmful (after all, some people prefer xml-mode not to run
> text-mode-hook).
> For major modes, I don't know what is the intention exactly, because I'm
> not sure exactly what kind of non-idempotence there is out there.
> I think for major modes a more significant issue is to make sure that
>     (with-temp-buffer (insert text) (funcall mode))
> doesn't do anything undesirable (and currently, we're pretty far from
> having such a guarantee, although we do have code like the above at
> various places).

Those are good points.  What should not be taken for granted,
I think, is that enabling twice can have only harmful effects
if a mode is not idempotent.  Not being idempotent only means
that invoking it more than once does not have zero effect.
It does not follow that it has harmful effects.

That's my point, about not imposing a convention or a requirement
without a good reason.  Not that I have in mind some particular
good use case for "beneficial" effects of multiple invocations.
Just that more than one invocation does not necessarily imply
harm instead of benefit.

reply via email to

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