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 16:36:57 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> And another very basic question:
>>
>> I can't get `add-function' to do its thing. I want to add a :filter-args
>> function to #'canonically-space-region, and because this is a minor
>> mode, I want it set locally.
>
> I guess there is a problem with what you want to achieve: we have no
> buffer local function bindings of symbols.
>
>> (add-function
>>    :filter-args
>>    (local 'canonically-space-region)
>>    #'my-canonical-space-region)
>>
>> (defun my-canonical-space-region (bounds)
>>   ;; etc
>>   (list (car bounds) (nth 1 bounds)))
>
> Technically ok, but this tries to bind the (value cell of the) symbol
> canonically-space-region.
>
> What I typically do in this (quite common) scenario is to install the
> advice (globally) and check for the mode in the `current-buffer' in the
> advice.  I guess there is no alternative unless you find a different way
> to reach what you want (like advising `canonical-space-region-function',
> which doesn't exist).

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. It's counterintuitive,
and I wonder if the docs couldn't make that more explicit. It's also a
bummer that my minor mode clobbers things globally, but I guess there's
no great harm done.

Thanks to both of you for being on call!

Eric




reply via email to

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