* Advice functions: required args that byte-compiler warns are unused
@ 2021-11-03 17:53 Drew Adams
2021-11-03 19:04 ` Stefan Monnier via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 2+ messages in thread
From: Drew Adams @ 2021-11-03 17:53 UTC (permalink / raw)
To: 'Help-Gnu-Emacs (help-gnu-emacs@gnu.org)'
[-- Attachment #1: Type: text/plain, Size: 957 bytes --]
I'm wondering how you deal with this - what's a
good way.
I have an advice function `my-foo-after-advice',
which I use as an :after advice for function `foo':
(defun my-foo-after-advice (&rest args)
"..."
(ignore args) ; Quiet the byte-compiler.
(do-stuff-that-doesnt-refer-to-ARGS))
Suppose function `foo' requires 3 arguments:
(defun foo (a b c) ...)
An :after advice needs to accept the same args as
the function it advises. But the byte-compiler
warns "Unused lexical argument 'args'" (naturally).
So I've been adding an `(ignore args)'.
Is there a better way to suppress such a warning?
I looked for a `declare' possibility for this,
which would be a declaration to the byte-compiler
rather than a runtime operation.
Of course `ignore' doesn't cost much here, but it
seems like we should be able to keep info for the
compiler separate from code that gets run.
Hope I'm missing something simple.
[-- Attachment #2: winmail.dat --]
[-- Type: application/ms-tnef, Size: 13492 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Advice functions: required args that byte-compiler warns are unused
2021-11-03 17:53 Advice functions: required args that byte-compiler warns are unused Drew Adams
@ 2021-11-03 19:04 ` Stefan Monnier via Users list for the GNU Emacs text editor
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2021-11-03 19:04 UTC (permalink / raw)
To: help-gnu-emacs
> (defun my-foo-after-advice (&rest args)
> "..."
> (ignore args) ; Quiet the byte-compiler.
> (do-stuff-that-doesnt-refer-to-ARGS))
Use
(defun my-foo-after-advice (&rest _args)
or just
(defun my-foo-after-advice (&rest _)
> Suppose function `foo' requires 3 arguments:
>
> (defun foo (a b c) ...)
Here you can use
(defun foo (_a _b _c) ...)
tho you can also use
(defun foo (&rest _) ...)
since you advice doesn't have to only accept exactly the same args as
the function it advises: it is free to accept *more* use-cases (and it's
often a good idea to do so, in case the advised function grows some
&optional arguments in the future).
Stefan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-03 19:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-03 17:53 Advice functions: required args that byte-compiler warns are unused Drew Adams
2021-11-03 19:04 ` Stefan Monnier via Users list for the GNU Emacs text editor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).