Geany dev
|
Originally the Geany plugin API only allowed plugins to add to Geany functionality, plugins could not modify Geany built-in functionality, but since Geany 2.1 the PluginExtension API allows plugins to take over some of the core Geany functionality: autocopletion, calltip display, symbol goto, and typename highlighting inside document.
Plugins using the PluginExtension
API are just normal plugins and behave as described in Plugin HowTo.
First, any plugin interested in using this interface has to register its PluginExtension
structure pointer using plugin_extension_register()
. This typically happens in the init()
function of the plugin. Registered PluginExtension
pointers have to be unregistered before the plugin is unloaded using plugin_extension_unregister()
, typically inside the cleanup()
function of the plugin.
Inside the PluginExtension
struct, the plugin fills-in the pointers of the functions it wishes to implement. Typically, these functions come in pairs:
_provided
are used by Geany to query the plugin whether it implements the particular feature for the passed document_perform
are used by Geany to pass control to the plugin to perform the feature instead of performing the Geany built-in functionality.When the plugin returns TRUE
from the function assigned to the _provided
member of PluginExtension
, it indicates it wants to take control of the particular feature and disable Geany's implementation. However, returning TRUE
does not automatically guarantee that the plugin's implementation is executed - if there are multiple plugins competing for implementing a feature, the extension with the highest priority passed into the plugin_extension_register()
function gets executed.
A plugin can perform a check if it gets executed for the particular feature; e.g. for autocompletion the plugin can use plugin_extension_autocomplete_provided()
which returns TRUE
if the passed extension is executed, taking into account all registered extension priorities and the return values of all functions assigned to autocomplete_provided
members of the registered extensions. This can be used if the plugin needs to perform auxiliary actions outside the function assigned to autocomplete_perform
to verify it is actually active for this feature.
Below you will find an example of a plugin implementing autocompletion for Python. The full version of this code can be found under plugins/demopluginext.c inside the Geany repository.