* bug#17348: 24.3.50; Cannot advice-add the same function :before and :after
@ 2014-04-26 11:16 Nicolas Richard
2014-04-26 12:46 ` Stefan Monnier
0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Richard @ 2014-04-26 11:16 UTC (permalink / raw
To: 17348
Evalling:
(progn
(defun yfcheck () (message "Check"))
(defun yftest () (message "Test"))
(advice-add 'yftest :before #'yfcheck)
(advice-add 'yftest :after #'yfcheck)
(yftest)
nil)
gives (in the *Messages* buffer)
Test
Check
I'd have expected:
Check
Test
Check
--
Nico.
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#17348: 24.3.50; Cannot advice-add the same function :before and :after
2014-04-26 11:16 bug#17348: 24.3.50; Cannot advice-add the same function :before and :after Nicolas Richard
@ 2014-04-26 12:46 ` Stefan Monnier
2014-04-26 20:22 ` Nicolas Richard
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2014-04-26 12:46 UTC (permalink / raw
To: Nicolas Richard; +Cc: 17348
> (advice-add 'yftest :before #'yfcheck)
> (advice-add 'yftest :after #'yfcheck)
`advice-add' will not add the same function twice, indeed.
Similarly to `add-hook'. This is done explicitly in advice--add-function:
(when a
;; The advice is already present. Remove the old one, first.
(setf (gv-deref ref)
(advice--remove-function (gv-deref ref) (advice--car a))))
I guess we could change that, but then the notion of "removal" becomes
more complicated.
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#17348: 24.3.50; Cannot advice-add the same function :before and :after
2014-04-26 12:46 ` Stefan Monnier
@ 2014-04-26 20:22 ` Nicolas Richard
2014-05-01 20:47 ` Stefan Monnier
0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Richard @ 2014-04-26 20:22 UTC (permalink / raw
To: Stefan Monnier; +Cc: Nicolas Richard, 17348
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> (advice-add 'yftest :before #'yfcheck)
>> (advice-add 'yftest :after #'yfcheck)
>
> `advice-add' will not add the same function twice, indeed.
> Similarly to `add-hook'. This is done explicitly in advice--add-function:
>
> (when a
> ;; The advice is already present. Remove the old one, first.
> (setf (gv-deref ref)
> (advice--remove-function (gv-deref ref) (advice--car a))))
>
> I guess we could change that, but then the notion of "removal" becomes
> more complicated.
In the actual situation that lead me to adding the same function twice,
it was a tracing function, like (message "time: %s ; value of
foovariable: %s" (current-time) foovariable) and I assumed that I would
be able to remove them both with one (advice-remove ...) -- I guess that
isn't too complicated.
OTOH I also think that the current behaviour is fine, but I'd suggest
emitting a warning when an advice is being overwritten/removed that way.
--
Nico.
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#17348: 24.3.50; Cannot advice-add the same function :before and :after
2014-04-26 20:22 ` Nicolas Richard
@ 2014-05-01 20:47 ` Stefan Monnier
2014-05-10 20:09 ` Stefan Monnier
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2014-05-01 20:47 UTC (permalink / raw
To: Nicolas Richard; +Cc: 17348
> In the actual situation that lead me to adding the same function twice,
> it was a tracing function, like (message "time: %s ; value of
> foovariable: %s" (current-time) foovariable) and I assumed that I would
> be able to remove them both with one (advice-remove ...) -- I guess that
> isn't too complicated.
Removing them both would not be desirable in general.
> OTOH I also think that the current behaviour is fine, but I'd suggest
> emitting a warning when an advice is being overwritten/removed that way.
It's not meant to be a "secret" behavior, so people should be able to
rely on this behavior (just like you can rely on add-hook being
idempotent) and use it, in which case emitting a warning is
not appropriate.
This said, maybe we should make it easier to do what you wanted.
E.g. we could probably make it possible to use different `name'
properties to let a user add a function several times (potentially at
different places, but even at the same place).
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#17348: 24.3.50; Cannot advice-add the same function :before and :after
2014-05-01 20:47 ` Stefan Monnier
@ 2014-05-10 20:09 ` Stefan Monnier
0 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2014-05-10 20:09 UTC (permalink / raw
To: Nicolas Richard; +Cc: 17348-done
I installed a patch in `emacs-24' which will let you add the same
function multiple times, as long as you specify different `name'
properties for each one.
>> In the actual situation that lead me to adding the same function twice,
>> it was a tracing function, like (message "time: %s ; value of
>> foovariable: %s" (current-time) foovariable) and I assumed that I would
>> be able to remove them both with one (advice-remove ...) -- I guess that
>> isn't too complicated.
> Removing them both would not be desirable in general.
With the new code, you can remove each one individually by specifying
its `name', or you can remove them all by specifying the function itself.
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-05-10 20:09 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-26 11:16 bug#17348: 24.3.50; Cannot advice-add the same function :before and :after Nicolas Richard
2014-04-26 12:46 ` Stefan Monnier
2014-04-26 20:22 ` Nicolas Richard
2014-05-01 20:47 ` Stefan Monnier
2014-05-10 20:09 ` Stefan Monnier
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.