unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Noam Postavsky <npostavs@gmail.com>
To: Eric Abrahamsen <eric@ericabrahamsen.net>
Cc: Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Re: proper use of add-function
Date: Tue, 22 May 2018 20:19:14 -0400	[thread overview]
Message-ID: <CAM-tV-_7KKOWQ3s7cFHSDoojhzaymXBD2UHJ2H3hryAKpvZRww@mail.gmail.com> (raw)
In-Reply-To: <871se3xmfk.fsf@ericabrahamsen.net>

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

>> 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).



  reply	other threads:[~2018-05-23  0:19 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
2018-05-22 23:58     ` Michael Heerdegen
2018-05-23  0:09       ` Eric Abrahamsen
2018-05-23  0:19         ` Noam Postavsky [this message]
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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=CAM-tV-_7KKOWQ3s7cFHSDoojhzaymXBD2UHJ2H3hryAKpvZRww@mail.gmail.com \
    --to=npostavs@gmail.com \
    --cc=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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).