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

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

bug#17348: 24.3.50; Cannot advice-add the same function :before and :aft


From: Nicolas Richard
Subject: bug#17348: 24.3.50; Cannot advice-add the same function :before and :after
Date: Sat, 26 Apr 2014 22:22:19 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

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.





reply via email to

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