Re: Last use of defadvice in Emacs
Stefan Monnier via CC-Mode-help <[email protected]> Thu, 07 Apr 2022 22:34:45 -0400
| Newsgroups | gmane.emacs.cc-mode.general,gmane.emacs.devel |
|---|---|
| Message-ID | <[email protected]> |
> 1. ad-get-arg vs ad-get-argument: I've always used ad-get-arg --
> however for the last few years I've notied that ad-get-arg is
> getting harder and harder to discover; for the last few years,
> emacs always completes ad-get-arg to ad-get-argument. I personally
> find ad-get-arg to be more idiomatic and easier to use.
`ad-get-argument` is basically an internal function of `advice.el` so
you never want to use it. But `ad-get-arg` (the thing you *do* need to
use to access arguments) is not "defined" anywhere, neither as
a function nor as a macro, so TAB completion will never know (and has
never known) to use it.
For kicks, try an advice like
(defadvice next-line (before some-fun activate)
(message "surprise: %S" '(ad-get-args 0)))
> 2. Re ad-return-value -- I've almost never had to explicitly set
> ad-return-value -- in around and after advice, I have always
> returned ad-return-value and have never hit issues --- perhaps
> because I've always wrappered my advice body in a let form --
> not sure. What kind of breakages happen when returning
> ad-return-value vs explicitly setting ad-return-value at the end
> of the advice body?
You typically need to set it when you want to do:
(defadvice some-function (around my-advice activate)
(if (bla bla)
(cons 1 ad-do-it)
(do something else)
(and return some value)))
which needs to be something like:
(defadvice some-function (around my-advice activate)
(if (bla bla)
(progn ad-do-it
(push 1 ad-return-value))
(do something else)
(setq ad-return-value (and return some value))))
> 3. I've avoided the complexity around preactivation vs
> activation etc by always saying (... pre act comp) in all my
> advice forms
Not sure in which sense this "avoided the complexity".
And most people reading your code won't know what it means, I'm afraid.
Stefan