diff --git a/doc/de/autogen/plugin_api/hdata.asciidoc b/doc/de/autogen/plugin_api/hdata.asciidoc index 2f66dad4b..2aac4832d 100644 --- a/doc/de/autogen/plugin_api/hdata.asciidoc +++ b/doc/de/autogen/plugin_api/hdata.asciidoc @@ -843,6 +843,8 @@ *** 'version' (string) *** 'license' (string) *** 'charset' (string) +*** 'priority' (integer) +*** 'initialized' (integer) *** 'debug' (integer) *** 'prev_plugin' (pointer, hdata: "plugin") *** 'next_plugin' (pointer, hdata: "plugin") diff --git a/doc/de/autogen/plugin_api/plugins_priority.asciidoc b/doc/de/autogen/plugin_api/plugins_priority.asciidoc new file mode 100644 index 000000000..d5a171b0b --- /dev/null +++ b/doc/de/autogen/plugin_api/plugins_priority.asciidoc @@ -0,0 +1,12 @@ +. charset (13000) +. logger (12000) +. exec (11000) +. trigger (10000) +. aspell (9000) +. alias (8000) +. fifo (7000) +. xfer (6000) +. irc (5000) +. relay (4000) +. guile, lua, perl, python, ruby, tcl (3000) +. script (2000) diff --git a/doc/docgen.py b/doc/docgen.py index d75ee914d..6ba11f0c4 100644 --- a/doc/docgen.py +++ b/doc/docgen.py @@ -351,6 +351,23 @@ def get_irc_colors(): return irc_colors +def get_plugins_priority(): + """ + Get priority of default WeeChat plugins as a dictionary. + """ + plugins_priority = {} + infolist = weechat.infolist_get('plugin', '', '') + while weechat.infolist_next(infolist): + name = weechat.infolist_string(infolist, 'name') + priority = weechat.infolist_integer(infolist, 'priority') + if priority in plugins_priority: + plugins_priority[priority].append(name) + else: + plugins_priority[priority] = [name] + weechat.infolist_free(infolist) + return plugins_priority + + def update_file(oldfile, newfile, num_files, num_files_updated, obj): """Update a doc file.""" try: @@ -394,6 +411,7 @@ def docgen_cmd_cb(data, buf, args): completions = get_completions() url_options = get_url_options() irc_colors = get_irc_colors() + plugins_priority = get_plugins_priority() # get path and replace ~ by home if needed path = weechat.config_get_plugin('path') @@ -675,34 +693,23 @@ def docgen_cmd_cb(data, buf, args): update_file(filename, tmpfilename, num_files, num_files_updated, 'irc_colors') + # write plugins priority + filename = directory + '/plugin_api/plugins_priority.asciidoc' + tmpfilename = filename + '.tmp' + _file = open(tmpfilename, 'w') + for priority in sorted(plugins_priority, reverse=True): + plugins = ', '.join(sorted(plugins_priority[priority])) + _file.write('. {0} ({1})\n'.format(escape(plugins), priority)) + _file.close() + update_file(filename, tmpfilename, num_files, num_files_updated, + 'plugins_priority') + # write counters weechat.prnt('', - 'docgen: {0}: {1:3d} files ' - '({2:2d} cmd, {3:2d} opt, {4:2d} infos, ' - '{5:2d} infos_hash, {6:2d} infolists, {7:2d} hdata, ' - '{8:2d} complt)' + 'docgen: {0}: {1} files, {2} updated' ''.format(locale, num_files['total1'], - num_files['commands'], - num_files['options'], - num_files['infos'], - num_files['infos_hashtable'], - num_files['infolists'], - num_files['hdata'], - num_files['completions'])) - weechat.prnt('', - ' ' - '{0:3d} updated ({1:2d} cmd, {2:2d} opt, {3:2d} infos, ' - '{4:2d} infos_hash, {5:2d} infolists, {6:2d} hdata, ' - '{7:2d} complt)' - ''.format(num_files_updated['total1'], - num_files_updated['commands'], - num_files_updated['options'], - num_files_updated['infos'], - num_files_updated['infos_hashtable'], - num_files_updated['infolists'], - num_files_updated['hdata'], - num_files_updated['completions'])) + num_files_updated['total1'])) weechat.prnt('', 'docgen: total: {0} files, {1} updated' ''.format(num_files['total2'], num_files_updated['total2'])) diff --git a/doc/en/autogen/plugin_api/hdata.asciidoc b/doc/en/autogen/plugin_api/hdata.asciidoc index 8b82d23f9..48afef9bd 100644 --- a/doc/en/autogen/plugin_api/hdata.asciidoc +++ b/doc/en/autogen/plugin_api/hdata.asciidoc @@ -843,6 +843,8 @@ *** 'version' (string) *** 'license' (string) *** 'charset' (string) +*** 'priority' (integer) +*** 'initialized' (integer) *** 'debug' (integer) *** 'prev_plugin' (pointer, hdata: "plugin") *** 'next_plugin' (pointer, hdata: "plugin") diff --git a/doc/en/autogen/plugin_api/plugins_priority.asciidoc b/doc/en/autogen/plugin_api/plugins_priority.asciidoc new file mode 100644 index 000000000..d5a171b0b --- /dev/null +++ b/doc/en/autogen/plugin_api/plugins_priority.asciidoc @@ -0,0 +1,12 @@ +. charset (13000) +. logger (12000) +. exec (11000) +. trigger (10000) +. aspell (9000) +. alias (8000) +. fifo (7000) +. xfer (6000) +. irc (5000) +. relay (4000) +. guile, lua, perl, python, ruby, tcl (3000) +. script (2000) diff --git a/doc/en/weechat_plugin_api.en.asciidoc b/doc/en/weechat_plugin_api.en.asciidoc index 8b71bf8ce..5deef0cd4 100644 --- a/doc/en/weechat_plugin_api.en.asciidoc +++ b/doc/en/weechat_plugin_api.en.asciidoc @@ -45,16 +45,19 @@ This file defines structures and types used to communicate with WeeChat. The plugin must use some macros (to define some variables): WEECHAT_PLUGIN_NAME("name"):: - plugin name + the plugin name WEECHAT_PLUGIN_DESCRIPTION("description"):: - short description of plugin + a short description of plugin WEECHAT_PLUGIN_VERSION("1.0"):: - plugin version + the plugin version WEECHAT_PLUGIN_LICENSE("GPL3"):: - plugin license + the plugin license + +WEECHAT_PLUGIN_PRIORITY(1000):: + the plugin priority (optional, see below) [[main_functions]] === Main functions @@ -87,6 +90,20 @@ Return value: * 'WEECHAT_RC_OK' if successful (plugin will be loaded) * 'WEECHAT_RC_ERROR' if error (plugin will NOT be loaded) +[[plugin_priority]] +===== Plugin priority + +When plugins are auto-loaded (for example on startup), WeeChat first loads all +plugins, and then calls the 'init' functions, using the priority defined in +each plugin. A high priority means that the 'init' function is called first. + +Default priority is 1000 (with such priority, the plugin is loaded after all +default plugins). + +The default WeeChat plugins are initialized in this order: + +include::autogen/plugin_api/plugins_priority.asciidoc[] + ==== weechat_plugin_end This function is called when plugin is unloaded by WeeChat. diff --git a/doc/fr/autogen/plugin_api/hdata.asciidoc b/doc/fr/autogen/plugin_api/hdata.asciidoc index 2e8242b68..4d7c06bcb 100644 --- a/doc/fr/autogen/plugin_api/hdata.asciidoc +++ b/doc/fr/autogen/plugin_api/hdata.asciidoc @@ -843,6 +843,8 @@ *** 'version' (string) *** 'license' (string) *** 'charset' (string) +*** 'priority' (integer) +*** 'initialized' (integer) *** 'debug' (integer) *** 'prev_plugin' (pointer, hdata: "plugin") *** 'next_plugin' (pointer, hdata: "plugin") diff --git a/doc/fr/autogen/plugin_api/plugins_priority.asciidoc b/doc/fr/autogen/plugin_api/plugins_priority.asciidoc new file mode 100644 index 000000000..d5a171b0b --- /dev/null +++ b/doc/fr/autogen/plugin_api/plugins_priority.asciidoc @@ -0,0 +1,12 @@ +. charset (13000) +. logger (12000) +. exec (11000) +. trigger (10000) +. aspell (9000) +. alias (8000) +. fifo (7000) +. xfer (6000) +. irc (5000) +. relay (4000) +. guile, lua, perl, python, ruby, tcl (3000) +. script (2000) diff --git a/doc/fr/weechat_plugin_api.fr.asciidoc b/doc/fr/weechat_plugin_api.fr.asciidoc index 3cfa93f1c..f8e920bce 100644 --- a/doc/fr/weechat_plugin_api.fr.asciidoc +++ b/doc/fr/weechat_plugin_api.fr.asciidoc @@ -58,6 +58,9 @@ WEECHAT_PLUGIN_VERSION("1.0"):: WEECHAT_PLUGIN_LICENSE("GPL3"):: licence de l'extension +WEECHAT_PLUGIN_PRIORITY(1000):: + priorité de l'extension (facultatif, voir ci-dessous) + [[main_functions]] === Fonctions principales @@ -90,6 +93,21 @@ Valeur de retour : * 'WEECHAT_RC_OK' si ok (l'extension sera chargée) * 'WEECHAT_RC_ERROR' si erreur (l'extension ne sera PAS chargée) +[[plugin_priority]] +===== Priorité de l'extension + +Lorsque les extensions sont automatiquement chargées (par exemple au +démarrage), WeeChat charge d'abord toutes les extensions, puis appelle les +fonctions 'init', en utilisant la priorité définie dans chaque extension. +Une grande priorité signifie que la fonction 'init' est appelée en premier. + +La priorité par défaut est 1000 (avec une telle priorité, l'extension est +chargée après toutes les extensions par défaut). + +Les extensions par défaut de WeeChat sont initialisées dans cet ordre : + +include::autogen/plugin_api/plugins_priority.asciidoc[] + ==== weechat_plugin_end Cette fonction est appelée quand l'extension est déchargée par WeeChat. diff --git a/doc/it/autogen/plugin_api/hdata.asciidoc b/doc/it/autogen/plugin_api/hdata.asciidoc index 5c70d6c63..7ea6f5bda 100644 --- a/doc/it/autogen/plugin_api/hdata.asciidoc +++ b/doc/it/autogen/plugin_api/hdata.asciidoc @@ -843,6 +843,8 @@ *** 'version' (string) *** 'license' (string) *** 'charset' (string) +*** 'priority' (integer) +*** 'initialized' (integer) *** 'debug' (integer) *** 'prev_plugin' (pointer, hdata: "plugin") *** 'next_plugin' (pointer, hdata: "plugin") diff --git a/doc/it/autogen/plugin_api/plugins_priority.asciidoc b/doc/it/autogen/plugin_api/plugins_priority.asciidoc new file mode 100644 index 000000000..d5a171b0b --- /dev/null +++ b/doc/it/autogen/plugin_api/plugins_priority.asciidoc @@ -0,0 +1,12 @@ +. charset (13000) +. logger (12000) +. exec (11000) +. trigger (10000) +. aspell (9000) +. alias (8000) +. fifo (7000) +. xfer (6000) +. irc (5000) +. relay (4000) +. guile, lua, perl, python, ruby, tcl (3000) +. script (2000) diff --git a/doc/it/weechat_plugin_api.it.asciidoc b/doc/it/weechat_plugin_api.it.asciidoc index d8fae2550..35a82b4c4 100644 --- a/doc/it/weechat_plugin_api.it.asciidoc +++ b/doc/it/weechat_plugin_api.it.asciidoc @@ -63,6 +63,10 @@ WEECHAT_PLUGIN_VERSION("1.0"):: WEECHAT_PLUGIN_LICENSE("GPL3"):: licenza del plugin +// TRANSLATION MISSING +WEECHAT_PLUGIN_PRIORITY(1000):: + the plugin priority (optional, see below) + [[main_functions]] === Funzioni principali @@ -98,6 +102,22 @@ Valori restituiti: * 'WEECHAT_RC_ERROR' se c'è un errore (il plugin NON verrà caricato) +// TRANSLATION MISSING +[[plugin_priority]] +===== Plugin priority + +// TRANSLATION MISSING +When plugins are auto-loaded (for example on startup), WeeChat first loads all +plugins, and then calls the 'init' functions, using the priority defined in +each plugin. A high priority means that the 'init' function is called first. + +Default priority is 1000 (with such priority, the plugin is loaded after all +default plugins). + +The default WeeChat plugins are initialized in this order: + +include::autogen/plugin_api/plugins_priority.asciidoc[] + ==== weechat_plugin_end Questa funzione viene chiamata quando il plugin viene diff --git a/doc/ja/autogen/plugin_api/hdata.asciidoc b/doc/ja/autogen/plugin_api/hdata.asciidoc index 65e1f906e..dbffd4c99 100644 --- a/doc/ja/autogen/plugin_api/hdata.asciidoc +++ b/doc/ja/autogen/plugin_api/hdata.asciidoc @@ -843,6 +843,8 @@ *** 'version' (string) *** 'license' (string) *** 'charset' (string) +*** 'priority' (integer) +*** 'initialized' (integer) *** 'debug' (integer) *** 'prev_plugin' (pointer, hdata: "plugin") *** 'next_plugin' (pointer, hdata: "plugin") diff --git a/doc/ja/autogen/plugin_api/plugins_priority.asciidoc b/doc/ja/autogen/plugin_api/plugins_priority.asciidoc new file mode 100644 index 000000000..d5a171b0b --- /dev/null +++ b/doc/ja/autogen/plugin_api/plugins_priority.asciidoc @@ -0,0 +1,12 @@ +. charset (13000) +. logger (12000) +. exec (11000) +. trigger (10000) +. aspell (9000) +. alias (8000) +. fifo (7000) +. xfer (6000) +. irc (5000) +. relay (4000) +. guile, lua, perl, python, ruby, tcl (3000) +. script (2000) diff --git a/doc/ja/weechat_plugin_api.ja.asciidoc b/doc/ja/weechat_plugin_api.ja.asciidoc index a5e0c0a40..4f88732a9 100644 --- a/doc/ja/weechat_plugin_api.ja.asciidoc +++ b/doc/ja/weechat_plugin_api.ja.asciidoc @@ -62,6 +62,10 @@ WEECHAT_PLUGIN_VERSION("1.0"):: WEECHAT_PLUGIN_LICENSE("GPL3"):: プラグインのライセンス +// TRANSLATION MISSING +WEECHAT_PLUGIN_PRIORITY(1000):: + the plugin priority (optional, see below) + [[main_functions]] === 重要な関数 @@ -93,6 +97,22 @@ int weechat_plugin_init (struct t_weechat_plugin *plugin, * 'WEECHAT_RC_OK' 成功した場合 (プラグインを読み込みます) * 'WEECHAT_RC_ERROR' エラーが起きた場合 (プラグインを読み込みません) +// TRANSLATION MISSING +[[plugin_priority]] +===== Plugin priority + +// TRANSLATION MISSING +When plugins are auto-loaded (for example on startup), WeeChat first loads all +plugins, and then calls the 'init' functions, using the priority defined in +each plugin. A high priority means that the 'init' function is called first. + +Default priority is 1000 (with such priority, the plugin is loaded after all +default plugins). + +The default WeeChat plugins are initialized in this order: + +include::autogen/plugin_api/plugins_priority.asciidoc[] + ==== weechat_plugin_end WeeChat プラグインを再読み込みする際にこの関数を呼び出します。 diff --git a/doc/pl/autogen/plugin_api/hdata.asciidoc b/doc/pl/autogen/plugin_api/hdata.asciidoc index 6e92ef980..bf962a9df 100644 --- a/doc/pl/autogen/plugin_api/hdata.asciidoc +++ b/doc/pl/autogen/plugin_api/hdata.asciidoc @@ -843,6 +843,8 @@ *** 'version' (string) *** 'license' (string) *** 'charset' (string) +*** 'priority' (integer) +*** 'initialized' (integer) *** 'debug' (integer) *** 'prev_plugin' (pointer, hdata: "plugin") *** 'next_plugin' (pointer, hdata: "plugin") diff --git a/doc/pl/autogen/plugin_api/plugins_priority.asciidoc b/doc/pl/autogen/plugin_api/plugins_priority.asciidoc new file mode 100644 index 000000000..d5a171b0b --- /dev/null +++ b/doc/pl/autogen/plugin_api/plugins_priority.asciidoc @@ -0,0 +1,12 @@ +. charset (13000) +. logger (12000) +. exec (11000) +. trigger (10000) +. aspell (9000) +. alias (8000) +. fifo (7000) +. xfer (6000) +. irc (5000) +. relay (4000) +. guile, lua, perl, python, ruby, tcl (3000) +. script (2000) diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 9a2225a21..012254a76 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -4395,7 +4395,7 @@ COMMAND_CALLBACK(plugin) &plugin_argc); } full_name = util_search_full_lib_name (argv[2], "plugins"); - plugin_load (full_name, plugin_argc, plugin_argv); + plugin_load (full_name, 1, plugin_argc, plugin_argv); if (full_name) free (full_name); if (plugin_argv) diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c index b93ebeb00..f36148d49 100644 --- a/src/plugins/alias/alias.c +++ b/src/plugins/alias/alias.c @@ -34,6 +34,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Alias commands")); WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu "); WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); +WEECHAT_PLUGIN_PRIORITY(8000); #define ALIAS_IS_ARG_NUMBER(number) ((number >= '1') && (number <= '9')) diff --git a/src/plugins/aspell/weechat-aspell.c b/src/plugins/aspell/weechat-aspell.c index 0c23ff05c..e6d3bff2b 100644 --- a/src/plugins/aspell/weechat-aspell.c +++ b/src/plugins/aspell/weechat-aspell.c @@ -46,6 +46,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Spell checker for input (with Aspell)")); WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu "); WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); +WEECHAT_PLUGIN_PRIORITY(9000); struct t_weechat_plugin *weechat_aspell_plugin = NULL; diff --git a/src/plugins/charset/charset.c b/src/plugins/charset/charset.c index 599b41c1a..ad275e848 100644 --- a/src/plugins/charset/charset.c +++ b/src/plugins/charset/charset.c @@ -37,6 +37,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Charset conversions")); WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu "); WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); +WEECHAT_PLUGIN_PRIORITY(13000); #define CHARSET_CONFIG_NAME "charset" diff --git a/src/plugins/exec/exec.c b/src/plugins/exec/exec.c index 7cce86265..7363700b4 100644 --- a/src/plugins/exec/exec.c +++ b/src/plugins/exec/exec.c @@ -37,6 +37,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Execution of external commands in WeeChat")); WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu "); WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); +WEECHAT_PLUGIN_PRIORITY(11000); struct t_weechat_plugin *weechat_exec_plugin = NULL; diff --git a/src/plugins/fifo/fifo.c b/src/plugins/fifo/fifo.c index 922099d75..a570742a8 100644 --- a/src/plugins/fifo/fifo.c +++ b/src/plugins/fifo/fifo.c @@ -40,6 +40,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("FIFO pipe for remote control")); WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu "); WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); +WEECHAT_PLUGIN_PRIORITY(7000); #define FIFO_FILENAME_PREFIX "weechat_fifo_" diff --git a/src/plugins/guile/weechat-guile.c b/src/plugins/guile/weechat-guile.c index 9dae6f860..f29a625ee 100644 --- a/src/plugins/guile/weechat-guile.c +++ b/src/plugins/guile/weechat-guile.c @@ -42,6 +42,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Support of scheme scripts (with Guile)")); WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu "); WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); +WEECHAT_PLUGIN_PRIORITY(3000); struct t_weechat_plugin *weechat_guile_plugin = NULL; diff --git a/src/plugins/irc/irc.c b/src/plugins/irc/irc.c index 0f8da74f0..70f2b0978 100644 --- a/src/plugins/irc/irc.c +++ b/src/plugins/irc/irc.c @@ -50,6 +50,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("IRC (Internet Relay Chat) protocol")); WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu "); WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); +WEECHAT_PLUGIN_PRIORITY(5000); struct t_weechat_plugin *weechat_irc_plugin = NULL; diff --git a/src/plugins/logger/logger.c b/src/plugins/logger/logger.c index 0ca04aec1..521adec1d 100644 --- a/src/plugins/logger/logger.c +++ b/src/plugins/logger/logger.c @@ -50,6 +50,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Log buffers to files")); WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu "); WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); +WEECHAT_PLUGIN_PRIORITY(12000); struct t_weechat_plugin *weechat_logger_plugin = NULL; diff --git a/src/plugins/lua/weechat-lua.c b/src/plugins/lua/weechat-lua.c index 233ade22e..354634316 100644 --- a/src/plugins/lua/weechat-lua.c +++ b/src/plugins/lua/weechat-lua.c @@ -39,6 +39,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Support of lua scripts")); WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu "); WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); +WEECHAT_PLUGIN_PRIORITY(3000); struct t_weechat_plugin *weechat_lua_plugin; diff --git a/src/plugins/perl/weechat-perl.c b/src/plugins/perl/weechat-perl.c index d19c84243..c51374553 100644 --- a/src/plugins/perl/weechat-perl.c +++ b/src/plugins/perl/weechat-perl.c @@ -37,6 +37,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Support of perl scripts")); WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu "); WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); +WEECHAT_PLUGIN_PRIORITY(3000); struct t_weechat_plugin *weechat_perl_plugin = NULL; diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 5974b88f9..bf5484b7d 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -36,6 +36,7 @@ #include #include "../core/weechat.h" +#include "../core/wee-arraylist.h" #include "../core/wee-config.h" #include "../core/wee-eval.h" #include "../core/wee-hashtable.h" @@ -281,38 +282,127 @@ plugin_check_autoload (const char *filename) } /* - * Searches for position of plugin (to keep list sorted). + * Returns arguments for plugins (only the relevant arguments for plugins, + * arguments for WeeChat core not returned). + * + * Note: plugin_argv must be freed after use (with free()). */ -struct t_weechat_plugin * -plugin_find_pos (struct t_weechat_plugin *plugin) +void +plugin_get_args (struct t_weechat_plugin *plugin, + int argc, char **argv, + int *plugin_argc, char ***plugin_argv) { - struct t_weechat_plugin *ptr_plugin; + int i, temp_argc; + char **temp_argv; - for (ptr_plugin = weechat_plugins; ptr_plugin; - ptr_plugin = ptr_plugin->next_plugin) + temp_argc = 0; + temp_argv = NULL; + + if (argc > 0) { - if (string_strcasecmp (plugin->name, ptr_plugin->name) < 0) - return ptr_plugin; + temp_argv = malloc ((argc + 1) * sizeof (*temp_argv)); + if (temp_argv) + { + for (i = 0; i < argc; i++) + { + if ((strcmp (argv[i], "-a") == 0) + || (strcmp (argv[i], "--no-connect") == 0) + || (strcmp (argv[i], "-s") == 0) + || (strcmp (argv[i], "--no-script") == 0) + || (strcmp (argv[i], "--upgrade") == 0) + || (strncmp (argv[i], plugin->name, + strlen (plugin->name)) == 0)) + { + temp_argv[temp_argc++] = argv[i]; + } + } + if (temp_argc == 0) + { + free (temp_argv); + temp_argv = NULL; + } + else + temp_argv[temp_argc] = NULL; + } } - return NULL; + + *plugin_argc = temp_argc; + *plugin_argv = temp_argv; +} + +/* + * Initializes a plugin by calling its init() function. + * + * Returns: + * 1: OK + * 0: error + */ + +int +plugin_call_init (struct t_weechat_plugin *plugin, int argc, char **argv) +{ + t_weechat_init_func *init_func; + int plugin_argc, rc; + char **plugin_argv; + + if (plugin->initialized) + return 1; + + /* look for plugin init function */ + init_func = dlsym (plugin->handle, "weechat_plugin_init"); + if (!init_func) + return 0; + + /* get arguments for the plugin */ + plugin_get_args (plugin, argc, argv, &plugin_argc, &plugin_argv); + + /* init plugin */ + if (weechat_debug_core >= 1) + { + gui_chat_printf (NULL, + _("Initializing plugin \"%s\" (priority: %d)"), + plugin->name, + plugin->priority); + } + rc = ((t_weechat_init_func *)init_func) (plugin, + plugin_argc, plugin_argv); + if (rc == WEECHAT_RC_OK) + { + plugin->initialized = 1; + } + else + { + gui_chat_printf (NULL, + _("%sError: unable to initialize plugin " + "\"%s\""), + gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], + plugin->filename); + } + + if (plugin_argv) + free (plugin_argv); + + return (rc == WEECHAT_RC_OK) ? 1 : 0; } /* * Loads a WeeChat plugin (a dynamic library). * + * If init_plugin == 1, then the init() function in plugin is called + * (with argc/argv), otherwise the plugin is just loaded but not initialized. + * * Returns a pointer to new WeeChat plugin, NULL if error. */ struct t_weechat_plugin * -plugin_load (const char *filename, int argc, char **argv) +plugin_load (const char *filename, int init_plugin, int argc, char **argv) { void *handle; char *name, *api_version, *author, *description, *version; char *license, *charset; t_weechat_init_func *init_func; - int rc, i, plugin_argc; - char **plugin_argv; + int *priority; struct t_weechat_plugin *new_plugin; struct t_config_option *ptr_option; @@ -477,6 +567,13 @@ plugin_load (const char *filename, int argc, char **argv) return NULL; } + /* + * look for plugin priority: it is used to initialize plugins in + * appropriate order: the important plugins that don't depend on other + * plugins are initialized first + */ + priority = dlsym (handle, "weechat_plugin_priority"); + /* create new plugin */ new_plugin = malloc (sizeof (*new_plugin)); if (new_plugin) @@ -490,6 +587,9 @@ plugin_load (const char *filename, int argc, char **argv) new_plugin->version = strdup (version); new_plugin->license = strdup (license); new_plugin->charset = (charset) ? strdup (charset) : NULL; + new_plugin->priority = (priority) ? + *priority : PLUGIN_PRIORITY_DEFAULT; + new_plugin->initialized = 0; ptr_option = config_weechat_debug_get (name); new_plugin->debug = (ptr_option) ? CONFIG_INTEGER(ptr_option) : 0; @@ -798,55 +898,14 @@ plugin_load (const char *filename, int argc, char **argv) */ gui_buffer_set_plugin_for_upgrade (name, new_plugin); - /* build arguments for plugin */ - plugin_argc = 0; - plugin_argv = NULL; - if (argc > 0) + if (init_plugin) { - plugin_argv = malloc ((argc + 1) * sizeof (*plugin_argv)); - if (plugin_argv) + if (!plugin_call_init (new_plugin, argc, argv)) { - plugin_argc = 0; - for (i = 0; i < argc; i++) - { - if ((strcmp (argv[i], "-a") == 0) - || (strcmp (argv[i], "--no-connect") == 0) - || (strcmp (argv[i], "-s") == 0) - || (strcmp (argv[i], "--no-script") == 0) - || (strcmp (argv[i], "--upgrade") == 0) - || (strncmp (argv[i], name, strlen (name)) == 0)) - { - plugin_argv[plugin_argc] = argv[i]; - plugin_argc++; - } - } - if (plugin_argc == 0) - { - free (plugin_argv); - plugin_argv = NULL; - } - else - plugin_argv[plugin_argc] = NULL; + plugin_remove (new_plugin); + return NULL; } } - - /* init plugin */ - rc = ((t_weechat_init_func *)init_func) (new_plugin, - plugin_argc, plugin_argv); - - if (plugin_argv) - free (plugin_argv); - - if (rc != WEECHAT_RC_OK) - { - gui_chat_printf (NULL, - _("%sError: unable to initialize plugin " - "\"%s\""), - gui_chat_prefix[GUI_CHAT_PREFIX_ERROR], - filename); - plugin_remove (new_plugin); - return NULL; - } } else { @@ -885,7 +944,28 @@ plugin_auto_load_file (void *args, const char *filename) plugin_args = (struct t_plugin_args *)args; if (plugin_check_extension_allowed (filename)) - plugin_load (filename, plugin_args->argc, plugin_args->argv); + plugin_load (filename, 0, plugin_args->argc, plugin_args->argv); +} + +/* + * Callback used to sort plugins arraylist by priority (high priority first). + */ + +int +plugin_arraylist_cmp_cb (void *data, struct t_arraylist *arraylist, + void *pointer1, void *pointer2) +{ + struct t_weechat_plugin *plugin1, *plugin2; + + /* make C compiler happy */ + (void) data; + (void) arraylist; + + plugin1 = (struct t_weechat_plugin *)pointer1; + plugin2 = (struct t_weechat_plugin *)pointer2; + + return (plugin1->priority > plugin2->priority) ? + -1 : ((plugin1->priority < plugin2->priority) ? 1 : 0); } /* @@ -896,8 +976,10 @@ void plugin_auto_load (int argc, char **argv) { char *dir_name, *plugin_path, *plugin_path2; + struct t_weechat_plugin *ptr_plugin; struct t_plugin_args plugin_args; - int length; + struct t_arraylist *arraylist; + int length, i; plugin_args.argc = argc; plugin_args.argv = argv; @@ -950,6 +1032,36 @@ plugin_auto_load (int argc, char **argv) plugin_autoload_array = NULL; } plugin_autoload_count = 0; + + /* initialize all uninitialized plugins */ + arraylist = arraylist_new (10, 1, 1, + &plugin_arraylist_cmp_cb, NULL, NULL, NULL); + if (arraylist) + { + for (ptr_plugin = weechat_plugins; ptr_plugin; + ptr_plugin = ptr_plugin->next_plugin) + { + arraylist_add (arraylist, ptr_plugin); + } + i = 0; + while (i < arraylist_size (arraylist)) + { + ptr_plugin = arraylist_get (arraylist, i); + if (!ptr_plugin->initialized) + { + if (!plugin_call_init (ptr_plugin, argc, argv)) + { + plugin_remove (ptr_plugin); + arraylist_remove (arraylist, i); + } + else + i++; + } + else + i++; + } + arraylist_free (arraylist); + } } /* @@ -1038,9 +1150,12 @@ plugin_unload (struct t_weechat_plugin *plugin) name = (plugin->name) ? strdup (plugin->name) : NULL; - end_func = dlsym (plugin->handle, "weechat_plugin_end"); - if (end_func) - (void) (end_func) (plugin); + if (plugin->initialized) + { + end_func = dlsym (plugin->handle, "weechat_plugin_end"); + if (end_func) + (void) (end_func) (plugin); + } plugin_remove (plugin); @@ -1118,7 +1233,7 @@ plugin_reload_name (const char *name, int argc, char **argv) if (filename) { plugin_unload (ptr_plugin); - plugin_load (filename, argc, argv); + plugin_load (filename, 1, argc, argv); free (filename); } } @@ -1244,6 +1359,8 @@ plugin_hdata_plugin_cb (void *data, const char *hdata_name) HDATA_VAR(struct t_weechat_plugin, version, STRING, 0, NULL, NULL); HDATA_VAR(struct t_weechat_plugin, license, STRING, 0, NULL, NULL); HDATA_VAR(struct t_weechat_plugin, charset, STRING, 0, NULL, NULL); + HDATA_VAR(struct t_weechat_plugin, priority, INTEGER, 0, NULL, NULL); + HDATA_VAR(struct t_weechat_plugin, initialized, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_weechat_plugin, debug, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_weechat_plugin, prev_plugin, POINTER, 0, NULL, hdata_name); HDATA_VAR(struct t_weechat_plugin, next_plugin, POINTER, 0, NULL, hdata_name); @@ -1296,6 +1413,10 @@ plugin_add_to_infolist (struct t_infolist *infolist, return 0; if (!infolist_new_var_string (ptr_item, "charset", plugin->charset)) return 0; + if (!infolist_new_var_integer (ptr_item, "priority", plugin->priority)) + return 0; + if (!infolist_new_var_integer (ptr_item, "initialized", plugin->initialized)) + return 0; if (!infolist_new_var_integer (ptr_item, "debug", plugin->debug)) return 0; @@ -1322,6 +1443,8 @@ plugin_print_log () log_printf (" description. . . . . . : '%s'", ptr_plugin->description); log_printf (" version. . . . . . . . : '%s'", ptr_plugin->version); log_printf (" charset. . . . . . . . : '%s'", ptr_plugin->charset); + log_printf (" priority . . . . . . . : %d", ptr_plugin->priority); + log_printf (" initialized. . . . . . : %d", ptr_plugin->initialized); log_printf (" debug. . . . . . . . . : %d", ptr_plugin->debug); log_printf (" prev_plugin. . . . . . : 0x%lx", ptr_plugin->prev_plugin); log_printf (" next_plugin. . . . . . : 0x%lx", ptr_plugin->next_plugin); diff --git a/src/plugins/plugin.h b/src/plugins/plugin.h index 1240a1805..08028f95a 100644 --- a/src/plugins/plugin.h +++ b/src/plugins/plugin.h @@ -24,6 +24,8 @@ #define PLUGIN_CORE "core" +#define PLUGIN_PRIORITY_DEFAULT 1000 + typedef int (t_weechat_init_func) (struct t_weechat_plugin *plugin, int argc, char *argv[]); typedef int (t_weechat_end_func) (struct t_weechat_plugin *plugin); @@ -35,6 +37,7 @@ extern int plugin_valid (struct t_weechat_plugin *plugin); extern struct t_weechat_plugin *plugin_search (const char *name); extern const char *plugin_get_name (struct t_weechat_plugin *plugin); extern struct t_weechat_plugin *plugin_load (const char *filename, + int init_plugin, int argc, char **argv); extern void plugin_auto_load (int argc, char **argv); extern void plugin_unload (struct t_weechat_plugin *plugin); diff --git a/src/plugins/python/weechat-python.c b/src/plugins/python/weechat-python.c index 5a8ea1bc0..434bb6536 100644 --- a/src/plugins/python/weechat-python.c +++ b/src/plugins/python/weechat-python.c @@ -39,6 +39,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Support of python scripts")); WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu "); WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); +WEECHAT_PLUGIN_PRIORITY(3000); struct t_weechat_plugin *weechat_python_plugin = NULL; diff --git a/src/plugins/relay/relay.c b/src/plugins/relay/relay.c index cca154afc..ead40834c 100644 --- a/src/plugins/relay/relay.c +++ b/src/plugins/relay/relay.c @@ -42,6 +42,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Relay WeeChat data to remote application " WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu "); WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); +WEECHAT_PLUGIN_PRIORITY(4000); struct t_weechat_plugin *weechat_relay_plugin = NULL; diff --git a/src/plugins/ruby/weechat-ruby.c b/src/plugins/ruby/weechat-ruby.c index 12c1fc880..6be92393e 100644 --- a/src/plugins/ruby/weechat-ruby.c +++ b/src/plugins/ruby/weechat-ruby.c @@ -61,6 +61,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Support of ruby scripts")); WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu "); WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); +WEECHAT_PLUGIN_PRIORITY(3000); struct t_weechat_plugin *weechat_ruby_plugin = NULL; diff --git a/src/plugins/script/script.c b/src/plugins/script/script.c index b1723ebee..8e0c690f8 100644 --- a/src/plugins/script/script.c +++ b/src/plugins/script/script.c @@ -40,6 +40,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Scripts manager")); WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu "); WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); +WEECHAT_PLUGIN_PRIORITY(2000); struct t_weechat_plugin *weechat_script_plugin = NULL; diff --git a/src/plugins/tcl/weechat-tcl.c b/src/plugins/tcl/weechat-tcl.c index f40ebecb0..d72f18572 100644 --- a/src/plugins/tcl/weechat-tcl.c +++ b/src/plugins/tcl/weechat-tcl.c @@ -40,6 +40,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Support of tcl scripts")); WEECHAT_PLUGIN_AUTHOR("Dmitry Kobylin "); WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); +WEECHAT_PLUGIN_PRIORITY(3000); struct t_weechat_plugin *weechat_tcl_plugin = NULL; diff --git a/src/plugins/trigger/trigger.c b/src/plugins/trigger/trigger.c index 8aae71c7c..fb77c3f19 100644 --- a/src/plugins/trigger/trigger.c +++ b/src/plugins/trigger/trigger.c @@ -38,6 +38,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("Text replacement and command execution on events WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu "); WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); +WEECHAT_PLUGIN_PRIORITY(10000); struct t_weechat_plugin *weechat_trigger_plugin = NULL; diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index c1ae5900d..c6ad8e3ec 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -57,7 +57,7 @@ struct timeval; * please change the date with current one; for a second change at same * date, increment the 01, otherwise please keep 01. */ -#define WEECHAT_PLUGIN_API_VERSION "20141122-01" +#define WEECHAT_PLUGIN_API_VERSION "20150114-01" /* macros for defining plugin infos */ #define WEECHAT_PLUGIN_NAME(__name) \ @@ -71,6 +71,8 @@ struct timeval; char weechat_plugin_version[] = __version; #define WEECHAT_PLUGIN_LICENSE(__license) \ char weechat_plugin_license[] = __license; +#define WEECHAT_PLUGIN_PRIORITY(__priority) \ + int weechat_plugin_priority = __priority; /* return codes for plugin functions */ #define WEECHAT_RC_OK 0 @@ -235,6 +237,8 @@ struct t_weechat_plugin char *version; /* plugin version */ char *license; /* license */ char *charset; /* charset used by plugin */ + int priority; /* plugin priority (default is 1000) */ + int initialized; /* plugin initialized? (init called) */ int debug; /* debug level for plugin (0=off) */ struct t_weechat_plugin *prev_plugin; /* link to previous plugin */ struct t_weechat_plugin *next_plugin; /* link to next plugin */ diff --git a/src/plugins/xfer/xfer.c b/src/plugins/xfer/xfer.c index 248b12b49..d7d14c41c 100644 --- a/src/plugins/xfer/xfer.c +++ b/src/plugins/xfer/xfer.c @@ -50,6 +50,7 @@ WEECHAT_PLUGIN_DESCRIPTION(N_("DCC file transfer and direct chat")); WEECHAT_PLUGIN_AUTHOR("Sébastien Helleu "); WEECHAT_PLUGIN_VERSION(WEECHAT_VERSION); WEECHAT_PLUGIN_LICENSE(WEECHAT_LICENSE); +WEECHAT_PLUGIN_PRIORITY(6000); struct t_weechat_plugin *weechat_xfer_plugin = NULL;