[Top][All Lists]

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

Advising a variable over functions?

From: Stephen Berman
Subject: Advising a variable over functions?
Date: 28 Feb 2002 00:23:38 +0100

I want to disable around a dozen functions in a derived mode of a
major mode I'm working on.  I can do this by advising these functions,
but in each case the advice is exactly the same, so I wrote a
function that loops over a list of the functions I want to advise,
instead of writing a dozen separate defadvice's, schematically:

        (defun my-advice ()
          (let ((func-list my-disabled-functions))
            (while func-list
              (let ((fn (car func-list)))
                (defadvice fn (before disable)
                  (if (my-disabled-buffer-p)      ;; this is the advice
                      (error my-error-message)))  ;; used in each case
                (ad-pushnew-advised-function fn)
                (ad-activate fn)
                (setq func-list (cdr func-list))))))

and I added this to the define-derived-mode function.  But when I call
a function that invoke the derived mode, I get the error message:
"ad-activate: `my-function' is not advised", where `my-function' is
the first function in the list `my-disabled-functions'.  Yet
`my-function' is listed in the value of `ad-advised-functions'.  Where
am I going wrong?  Or is it not possible to do what I want (advising a
variable over functions)?  If not, is there some other way than
writing a dozen or more near-identical defadvice's to disable the
functions in the derived mode?

--Steve Berman

reply via email to

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