bug-gnu-emacs
[Top][All Lists]
Advanced

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

Re: An idea: controlling the order of execution of elisp hook functions


From: Kim F. Storm
Subject: Re: An idea: controlling the order of execution of elisp hook functions
Date: 10 Dec 2001 12:10:41 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1

eliz@is.elta.co.il (Eli Zaretskii) writes:

> On 10 Dec 2001, Kim F. Storm wrote:
> 
> > > Perhaps such a category scheme could simply store, together with the
> > > hook, the name of the package that added the hook.  Then other
> > > packages could decide whether they need to put their hook before or
> > > after the hooks that are already in the list.  A simple extension of
> > > add-hook could provide a `before' and an `after' feature.
> > 
> > Suppose package A knows its hook should come before package B, but B
> > doesn't know about A.
> > 
> > Now, if A's hook is added before B, then you need to store the `before B'
> > requirement too, to handle adding B's hook later on.
> 
> Most of the packages don't have any requirements about whereabouts of
> their hooks.  If they did, the current situation would wimply not
> work.  The fact that it does suggests that the interdependencies
> between the hooks are largely a non-issue.
> 
> Assuming that only a handful of hooks need to be placed before or
> after a certain other hook, do you still see a problem?

Not as such, but *if there is a problem* I just wanted to point out
that your idea didn't solve it in general.

I would imagine that most hooks really don't need to be run in a
specific order, but *some* hooks need to be run either first or last -
specifically the pre-command-hook and post-command-hook might need
this level of control.  We could achieve this by adding :first and
:last modifiers to add-hook.

Here, I could imagine a package which uses both a pre and a post hook
would like to say that its pre hook should be run as the *last* hook run
before executing the command and its post hook should be the *first*
hook to run after executing the command.

Now, the problem arises if two packages both want their hook to
be run first or last.  In that case, those hooks probably need
to be run in a specific sequence for proper operation of both
packages.

If that is the case, I see two options:

1) The `add-hook' need more logic to handle a `:before HOOK' modifier
   in addition to :first and :last.

2) The packages have to be modified to use a common hook which calls
   the original hooks in the proper sequence.

Option 1 is the clean option, but 2 is probably sufficient in the few
cases there this is really a problem (hoping that the package
developers are able to co-operate).




reply via email to

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