* '(emacs)Init Syntax' customizable minor mode variables
@ 2022-08-08 12:38 YE
2022-08-08 14:23 ` [External] : " Drew Adams
2022-08-11 3:37 ` Michael Heerdegen
0 siblings, 2 replies; 7+ messages in thread
From: YE @ 2022-08-08 12:38 UTC (permalink / raw)
To: help-gnu-emacs
Hello,
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [External] : '(emacs)Init Syntax' customizable minor mode variables 2022-08-08 12:38 '(emacs)Init Syntax' customizable minor mode variables YE @ 2022-08-08 14:23 ` Drew Adams 2022-08-09 17:08 ` YE 2022-08-11 3:37 ` Michael Heerdegen 1 sibling, 1 reply; 7+ messages in thread From: Drew Adams @ 2022-08-08 14:23 UTC (permalink / raw) To: YE, help-gnu-emacs@gnu.org > 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. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [External] : '(emacs)Init Syntax' customizable minor mode variables 2022-08-08 14:23 ` [External] : " Drew Adams @ 2022-08-09 17:08 ` YE 0 siblings, 0 replies; 7+ messages in thread From: YE @ 2022-08-09 17:08 UTC (permalink / raw) To: Drew Adams; +Cc: YE, help-gnu-emacs@gnu.org Thank you, Drew. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: '(emacs)Init Syntax' customizable minor mode variables 2022-08-08 12:38 '(emacs)Init Syntax' customizable minor mode variables YE 2022-08-08 14:23 ` [External] : " Drew Adams @ 2022-08-11 3:37 ` Michael Heerdegen 2022-08-11 9:19 ` YE 1 sibling, 1 reply; 7+ messages in thread From: Michael Heerdegen @ 2022-08-11 3:37 UTC (permalink / raw) To: YE; +Cc: help-gnu-emacs YE <yet@ego.team> writes: > Could someone provide an example(s) for the "customizable minor mode > variables" that "do special things to enable the mode"? Enabling a mode has a lot of side effects - it's no surprise that most modes can't be enabled by just setting the mode's variable. Just as adding "MODE" to the mode-line won't enable the mode. There are some special examples where setting the mode variable does suffice to turn the mode, but that's due to the kind of implementation (you can, for example, set up the mode so that it is on, more or less, all the time, but permanently watches the variable and does nothing and stays silent when the variable is nil). Michael. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: '(emacs)Init Syntax' customizable minor mode variables 2022-08-11 3:37 ` Michael Heerdegen @ 2022-08-11 9:19 ` YE 2022-08-12 2:14 ` Michael Heerdegen 0 siblings, 1 reply; 7+ messages in thread From: YE @ 2022-08-11 9:19 UTC (permalink / raw) To: Michael Heerdegen; +Cc: YE, Drew Adams, help-gnu-emacs Michael Heerdegen <michael_heerdegen@web.de> writes: > YE <yet@ego.team> writes: > >> Could someone provide an example(s) for the "customizable minor mode >> variables" that "do special things to enable the mode"? > > Enabling a mode has a lot of side effects - it's no surprise that most > modes can't be enabled by just setting the mode's variable. Just as > adding "MODE" to the mode-line won't enable the mode. That's right. It's hard to comprehend that sentence also because one normally doesn't expect variables to perform an action, especially "to enable the mode". Typically, one expects functions to do the action and variables to store values. (I suppose it's rightful to say "normally" and "typically" here, looking from the point of view of an average modern programmer.) As Drew had already mentioned, part of this confusion comes from the fact 'defcustom' can not only store values but also do things (':set'). And which frustrates not aware users from time to time (when they try to change a user option value with an ubiquitous 'setq' but that doesn't work). > There are some special examples where setting the mode variable does > suffice to turn the mode, but that's due to the kind of implementation > (you can, for example, set up the mode so that it is on, more or less, > all the time, but permanently watches the variable and does nothing and > stays silent when the variable is nil). I find this example helpful, thank you. Does it mean the word "enable" in that paragraph should be read not as "turn on the minor mode" but rather "store a state marker for the turned on minor mode"? If it is so, than the source of my confusion regarding that sentence is found. The discussed sentence: > 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. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: '(emacs)Init Syntax' customizable minor mode variables 2022-08-11 9:19 ` YE @ 2022-08-12 2:14 ` Michael Heerdegen 2022-08-12 10:17 ` YE 0 siblings, 1 reply; 7+ messages in thread From: Michael Heerdegen @ 2022-08-12 2:14 UTC (permalink / raw) To: YE; +Cc: Drew Adams, help-gnu-emacs YE <yet@ego.team> writes: > That's right. It's hard to comprehend that sentence also because one > normally doesn't expect variables to perform an action, especially "to > enable the mode". Typically, one expects functions to do the action and > variables to store values. In that case they are more than plain Elisp variables, in some sense. It's good that we have a different name: "(user) options". > Does it mean the word "enable" in that paragraph should be read not as > "turn on the minor mode" but rather "store a state marker for the turned > on minor mode"? If it is so, than the source of my confusion regarding > that sentence is found. > > The discussed sentence: > > 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. Note that what I mentioned was only describing one possibility (of a minority of minor modes). I think in the majority of cases the setter just calls the mode function (`custom-set-minor-mode'). Doing "special things" is probably an exception. So what you should keep in mind that (setq MODE-VARIABLE VALUE) doesn't turn the mode in a lot of cases, but Customize is more user friendly (as a graphical interface), so it takes care of all cases and setting the mode variable from Customize should always work. In most cases setting the mode variable from Customize will just call the mode function. Michael. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: '(emacs)Init Syntax' customizable minor mode variables 2022-08-12 2:14 ` Michael Heerdegen @ 2022-08-12 10:17 ` YE 0 siblings, 0 replies; 7+ messages in thread From: YE @ 2022-08-12 10:17 UTC (permalink / raw) To: Michael Heerdegen; +Cc: YE, help-gnu-emacs Thanks, Michael. This discussion answered the questions I had on the topic at this stage. ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-08-12 10:17 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-08-08 12:38 '(emacs)Init Syntax' customizable minor mode variables YE 2022-08-08 14:23 ` [External] : " Drew Adams 2022-08-09 17:08 ` YE 2022-08-11 3:37 ` Michael Heerdegen 2022-08-11 9:19 ` YE 2022-08-12 2:14 ` Michael Heerdegen 2022-08-12 10:17 ` YE
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).