I’m not sure I am using ad-get-args and ad-get-arg right.
For example, the following code doesn’t work.
(defun my-add (a b)
(+ a b))
(defadvice my-add (after my-log-on activate)
(message "my-add: %s" (ad-get-args)))
(my-add 1 2)
The last expression causes an error:
Debugger entered--Lisp error: (void-function ad-get-args).
The following doesn’t work either.
(defun my-substract (a b)
(- a b))
(defadvice my-substract (around my-log-on activate)
(message "my-substract: %s" (ad-get-arg 0))
(ad-do-it))
(my-substract 10 1)
The defadvice gives a warning:
Warning: `(setq ad-return-value (ad-Orig-my-substract a b))' is a malformed
function
And the last expression gives an error:
Debugger entered--Lisp error: (invalid-function (setq ad-return-value (ad-Orig-my-substract a b)))
(setq ad-return-value (ad-Orig-my-substract a b))()
I was trying to use defadvice to watch start-process arguments for debugging purposes and I found my way of using ad-get-arg didn’t work.
Update: Answer,
From the answers it turns out that I should have used (ad-get-args 0) instead of (ad-get-args) in (defadvice my-add ..), and I should have used ad-do-it instead of (ad-do-it) in in (defadvice my-substract ..).
And it’s better to use trace-function.
You have two problems in your code.
First (as you noted), you’re using
ad-get-argsincorrectly. The docs say:It looks like what you want is:
In your
my-subtract, the problem is your use ofad-do-it, you have it surrounded by parentheses, it should not be. This is the correct use:From the docs in the advice library:
The best tutorial and introduction to advice I’ve found is in the advice library itself (in the comments in the beginning).