unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: Leo Liu <sdl.web@gmail.com>, 19066@debbugs.gnu.org
Subject: bug#19066: 25.0.50; nadvice and interactive-form
Date: Sun, 30 May 2021 13:26:52 -0400	[thread overview]
Message-ID: <jwvwnrgw3c7.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87r1hry5dq.fsf@gnus.org> (Lars Ingebrigtsen's message of "Fri, 28 May 2021 04:11:13 +0200")

Lars Ingebrigtsen [2021-05-28 04:11:13] wrote:
> Leo Liu <sdl.web@gmail.com> writes:
>> 1. Start emacs and load a file with these lines:
>>
>>    (advice-add 'just-one-space :before #'change-interactive-form)
>>    (defun change-interactive-form (&optional x y)
>>      (interactive (list 1 1))
>>      (princ (list x y)))
>>
>> M-x just-one-space prints (1 nil)
>>
>> 2. Start emacs and load a file with these lines:
>>
>>    (defun change-interactive-form (&optional x y)
>>      (interactive (list 1 1))
>>      (princ (list x y)))
>>    (advice-add 'just-one-space :before #'change-interactive-form)
>>
>> M-x just-one-space errs: apply: Wrong number of arguments: (0 . 1), 2
>
> So whether this works depends on whether `change-interactive-form' is
> defined or not when `advice-add' is run?  (The only difference here is
> the order.)
> Perhaps Stefan has some insights here; added to the CCs.

[ Side note: the correct/desired behavior is the one described by (2),
  i.e. it should signal a "Wrong number of arguments" (tho after
  printing (1 1)).  ]

`advice-add` creates a new function object which is a "composition" of
the old function and the advice that's added to it.

In the case where `change-interactive-form` is defined later, one way to
make this work right would be for `advice-add` to put some kind of
"watcher" on (symbol-function 'change-interactive-form) to recompute the
interactive form of the "composed function".

Another way would be to make the interactive form of the "compose
function" more dynamic: make it re-checks the interactive form of every
advice function every time.  That's probably the better option.


        Stefan






  reply	other threads:[~2021-05-30 17:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-16 10:00 bug#19066: 25.0.50; nadvice and interactive-form Leo Liu
2021-05-28  2:11 ` Lars Ingebrigtsen
2021-05-30 17:26   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2021-05-31  5:43     ` Lars Ingebrigtsen
2021-05-31 12:49       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvwnrgw3c7.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=19066@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=sdl.web@gmail.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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).