all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: watching for variable assignment
Date: Mon, 10 Mar 2014 09:06:24 -0400	[thread overview]
Message-ID: <jwv61nmcj6e.fsf-monnier+gmane.emacs.help@gnu.org> (raw)
In-Reply-To: 87y50iibni.fsf@ericabrahamsen.net

> 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	other threads:[~2014-03-10 13:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-10  9:21 watching for variable assignment Eric Abrahamsen
2014-03-10  9:29 ` Jambunathan K
2014-03-10  9:59   ` Eric Abrahamsen
2014-03-10 10:00     ` Nicolas Richard
2014-03-10 10:09       ` Eric Abrahamsen
2014-03-10 10:35     ` Jambunathan K
2014-03-10 10:48       ` Jambunathan K
2014-03-10 11:23         ` Eric Abrahamsen
2014-03-10 10:54       ` Eric Abrahamsen
2014-03-10 11:08         ` Jambunathan K
2014-03-10 11:38           ` Jambunathan K
2014-03-10 10:35   ` Eric Abrahamsen
2014-03-10 13:06     ` Stefan Monnier [this message]
2014-03-21 10:26       ` Eric Abrahamsen
2014-03-21 12:21         ` Stefan
2014-03-10 19:56     ` Michael Heerdegen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwv61nmcj6e.fsf-monnier+gmane.emacs.help@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.