From: Stefan Monnier via CC-Mode-help <cc-mode-help@lists.sourceforge.net>
To: "T.V Raman" <raman@google.com>
Cc: bug-cc-mode@gnu.org, acm@muc.de, eliz@gnu.org, emacs-devel@gnu.org
Subject: Re: Last use of defadvice in Emacs
Date: Thu, 07 Apr 2022 22:34:45 -0400 [thread overview]
Message-ID: <jwvpmlsnwn1.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <25167.38053.15113.49802@retriever.mtv.corp.google.com> (T. V. Raman's message of "Thu, 7 Apr 2022 18:49:25 -0700")
> 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
next prev parent reply other threads:[~2022-04-08 2:34 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-04 19:49 Last use of defadvice in Emacs Stefan Monnier
2022-04-04 20:08 ` T.V Raman
2022-04-04 20:38 ` Stefan Monnier via CC-Mode-help
2022-04-04 20:48 ` T.V Raman
2022-04-05 4:28 ` Richard Stallman
2022-04-06 18:52 ` Alan Mackenzie
2022-04-06 21:08 ` Stefan Monnier via CC-Mode-help
2022-04-07 1:51 ` T.V Raman
2022-04-07 2:49 ` Stefan Monnier via CC-Mode-help
2022-04-07 6:14 ` Eli Zaretskii
2022-04-07 21:59 ` Stefan Monnier via CC-Mode-help
2022-04-08 1:49 ` T.V Raman
2022-04-08 2:34 ` Stefan Monnier via CC-Mode-help [this message]
2022-04-08 14:21 ` T.V Raman
2022-04-08 6:00 ` Eli Zaretskii
2022-04-07 18:18 ` Alan Mackenzie
2022-04-07 18:37 ` Stefan Monnier
2022-04-08 17:10 ` Alan Mackenzie
2022-04-08 17:39 ` Stefan Monnier via CC-Mode-help
2022-04-08 18:06 ` Alan Mackenzie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvpmlsnwn1.fsf-monnier+emacs@gnu.org \
--to=cc-mode-help@lists.sourceforge.net \
--cc=acm@muc.de \
--cc=bug-cc-mode@gnu.org \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
--cc=raman@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.