* Activating a function when a variable is set
@ 2007-10-25 21:52 Vinicius Jose Latorre
2007-10-25 21:21 ` Davis Herring
2007-10-26 9:45 ` Richard Stallman
0 siblings, 2 replies; 4+ messages in thread
From: Vinicius Jose Latorre @ 2007-10-25 21:52 UTC (permalink / raw)
To: GNU Emacs (devel)
Does anybody know if there is a way to activate a function when a
variable is set to t and also when the same variable is set to nil?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Activating a function when a variable is set
2007-10-25 21:52 Activating a function when a variable is set Vinicius Jose Latorre
@ 2007-10-25 21:21 ` Davis Herring
2007-10-26 1:33 ` Vinicius Jose Latorre
2007-10-26 9:45 ` Richard Stallman
1 sibling, 1 reply; 4+ messages in thread
From: Davis Herring @ 2007-10-25 21:21 UTC (permalink / raw)
To: Vinicius Jose Latorre; +Cc: GNU Emacs
> Does anybody know if there is a way to activate a function when a
> variable is set to t and also when the same variable is set to nil?
As in, react immediately to (setq trapped-variable t)? No. With custom
variables you can react to them being customized by giving them a :set
attribute. But AFAIK there's no way to "detect" a change to a Lisp
variable.
Davis
--
This product is sold by volume, not by mass. If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Activating a function when a variable is set
2007-10-25 21:21 ` Davis Herring
@ 2007-10-26 1:33 ` Vinicius Jose Latorre
0 siblings, 0 replies; 4+ messages in thread
From: Vinicius Jose Latorre @ 2007-10-26 1:33 UTC (permalink / raw)
To: herring; +Cc: GNU Emacs
Davis Herring wrote:
>> Does anybody know if there is a way to activate a function when a
>> variable is set to t and also when the same variable is set to nil?
>>
>
> As in, react immediately to (setq trapped-variable t)? No. With custom
> variables you can react to them being customized by giving them a :set
> attribute. But AFAIK there's no way to "detect" a change to a Lisp
> variable.
>
There is a way to react to (setq trapped-var t) by programming a minor
mode, like:
(defvar trapped-var nil)
(add-to-list 'minor-mode-alist '(trapped-var :eval (trapped-fun)))
(defun trapped-fun ()
(message "trapped-var is t")
" TRAP")
When the command (setq trapped-var t) is executed, the modeline will
show " TRAP" and the minibuffer will display "trapped-var is t".
When the command (setq trapped-var nil) is executed, the modeline will
not show " TRAP" but trapped-fun will not be invoked.
The question is if there is a way to react also when (setq trapped-var
nil) is executed.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Activating a function when a variable is set
2007-10-25 21:52 Activating a function when a variable is set Vinicius Jose Latorre
2007-10-25 21:21 ` Davis Herring
@ 2007-10-26 9:45 ` Richard Stallman
1 sibling, 0 replies; 4+ messages in thread
From: Richard Stallman @ 2007-10-26 9:45 UTC (permalink / raw)
To: Vinicius Jose Latorre; +Cc: emacs-devel
Does anybody know if there is a way to activate a function when a
variable is set to t and also when the same variable is set to nil?
I don't want to change the architecture of Lisp that way.
I don't even like the fact that define-minor-modes defines minor
mode commands that do something other than set a variable.
It's not clean.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-10-26 9:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-25 21:52 Activating a function when a variable is set Vinicius Jose Latorre
2007-10-25 21:21 ` Davis Herring
2007-10-26 1:33 ` Vinicius Jose Latorre
2007-10-26 9:45 ` Richard Stallman
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).