[Geany-devel] GeanyPy Keybindings Again

Colomban Wendling lists.ban at xxxxx
Mon Sep 12 21:37:37 UTC 2011


Le 12/09/2011 22:16, Matthew Brush a écrit :
> Hi,

Hey,

> I started working on keybindings again for GeanyPy and I was hoping to
> get a little advice from the experts.

Experts? OK, I don't feel concerned :D

> I've hacked together some code that allows the single GeanyPy plugin to
> create new GeanyPlugin structs so that it can add multiple keygroups for
> the single plugin.  This actually seems to work fairly well considering
> how kludgey the implementation is (ie. copying structs from Geanys code
> into GeanyPy's code because they aren't exposed, etc.).

Ouch

> Now I have two remaining challenges to overcome.  The first is that
> there doesn't seem to be a way to remove/delete a keygroup, that is to
> undo what plugin_set_keygroup does.  The function I think I need is
> keybindings_free_group(), but it's not in the plugin API, and I can't
> "fake" it like I've done with other parts since it requires the
> `keybinding_groups`.  So basically what's happening, is when a Python
> plugin is unloaded and is cleaned up, I free the "sub" GeanyPlugin and
> all it's memory.  Now when you go into the Preferences->Keybindings you
> see just weird things where the plugin name/keybindings were, presumably
> since Geany is reading from freed/adjacent memory or some such.
> 
> So the first question is, is there a way to remove a plugin/keygroup
> from those registered with Geany?  At this point, I don't really care if
> it's a kludgey solution, I just want it working :)

Unfortunately I think (as said on IRC) that the answer is "no".
Unloading the plugin does it, but heh, you don't want to...

Actually this is related to hacking the GeanyPlugin stuff since normal
plugins would break everything if they freed the keybindings themselves.
 Actually you'd need plugin_free(), but it's obviously not meant to be
exported...

> The second challenge I'm facing is coming up with a way for GeanyPy to
> manage connection of Python plugins keybindings and dispatching to them
> when a keybinding is pressed.  What I've done so far is, as mentioned
> above, to create a phony GeanyPlugin/GeanyKeygroup for each plugin, and
> each plugin gets allotted KEYBINDINGS_MAX bindings using the
> plugin_set_keygroup() function.  The problem I'm having now is how to
> associate the Python plugin (consider it a C struct if it helps) with
> the keybinding.  It seems like it would be easier if there was
> possibility of passing a closure or whatever it's called when connecting
> to the key binding, but GeanyKeyCallback doesn't seem to support this.
> I've a tried and failed so far with a few different ideas.  So, can
> anyone recommend a decent way of mapping which Python plugin connected
> to which keybinding and then call out to the plugin when the keybinding
> is activated?

Currently the keybinding's callback only have one parameter: the ID with
which this keybinding was registered.  We could imagine we add
additional infos at some point for it to look like

void GeanyKeyGroupCallback (GeanyPlugin *plugin, guint key_id, gpointer
user_data)

or something.  Though, in most cases (e.g. "normal" plugins) the plugin
argument is suite useless, and the user_data only allows to pass data
without a global, so for most plugins (again) it only allows another
style.  In your case it would allow to register a kind of dispatch
function and know to which "subplugin" dispatch it.

> One last thing since I'm already writing a really long email, I notice
> in keybindings.h[1] in the GeanyKeyGroup definition, there's a 'plugin'
> member that is mentioned elsewhere in keybindings.c (I think) as being
> used by GeanyLua or some such.  What is this for, and would it be useful
> for what I'm trying to do with GeanyPy?
> 
> Also, why is the comment above the definition "Plugins should not set
> these fields", while the comment for the 'plugin' member says "Used by
> plugins"?

The "plugin" member is a boolean that is used to know whether the key
group is an internal one or a plugin one.internal.

Not sure what's the matter about GeanyLua, but it only speaks about
duplicating string used as keybinding entries' name and label.


Regards,
Colomban



More information about the Devel mailing list