unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#19066: 25.0.50; nadvice and interactive-form
@ 2014-11-16 10:00 Leo Liu
  2021-05-28  2:11 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Leo Liu @ 2014-11-16 10:00 UTC (permalink / raw)
  To: 19066


1. Start emacs and load a file with these lines:

--8<---------------cut here---------------start------------->8---
   (advice-add 'just-one-space :before #'change-interactive-form)
   (defun change-interactive-form (&optional x y)
     (interactive (list 1 1))
     (princ (list x y)))
--8<---------------cut here---------------end--------------->8---

M-x just-one-space prints (1 nil)

2. Start emacs and load a file with these lines:

--8<---------------cut here---------------start------------->8---
   (defun change-interactive-form (&optional x y)
     (interactive (list 1 1))
     (princ (list x y)))
   (advice-add 'just-one-space :before #'change-interactive-form)
--8<---------------cut here---------------end--------------->8---

M-x just-one-space errs: apply: Wrong number of arguments: (0 . 1), 2

Leo





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#19066: 25.0.50; nadvice and interactive-form
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2021-05-28  2:11 UTC (permalink / raw)
  To: Leo Liu; +Cc: 19066, Stefan Monnier

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.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#19066: 25.0.50; nadvice and interactive-form
  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
  2021-05-31  5:43     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-05-30 17:26 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Leo Liu, 19066

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






^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#19066: 25.0.50; nadvice and interactive-form
  2021-05-30 17:26   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 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
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2021-05-31  5:43 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Leo Liu, 19066

Stefan Monnier <monnier@iro.umontreal.ca> writes:

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

That sounds like a good solution to me -- the interactive path isn't
normally performance critical, so adding more work in that case should
be fine.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#19066: 25.0.50; nadvice and interactive-form
  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
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2021-05-31 12:49 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Leo Liu, 19066

Lars Ingebrigtsen [2021-05-31 07:43:34] wrote:
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> 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.
> That sounds like a good solution to me -- the interactive path isn't
> normally performance critical, so adding more work in that case should
> be fine.

Yes, performance is not an issue.  But preserving the semantics 100% is
currently somewhere between hard and impossible.  99.9% is fairly easy,
OTOH (IIRC the main problem has to do with how the args get represented
in `command-history`).


        Stefan






^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-05-31 12:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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