emacs-devel
[Top][All Lists]
Advanced

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

Re: How to get advised function name form inside of the advice


From: Vitalie Spinu
Subject: Re: How to get advised function name form inside of the advice
Date: Mon, 21 Mar 2016 02:33:58 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.91 (gnu/linux)

Hi Stefan,

Sorry for coming late on this. Your reply didn't reach my mailbox.

Yes. The use case is your second example of multiple adviced functions and it
indeed solves the problem in a very acceptable way.

Thanks!

  Vitalie

>> On Mon, Mar 07 2016 23:22, Stefan Monnier wrote:

>> (defun tt-add (fun &rest args)
>>   (message "running advice for: %s" how_to_get_tt_name_here_)
>>   (apply fun args))
>> (advice-add 'tt :around 'tt-add)

>> I think my use case is a good reason to have such a feature.  Otherwise
>> one would need a macro to define separate advice function per advice
>> or pass a closure as an advice. Both ways are overkill for such
>> a basic requirement.

> I'm not sure I understand the details of the use case.  I can see two
> situations:

> - this tt-add advice is only used for `tt`, in which case it might be OK
>   for the the message to emit "tt-add" rather then "tt".
>   For that it would be desirable to have some kind of `current-defun-name`
>   macro, which could be useful more generally (not only for advices).

> - this tt-add advice is used on several functions.  In that
>   case the effort of writing something like

>     (defun tt-add (name fun &rest args)
>       (message "running advice for: %s" name)
>       (apply fun args))
>     (dolist (f '(tt tt2 tt3 tt4))
>       (advice-add f :around (apply-partially #'tt-add f)))

>   isn't that terrible.

> This said, if you're motivated enough, it should be possible to write
> a `current-advised-function-name` function, using the same kind of
> implementation hack as called-interactively-p (i.e. walking up the
> backtrace) and with similar limitations.

>         Stefan



reply via email to

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