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

From: Nicolas Richard <[email-masked]>
Date: Sat, 26 Apr 2014 22:22:19 +0200

Stefan Monnier <[email-masked]> 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.