emacs-devel
[Top][All Lists]
Advanced

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

Re: replacing process sentinels and filters with hooks


From: Stefan Monnier
Subject: Re: replacing process sentinels and filters with hooks
Date: Wed, 03 Oct 2012 09:37:33 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux)

> 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



reply via email to

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