[Top][All Lists]

[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: Mon, 01 Oct 2012 11:34:11 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux)

> 1) Process filters and sentinels do not fit in with the rest of the
> Emacs API. In every other API that I can think of that involves a user
> callback, the hooks API is used.

Hooks are used normally for un-planned interaction between two
unrelated packages.  OTOH process sentinels and filters are typically
tightly linked to their process, the package that creates the process
being usually the same that provides the sentinels and filters.

> 2) A process sentinel must parse text to figure out how the process
> changed.

Yes, that's ugly (and it only affects sentinels).

> 3) It's hard for more than one interested party to interact with a process.

Indeed, tho it's rarely needed.  Concrete examples would be useful for
this discussion.

> My proposed change is to add a new function, (process-hook-list
> <proc>), which returns a list of hooks.  Each hook takes one argument,
> which has one of the following forms:

A hook is a symbol/variable which can hold a list of functions.
I'd rather call it `process-callbacks'.

> '(input <string>)

Just <string> would work as well.

So your proposal can be decomposed in 3 parts:
- merge sentinels and filters.
- provide a standard way to combine sentinels and filters, which is to
  run them in sequence (for sentinels, it might be a fine default, but
  for filters, it might be more useful for each filter to be able to
  affect the <string> passed to the next filter).
- change the particular representation of state passed to process sentinels.

I agree the third part is a good change (tho not terribly important).
I'm not sure the first is useful since in my experience sentinels and
filters do different things anyway.

As for the second, maybe a better path is to try and provide generic
`add-function' and `remove-function' that can operate on any
generalized-variable that holds a function.  So you could do

  (add-function (process-filter proc) #'toto)

which would set proc's filter to a new function that runs the old
function (if any) and runs toto as well.   And then `remove-function'
would reset the sentinel to its original value.

> signals through (run-hooks (process-hook-list ..))

run-hooks takes symbols as arguments.


reply via email to

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