[Top][All Lists]

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

Re: watching for variable assignment

From: Stefan Monnier
Subject: Re: watching for variable assignment
Date: Mon, 10 Mar 2014 09:06:24 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

> No, this isn't going to work -- the only way I could find the code
> that's resetting the variable would be to instrument it directly,
> which would require knowing which code it was in the first place.
> Not much use!

FWIW, I think I'd accept a patch which adds support for "watchers" on
symbols (by extending the read-only bit to 2 bits, so we can
distinguish a "really read-only symbol" from a "symbol with watchers").

> I've got git emacs installed on my system, and I think the newer version
> of advising functions might work better. I'm hoping that if I add a
> function to "setq" with the :before key, I can avoid the infinite loop
> problem.

No, you can't advise special forms (and even if you changed nadvice.el to
try and support it, it still wouldn't apply to byte-compiled code).

> I read the manual, and found it pretty unhelpful on the question of how
> to tell it what function you're actually trying to advise.  A "setf-able
> place" doesn't mean much to me when I'm just trying to hijack "setq" and
> check its args.

Can you point to the offending documentation (it's still in the process
of being written, so it would be helpful).
I don't see any "setf-able" anywhere, but FWIW such a thing is also
called "an lvalue" in other languages.

In any case it sounds like you were looking at the doc of add-function,
whereas you'd want to use advice-add instead (tho you don't really want
to use it since it wouldn't work on setq anyway).

> Can someone illustrate for me the (I'd hope fairly simple) case of
> adding a function :before "setq", and checking if its first argument is
> "nnimap-split-fancy"? The possibility that's it's a longer setq form
> with multiple arguments is one I'll consider after I've got the basic
> shape down...

It could look something like

   (defun my-setter (var val &rest _)
     (if (eq var 'nnimap-split-fancy)
         (error "Gotcha, sucker!")))
   (advice-add 'set :before #'my-setter)

-- Stefan

reply via email to

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