From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: watching for variable assignment Date: Mon, 10 Mar 2014 09:06:24 -0400 Message-ID: References: <87lhwih0ij.fsf@ericabrahamsen.net> <87lhwicsgc.fsf@gmail.com> <87y50iibni.fsf@ericabrahamsen.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1394474654 25355 80.91.229.3 (10 Mar 2014 18:04:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 10 Mar 2014 18:04:14 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Mar 10 19:04:23 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WN4Yn-0007md-Qj for geh-help-gnu-emacs@m.gmane.org; Mon, 10 Mar 2014 19:04:21 +0100 Original-Received: from localhost ([::1]:50407 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WN4Yn-0000r8-C5 for geh-help-gnu-emacs@m.gmane.org; Mon, 10 Mar 2014 14:04:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42423) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WN4YV-0000qj-2b for help-gnu-emacs@gnu.org; Mon, 10 Mar 2014 14:04:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WN4YN-0007jr-ON for help-gnu-emacs@gnu.org; Mon, 10 Mar 2014 14:04:03 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:45292) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WN4YN-0007jk-Hr for help-gnu-emacs@gnu.org; Mon, 10 Mar 2014 14:03:55 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1WN4YL-0007Fp-OG for help-gnu-emacs@gnu.org; Mon, 10 Mar 2014 19:03:53 +0100 Original-Received: from 76-10-154-114.dsl.teksavvy.com ([76.10.154.114]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 10 Mar 2014 19:03:53 +0100 Original-Received: from monnier by 76-10-154-114.dsl.teksavvy.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 10 Mar 2014 19:03:53 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 46 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 76-10-154-114.dsl.teksavvy.com User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) Cancel-Lock: sha1:88Zptp3F9kqC6WcfDTZgHc42WZs= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:96402 Archived-At: > 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