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

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

RE: [External] : '(emacs)Init Syntax' customizable minor mode variables


From: Drew Adams
Subject: RE: [External] : '(emacs)Init Syntax' customizable minor mode variables
Date: Mon, 8 Aug 2022 14:23:30 +0000

> Could someone provide an example(s) for the "customizable minor mode
> variables" that "do special things to enable the mode"?
> 
> The full sentence from the `(info "(emacs)Init Syntax")' node:
> 
> >    Some customizable minor mode variables do special things to enable
> > the mode when you set them with Customize, but ordinary ‘setq’ won’t
> > do that; to enable the mode in your init file, call the minor mode
> > command.

Good question.

This was more true before `define-minor-mode', IMO.
Before that, just `defun' was used to define a mode
command, and a `defcustom' defined its mode variable.

But the real point behind that, IMO, goes beyond minor
modes.  When a user option gets set, it's sometimes
important, or convenient, to carry out some associated
actions.

A minor-mode command is, among other things, a way
(the recommended way) to set its value, which records
whether the mode is on or off.  Since the command sets
the variable it is also the natural place to carry out
any actions associated with setting it.

If a user isn't aware that the command does more than
change the option value, just using `setq' to change
the value won't perform the associated actions.  That
might be disastrous, or it might just fail to do some
things that are desirable but not very important.
You might see that the mode was turned on/off OK when
you used setq, but you might not notice (e.g. right
away) that other things didn't happen as they should.  

For a user option more generally (not a mode variable),
there isn't necessarily a command to set the option.
And even if there is, some users might not be aware
that that's the way to set it (so that the associated
actions take place).

Simple example: When this option is set, function
`echo-bell-update' takes place, to do some other
things that take into account the changed value.

(defcustom echo-bell-background "Aquamarine"
  "Background color for `echo-bell-string'."
  :type  'color
  :set   (lambda (sym defs)
           (custom-set-default sym defs)
           (echo-bell-update))
  :group 'user)

The :set function takes care of this, as long as
you use Customize (or one of its functions, such as
`customize-set-variable) to set the value.

The `custom-set-default' part sets the option value,
and the `echo-bell-update' part carries out the
necessary actions associated with the value having
changed.

`setq' knows nothing about any actions that might
logically be associated with change a variable's
value.

In sum, if setting a variable is associated with
some actions then `setq' isn't the way to go.

reply via email to

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