all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: help-gnu-emacs@gnu.org
Subject: Re: proper use of add-function
Date: Tue, 22 May 2018 16:36:57 -0700	[thread overview]
Message-ID: <87603fxnxi.fsf@ericabrahamsen.net> (raw)
In-Reply-To: 87a7srgtco.fsf@web.de

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	other threads:[~2018-05-22 23:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-22 22:58 proper use of add-function Eric Abrahamsen
2018-05-22 23:18 ` Noam Postavsky
2018-05-22 23:31 ` Michael Heerdegen
2018-05-22 23:36   ` Eric Abrahamsen [this message]
2018-05-22 23:58     ` Michael Heerdegen
2018-05-23  0:09       ` Eric Abrahamsen
2018-05-23  0:19         ` Noam Postavsky
2018-05-23  0:29           ` Eric Abrahamsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87603fxnxi.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.