emacs-devel
[Top][All Lists]
Advanced

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

Re: Last use of defadvice in Emacs


From: Stefan Monnier
Subject: Re: Last use of defadvice in Emacs
Date: Thu, 07 Apr 2022 22:34:45 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

> 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




reply via email to

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