From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Christopher Monsanto <chris@monsan.to>
Cc: emacs-devel@gnu.org
Subject: Re: replacing process sentinels and filters with hooks
Date: Wed, 03 Oct 2012 09:37:33 -0400 [thread overview]
Message-ID: <jwvpq4zd790.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <CAC5n7TEjMEdqAfwwF_45TK1ZBo4Kj26awujJx1wcmSETijLAeg@mail.gmail.com> (Christopher Monsanto's message of "Wed, 3 Oct 2012 06:59:58 -0400")
> way of doing things?", I'm referring to the fact that add-function and
> add-hook do similar things and it would be ideal (in my opinion) to
> not have two general purpose APIs that (almost?) do the same thing.
I agree that having both add-hook and add-function is not ideal.
But I think the ideal solution doesn't exist because of constraints
imposed by backward compatibility.
> Hooks could use an interface similar to defadvice to change their
> arguments: (hook-set-arg <index> <value>) would modify the argument
> being passed to the next hook.
Hmm... that sounds ugly. Because we also want to let a function prevent
the subsequent functions from being run. IOW we want to be able to have
the equivalent of an `around' advice.
I think something along the lines of what with-wrapper-hook does is
a good model (i.e. (add-function (process-filter proc) fun) would take
a `fun' which expects 3 args: the proc, the string, and a
"keep-running-the-hook" function which expects 2 args (the proc and the
string)).
Then we can also define
(defmacro add-function-before (place fun)
`(add-function ,place (lambda (fallback-fun &rest args)
(apply ,fun args)
(apply fallback-fun args))))
Which is more like `add-hook'; and
(defmacro add-function-after (place fun)
`(add-function ,place (lambda (fallback-fun &rest args)
(apply fallback-fun args)
(apply ,fun args))))
which is a bit like "add-hook with the append arg set".
> Yes, there seems to be a bit of ugliness in this case with
> process-callbacks needing to return a symbol.
Yes, that's one ugliness. The other problem with it is that it means
that it doesn't solve the problem for other "objects holding a function"
such as symbol-function, or syntax-propertize-function.
> In this case, I just think of a symbol as acting as a reference type
> in ML, so it doesn't bother me too much I guess.
As a functional programmer, that's very much the way I think about
it, indeed. But the advantage of add-function (assuming we can write
it) is that it can work for anything that holds a function. E.g. we
wouldn't even need to change process-filter (I'd still consider
changing process-sentinel to clean up its string argument).
I.e. not only we can preserve backward compatibility, but we don't even
need to obsolete anything.
> I've copied the rest of your message below, as it wasn't sent to the
> list. My apologies if it was meant to be private.
Thank you for that (I actually did send it to the list "by hand" via
`resend' after noticing, IIRC).
Stefan
next prev parent reply other threads:[~2012-10-03 13:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-01 13:14 replacing process sentinels and filters with hooks Christopher Monsanto
2012-10-01 14:42 ` Paul Eggert
2012-10-01 15:20 ` Christopher Monsanto
2012-10-01 15:34 ` Stefan Monnier
[not found] ` <CAC5n7TGfMktPFOwpSqeqC6pF9rtpx14_fQaouEVnWmma2SfzdA@mail.gmail.com>
2012-10-01 16:53 ` Christopher Monsanto
[not found] ` <jwvboglmxm8.fsf-monnier+emacs@gnu.org>
2012-10-03 10:59 ` Christopher Monsanto
2012-10-03 13:37 ` Stefan Monnier [this message]
2012-11-13 17:58 ` Stefan Monnier
2012-10-03 14:39 ` Stephen J. Turnbull
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=jwvpq4zd790.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=chris@monsan.to \
--cc=emacs-devel@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.