emacs-devel
[Top][All Lists]
Advanced

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

Re: Should mode commands be idempotent?


From: Clément Pit-Claudel
Subject: Re: Should mode commands be idempotent?
Date: Wed, 20 Sep 2017 00:10:51 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0

On 2017-09-19 21:58, Philipp Stephani wrote:
> I think it's generally expected that mode commands (both major and minor) are 
> reasonably idempotent, i.e. calling them twice should have the same effects 
> as calling them once (unless using 'toggle, of course). However, I couldn't 
> find this requirement in the manual, should it be added to the "Modes" 
> section?

I was not aware of this convention :/

Is there a way inside of a minor mode to check if it was already enabled before 
the current call, short of having a second variable for that? Most modes I've 
seen just check whether they're enabled or disabled, and do something based on 
that:

(define-minor-mode foo-mode
  "Foo."
  :lighter " foo"
  (if foo-mode
      (foo-mode-enable)
    (foo-mode-disable)))

This is often not idempotent (see visual-line-mode for a concrete example).

Clément.



reply via email to

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