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

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

Re: proper use of add-function


From: Eric Abrahamsen
Subject: Re: proper use of add-function
Date: Tue, 22 May 2018 17:29:17 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

On 05/22/18 20:19 PM, Noam Postavsky wrote:
> On 22 May 2018 at 20:09, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:
>> Michael Heerdegen <michael_heerdegen@web.de> writes:
>>
>>> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>>>
>>>> Okay, I see what you and Noam are saying, and in fact what the docstring
>>>> is saying. It's just pretty weird that `add-function' works on
>>>> variables, and `advice-add' works on functions.
>
> Yeah, this isn't the first time I've seen confusion over this (e.g.,
> Bug#30241). The docstring is clear enough when you already know what
> it says, but I've just added an extra note that should help guide
> people toward advice-add.
>
> [1: e3f00f5637]: 2018-05-22 20:08:01 -0400
>   Clarify when to use advice-add vs add-function
>   
> https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=e3f00f5637a2790923a9c4c1d4b7dbf65027d8ce

Thanks for doing that. That was definitely a "makes sense when you
already understand it" situation.

>>> Actually `add-function' works for "places" (including
>>> `symbol-function'), so it's the more general and more low-level tool.
>>> `advice-add' is higher-level and specialized on function names.
>>
>> I guess that's why I kept trying to make this work -- I thought the
>> `symbol-function' place would allow me to apply my advice to
>> 'canonically-space-region. Why doesn't that work?
>
> (add-function
>    :filter-args
>    (symbol-function 'canonically-space-region)
>    #'my-canonical-space-region)
>
> This seems to work for me (although advice-add is preferable for
> reasons listed in the manual).

Right, I get that now. I was only stuck on `add-function' because I was
under the impression that it would get me buffer-local behavior, which I
understand now it won't.

Thanks,
Eric



reply via email to

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