On Sun, Feb 22, 2009 at 3:11 AM, Ville M. Vainio <[email protected]> wrote:

>
> I suggest we do create CommandChainDispatcher in g namespace:
>
> g.act_on_node = CommandChainDispatcher()


more likely leoPlugins.CommandChainDispatcher.

>
> And call g.act_on_node(c,p) on alt+a.
>
> Then you could create your own handlers easily in scripts:
>
> def act_check_url(c,p):
>  if not p.h.startswith('@url'): raise g.TryNext
>  jump_to_url(p.b.splitlines())[0].strip())
>
> g.act_on_node.add(act,check_url, priority = 10)


This hints at solutions to several long-standing problems with dispatching
plugins.  It sets a priority, thereby affecting the order in which event
handlers (aka hooks) are called, and raising g.tryNext allows a handler to
indicate "failure".  It will work.

I think we can, and should, make this scheme as flexible a we possibly can.
It will cost nothing and will allow much greater interactions between
plugins.  Such a scheme could be applied to all, or almost all, event
handlers, not just act_on_node.

Suppose event handlers are allowed to indicate more than a simple yes/no
"success" indication.  Instead, they would "return" values that indicate
this kind of information:

- Don't call any other event hook for this event.  This is the present
"success" indication.
- Allow all other event hooks for this event.
- Allow event hooks only for a list of named plugins.

The last would allow a bit more flexibility than a simple priority.  I'm not
completely sure that this flexibility would actually be useful, but I am
inclined to allow it unless it can be shown to be completely redundant.
Maybe it is, or could be made redundant.

In addition, we could imaging a two-stage process for loading plugins.
Stage one is the present process for loading plugins.  Stage two would be a
post-plugin-load pass, which would give all plugins the chance to
communicate with each other just after all plugins have been loaded but
before any hooks have been called.  The plugins manager would call each
plugins 'plugins-loaded' event handler,  This hook would give plugins the
chance to query the load status, priorities and defined event handlers of
all other plugins.  Based on this information, plugins could disable
themselves, reset priorities, etc. For the first time, I think, this would
allow an easy way for plugins to communicate with each other.

This solves a lot of problems!  Perhaps more importantly, it opens up the
real possibility of plugins acting in concert.  Thanks for your ideas,
Ville.  This is heading in a promising new direction.

Edward

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to