bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#19066: 25.0.50; nadvice and interactive-form


From: Stefan Monnier
Subject: bug#19066: 25.0.50; nadvice and interactive-form
Date: Sun, 30 May 2021 13:26:52 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

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 via email to

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