emacs-devel
[Top][All Lists]
Advanced

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

Re: Activating a function when a variable is set


From: Vinicius Jose Latorre
Subject: Re: Activating a function when a variable is set
Date: Thu, 25 Oct 2007 22:33:30 -0300
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.8) Gecko/20071009 SeaMonkey/1.1.5

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.





reply via email to

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