diff options
-rw-r--r-- | doc/en/weechat_plugin_api.en.adoc | 384 | ||||
-rw-r--r-- | doc/fr/weechat_plugin_api.fr.adoc | 394 | ||||
-rw-r--r-- | doc/it/weechat_plugin_api.it.adoc | 396 | ||||
-rw-r--r-- | doc/ja/weechat_plugin_api.ja.adoc | 386 | ||||
-rw-r--r-- | src/plugins/guile/weechat-guile-api.c | 208 | ||||
-rw-r--r-- | src/plugins/javascript/weechat-js-api.cpp | 216 | ||||
-rw-r--r-- | src/plugins/lua/weechat-lua-api.c | 224 | ||||
-rw-r--r-- | src/plugins/perl/weechat-perl-api.c | 226 | ||||
-rw-r--r-- | src/plugins/python/weechat-python-api.c | 224 | ||||
-rw-r--r-- | src/plugins/ruby/weechat-ruby-api.c | 272 | ||||
-rw-r--r-- | src/plugins/tcl/weechat-tcl-api.c | 238 |
11 files changed, 1584 insertions, 1584 deletions
diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index d23d0a765..19a21a1eb 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -7187,6 +7187,198 @@ hook = weechat.hook_command("myfilter", "description of myfilter", "my_command_cb", "") ---- +==== hook_completion + +_Updated in 1.5._ + +Hook a completion. + +Prototype: + +[source,C] +---- +struct t_hook *weechat_hook_completion (const char *completion_item, + const char *description, + int (*callback)(const void *pointer, + void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion), + const void *callback_pointer, + void *callback_data); +---- + +Arguments: + +* _completion_item_: name of completion item, after you can use _%(name)_ in + a command hooked (argument _completion_) + (priority allowed, see note about <<hook_priority,priority>>) +* _description_: description of completion +* _callback_: function called when completion item is used (user is completing + something using this item), arguments and return value: +** _const void *pointer_: pointer +** _void *data_: pointer +** _const char *completion_item_: name of completion item +** _struct t_gui_buffer *buffer_: buffer where completion is made +** _struct t_gui_completion *completion_: structure used to add words for + completion (see + <<_hook_completion_list_add,hook_completion_list_add>>) +** return value: +*** _WEECHAT_RC_OK_ +*** _WEECHAT_RC_ERROR_ +* _callback_pointer_: pointer given to callback when it is called by WeeChat +* _callback_data_: pointer given to callback when it is called by WeeChat; + if not NULL, it must have been allocated with malloc (or similar function) + and it is automatically freed when the hook is deleted + +[NOTE] +Completion names are global (shared across WeeChat and plugins). So it is +recommended to choose a name with a unique prefix, like "plugin_xxx" (where +"xxx" is your item name). + +[IMPORTANT] +The callback must only call function <<_hook_completion_list_add,hook_completion_list_add>> +and must *NOT* update the command line. + +To update the command line when kbd:[Tab] is pressed, you can use the function +<<_hook_command_run,hook_command_run>> with command: "/input complete_next" +(and you must return _WEECHAT_RC_OK_EAT_ if your callback has updated the command line, +so that WeeChat will not perform the completion). + +Return value: + +* pointer to new hook, NULL if error occurred + +C example: + +[source,C] +---- +int +my_completion_cb (const void *pointer, void *data, const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + weechat_hook_completion_list_add (completion, "word1", + 0, WEECHAT_LIST_POS_SORT); + weechat_hook_completion_list_add (completion, "test_word2", + 0, WEECHAT_LIST_POS_SORT); + return WEECHAT_RC_OK; +} + +struct t_hook *my_completion_hook = weechat_hook_completion ("plugin_item", + "my custom completion!", + &my_completion_cb, NULL, NULL); +---- + +Script (Python): + +[source,python] +---- +# prototype +hook = weechat.hook_completion(completion_item, description, callback, callback_data) + +# example +def my_completion_cb(data, completion_item, buffer, completion): + weechat.hook_completion_list_add(completion, "word1", 0, weechat.WEECHAT_LIST_POS_SORT) + weechat.hook_completion_list_add(completion, "test_word2", 0, weechat.WEECHAT_LIST_POS_SORT) + return weechat.WEECHAT_RC_OK + +hook = weechat.hook_completion("plugin_item", "my custom completion!", + "my_completion_cb", "") +---- + +==== hook_completion_get_string + +_WeeChat ≥ 0.3.4._ + +Get a completion property as string. + +Prototype: + +[source,C] +---- +const char *weechat_hook_completion_get_string (struct t_gui_completion *completion, + const char *property); +---- + +Arguments: + +* _completion_: completion pointer +* _property_: property name: +** _base_command_: command used for completion +** _base_word_: word being completed +** _args_: command arguments (including base word) + +C example: + +[source,C] +---- +int +my_completion_cb (const void *pointer, void *data, const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + /* get arguments of command */ + const char *args = weechat_hook_completion_get_string (completion, "args"); + + /* completion depending on args */ + /* ... */ + + return WEECHAT_RC_OK; +} +---- + +Script (Python): + +[source,python] +---- +# prototype +value = weechat.hook_completion_get_string(completion, property) + +# example +def my_completion_cb(data, completion_item, buffer, completion): + # get arguments of command + args = weechat.hook_completion_get_string(completion, "args") + # completion depending on args + # ... + return weechat.WEECHAT_RC_OK +---- + +==== hook_completion_list_add + +Add a word for a completion. + +Prototype: + +[source,C] +---- +void weechat_hook_completion_list_add (struct t_gui_completion *completion, + const char *word, + int nick_completion, + const char *where); +---- + +Arguments: + +* _completion_: completion pointer +* _word_: word to add +* _nick_completion_: 1 if word is a nick, otherwise 0 +* _where_: position where word will be inserted in list: +** _WEECHAT_LIST_POS_SORT_: any position, to keep list sorted +** _WEECHAT_LIST_POS_BEGINNING_: beginning of list +** _WEECHAT_LIST_POS_END_: end of list + +C example: see <<_hook_completion,hook_completion>>. + +Script (Python): + +[source,python] +---- +# prototype +weechat.hook_completion_list_add(completion, word, nick_completion, where) + +# example: see function hook_completion above +---- + ==== hook_command_run _Updated in 1.5._ @@ -9493,198 +9685,6 @@ def my_config_cb(data, option, value): hook = weechat.hook_config("weechat.look.item_time_format", "my_config_cb", "") ---- -==== hook_completion - -_Updated in 1.5._ - -Hook a completion. - -Prototype: - -[source,C] ----- -struct t_hook *weechat_hook_completion (const char *completion_item, - const char *description, - int (*callback)(const void *pointer, - void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion), - const void *callback_pointer, - void *callback_data); ----- - -Arguments: - -* _completion_item_: name of completion item, after you can use _%(name)_ in - a command hooked (argument _completion_) - (priority allowed, see note about <<hook_priority,priority>>) -* _description_: description of completion -* _callback_: function called when completion item is used (user is completing - something using this item), arguments and return value: -** _const void *pointer_: pointer -** _void *data_: pointer -** _const char *completion_item_: name of completion item -** _struct t_gui_buffer *buffer_: buffer where completion is made -** _struct t_gui_completion *completion_: structure used to add words for - completion (see - <<_hook_completion_list_add,hook_completion_list_add>>) -** return value: -*** _WEECHAT_RC_OK_ -*** _WEECHAT_RC_ERROR_ -* _callback_pointer_: pointer given to callback when it is called by WeeChat -* _callback_data_: pointer given to callback when it is called by WeeChat; - if not NULL, it must have been allocated with malloc (or similar function) - and it is automatically freed when the hook is deleted - -[NOTE] -Completion names are global (shared across WeeChat and plugins). So it is -recommended to choose a name with a unique prefix, like "plugin_xxx" (where -"xxx" is your item name). - -[IMPORTANT] -The callback must only call function <<_hook_completion_list_add,hook_completion_list_add>> -and must *NOT* update the command line. + -To update the command line when kbd:[Tab] is pressed, you can use the function -<<_hook_command_run,hook_command_run>> with command: "/input complete_next" -(and you must return _WEECHAT_RC_OK_EAT_ if your callback has updated the command line, -so that WeeChat will not perform the completion). - -Return value: - -* pointer to new hook, NULL if error occurred - -C example: - -[source,C] ----- -int -my_completion_cb (const void *pointer, void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - weechat_hook_completion_list_add (completion, "word1", - 0, WEECHAT_LIST_POS_SORT); - weechat_hook_completion_list_add (completion, "test_word2", - 0, WEECHAT_LIST_POS_SORT); - return WEECHAT_RC_OK; -} - -struct t_hook *my_completion_hook = weechat_hook_completion ("plugin_item", - "my custom completion!", - &my_completion_cb, NULL, NULL); ----- - -Script (Python): - -[source,python] ----- -# prototype -hook = weechat.hook_completion(completion_item, description, callback, callback_data) - -# example -def my_completion_cb(data, completion_item, buffer, completion): - weechat.hook_completion_list_add(completion, "word1", 0, weechat.WEECHAT_LIST_POS_SORT) - weechat.hook_completion_list_add(completion, "test_word2", 0, weechat.WEECHAT_LIST_POS_SORT) - return weechat.WEECHAT_RC_OK - -hook = weechat.hook_completion("plugin_item", "my custom completion!", - "my_completion_cb", "") ----- - -==== hook_completion_get_string - -_WeeChat ≥ 0.3.4._ - -Get a completion property as string. - -Prototype: - -[source,C] ----- -const char *weechat_hook_completion_get_string (struct t_gui_completion *completion, - const char *property); ----- - -Arguments: - -* _completion_: completion pointer -* _property_: property name: -** _base_command_: command used for completion -** _base_word_: word being completed -** _args_: command arguments (including base word) - -C example: - -[source,C] ----- -int -my_completion_cb (const void *pointer, void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - /* get arguments of command */ - const char *args = weechat_hook_completion_get_string (completion, "args"); - - /* completion depending on args */ - /* ... */ - - return WEECHAT_RC_OK; -} ----- - -Script (Python): - -[source,python] ----- -# prototype -value = weechat.hook_completion_get_string(completion, property) - -# example -def my_completion_cb(data, completion_item, buffer, completion): - # get arguments of command - args = weechat.hook_completion_get_string(completion, "args") - # completion depending on args - # ... - return weechat.WEECHAT_RC_OK ----- - -==== hook_completion_list_add - -Add a word for a completion. - -Prototype: - -[source,C] ----- -void weechat_hook_completion_list_add (struct t_gui_completion *completion, - const char *word, - int nick_completion, - const char *where); ----- - -Arguments: - -* _completion_: completion pointer -* _word_: word to add -* _nick_completion_: 1 if word is a nick, otherwise 0 -* _where_: position where word will be inserted in list: -** _WEECHAT_LIST_POS_SORT_: any position, to keep list sorted -** _WEECHAT_LIST_POS_BEGINNING_: beginning of list -** _WEECHAT_LIST_POS_END_: end of list - -C example: see <<_hook_completion,hook_completion>>. - -Script (Python): - -[source,python] ----- -# prototype -weechat.hook_completion_list_add(completion, word, nick_completion, where) - -# example: see function hook_completion above ----- - ==== hook_modifier _Updated in 1.5._ diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index c1255d3a7..fdbfa576a 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -7310,6 +7310,203 @@ hook = weechat.hook_command("monfiltre", "description de monfiltre", "my_command_cb", "") ---- +==== hook_completion + +_Mis à jour dans la 1.5._ + +Accrocher une complétion. + +Prototype : + +[source,C] +---- +struct t_hook *weechat_hook_completion (const char *completion_item, + const char *description, + int (*callback)(const void *pointer, + void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion), + const void *callback_pointer, + void *callback_data); +---- + +Paramètres : + +* _completion_item_ : nom de l'objet de complétion, après vous pouvez utiliser + _%(nom)_ dans une commande (paramètre _completion_) + (priorité autorisée, voir la note sur la <<hook_priority,priorité>>) +* _description_ : description de la complétion +* _callback_ : fonction appelée lorsque la complétion est utilisée + (l'utilisateur est en train de compléter quelque chose qui fait appel à cette + complétion), paramètres et valeur de retour : +** _const void *pointer_ : pointeur +** _void *data_ : pointeur +** _const char *completion_item_ : nom de la complétion +** _struct t_gui_buffer *buffer_ : tampon où la complétion est effectuée +** _struct t_gui_completion *completion_ : structure utilisée pour ajouter + les mots pour la complétion (voir + <<_hook_completion_list_add,hook_completion_list_add>>) +** valeur de retour : +*** _WEECHAT_RC_OK_ +*** _WEECHAT_RC_ERROR_ +* _callback_pointer_ : pointeur donné au "callback" lorsqu'il est appelé par + WeeChat +* _callback_data_ : pointeur donné au "callback" lorsqu'il est appelé par + WeeChat; si non NULL, doit avoir été alloué par malloc (ou une fonction + similaire) et est automatiquement libéré (par free) lorsque le "hook" est + supprimé + +[NOTE] +Les noms de complétion sont globaux (partagés entre WeeChat et les extensions). +Il est donc recommandé de choisir un nom avec un préfixe unique, comme +"monextension_xxx" (où "xxx" est le nom de votre complétion). + +[IMPORTANT] +Le "callback" doit seulement appeler la fonction +<<_hook_completion_list_add,hook_completion_list_add>> +et ne doit *PAS* mettre à jour la ligne de commande. + +Pour mettre à jour la ligne de commande quand kbd:[Tab] est pressé, vous pouvez +utiliser la fonction <<_hook_command_run,hook_command_run>> +avec la commande : "/input complete_next" (et vous devez retourner +_WEECHAT_RC_OK_EAT_ si votre "callback" a mis à jour la ligne de commande, de +sorte que WeeChat n'exécute pas la complétion). + +Valeur de retour : + +* pointeur vers le nouveau "hook", NULL en cas d'erreur + +Exemple en C : + +[source,C] +---- +int +my_completion_cb (const void *pointer, void *data, const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + weechat_hook_completion_list_add (completion, "mot1", + 0, WEECHAT_LIST_POS_SORT); + weechat_hook_completion_list_add (completion, "test_mot2", + 0, WEECHAT_LIST_POS_SORT); + return WEECHAT_RC_OK; +} + +struct t_hook *my_completion_hook = weechat_hook_completion ("extension_item", + "ma complétion !", + &my_completion_cb, NULL, NULL); +---- + +Script (Python) : + +[source,python] +---- +# prototype +hook = weechat.hook_completion(completion_item, description, callback, callback_data) + +# exemple +def my_completion_cb(data, completion_item, buffer, completion): + weechat.hook_completion_list_add(completion, "mot1", 0, weechat.WEECHAT_LIST_POS_SORT) + weechat.hook_completion_list_add(completion, "test_mot2", 0, weechat.WEECHAT_LIST_POS_SORT) + return weechat.WEECHAT_RC_OK + +hook = weechat.hook_completion("extension_item", "ma complétion !", + "my_completion_cb", "") +---- + +==== hook_completion_get_string + +_WeeChat ≥ 0.3.4._ + +Retourner la valeur d'une propriété de la complétion sous forme de chaîne. + +Prototype : + +[source,C] +---- +const char *weechat_hook_completion_get_string (struct t_gui_completion *completion, + const char *property); +---- + +Paramètres : + +* _completion_ : pointeur vers la complétion +* _property_ : nom de la propriété : +** _base_command_ : commande utilisée pour la complétion +** _base_word_ : le mot qui va être complété +** _args_ : paramètres de la commande (incluant le mot de base "base_word") + +Exemple en C : + +[source,C] +---- +int +my_completion_cb (const void *pointer, void *data, const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + /* récupère les paramètres de la commande */ + const char *args = weechat_hook_completion_get_string (completion, "args"); + + /* complétion selon les paramètres */ + /* ... */ + + return WEECHAT_RC_OK; +} +---- + +Script (Python) : + +[source,python] +---- +# prototype +value = weechat.hook_completion_get_string(completion, property) + +# exemple +def my_completion_cb(data, completion_item, buffer, completion): + # récupère les paramètres de la commande + args = weechat.hook_completion_get_string(completion, "args") + # complétion selon les paramètres + # ... + return weechat.WEECHAT_RC_OK +---- + +==== hook_completion_list_add + +Ajouter un mot pour une complétion. + +Prototype : + +[source,C] +---- +void weechat_hook_completion_list_add (struct t_gui_completion *completion, + const char *word, + int nick_completion, + const char *where); +---- + +Paramètres : + +* _completion_ : pointeur vers la complétion +* _word_ : mot à ajouter +* _nick_completion_ : 1 si le mot est un pseudo, sinon 0 +* _where_ : position où sera inséré le mot dans la liste : +** _WEECHAT_LIST_POS_SORT_ : n'importe où, pour maintenir la liste triée +** _WEECHAT_LIST_POS_BEGINNING_ : au début de la liste +** _WEECHAT_LIST_POS_END_ : à la fin de la liste + +Exemple en C : voir <<_hook_completion,hook_completion>>. + +Script (Python) : + +[source,python] +---- +# prototype +weechat.hook_completion_list_add(completion, word, nick_completion, where) + +# exemple : voir la fonction hook_completion ci-dessus +---- + ==== hook_command_run _Mis à jour dans la 1.5._ @@ -9683,203 +9880,6 @@ def my_config_cb(data, option, value): hook = weechat.hook_config("weechat.look.item_time_format", "my_config_cb", "") ---- -==== hook_completion - -_Mis à jour dans la 1.5._ - -Accrocher une complétion. - -Prototype : - -[source,C] ----- -struct t_hook *weechat_hook_completion (const char *completion_item, - const char *description, - int (*callback)(const void *pointer, - void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion), - const void *callback_pointer, - void *callback_data); ----- - -Paramètres : - -* _completion_item_ : nom de l'objet de complétion, après vous pouvez utiliser - _%(nom)_ dans une commande (paramètre _completion_) - (priorité autorisée, voir la note sur la <<hook_priority,priorité>>) -* _description_ : description de la complétion -* _callback_ : fonction appelée lorsque la complétion est utilisée - (l'utilisateur est en train de compléter quelque chose qui fait appel à cette - complétion), paramètres et valeur de retour : -** _const void *pointer_ : pointeur -** _void *data_ : pointeur -** _const char *completion_item_ : nom de la complétion -** _struct t_gui_buffer *buffer_ : tampon où la complétion est effectuée -** _struct t_gui_completion *completion_ : structure utilisée pour ajouter - les mots pour la complétion (voir - <<_hook_completion_list_add,hook_completion_list_add>>) -** valeur de retour : -*** _WEECHAT_RC_OK_ -*** _WEECHAT_RC_ERROR_ -* _callback_pointer_ : pointeur donné au "callback" lorsqu'il est appelé par - WeeChat -* _callback_data_ : pointeur donné au "callback" lorsqu'il est appelé par - WeeChat; si non NULL, doit avoir été alloué par malloc (ou une fonction - similaire) et est automatiquement libéré (par free) lorsque le "hook" est - supprimé - -[NOTE] -Les noms de complétion sont globaux (partagés entre WeeChat et les extensions). -Il est donc recommandé de choisir un nom avec un préfixe unique, comme -"monextension_xxx" (où "xxx" est le nom de votre complétion). - -[IMPORTANT] -Le "callback" doit seulement appeler la fonction -<<_hook_completion_list_add,hook_completion_list_add>> -et ne doit *PAS* mettre à jour la ligne de commande. + -Pour mettre à jour la ligne de commande quand kbd:[Tab] est pressé, vous pouvez -utiliser la fonction <<_hook_command_run,hook_command_run>> -avec la commande : "/input complete_next" (et vous devez retourner -_WEECHAT_RC_OK_EAT_ si votre "callback" a mis à jour la ligne de commande, de -sorte que WeeChat n'exécute pas la complétion). - -Valeur de retour : - -* pointeur vers le nouveau "hook", NULL en cas d'erreur - -Exemple en C : - -[source,C] ----- -int -my_completion_cb (const void *pointer, void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - weechat_hook_completion_list_add (completion, "mot1", - 0, WEECHAT_LIST_POS_SORT); - weechat_hook_completion_list_add (completion, "test_mot2", - 0, WEECHAT_LIST_POS_SORT); - return WEECHAT_RC_OK; -} - -struct t_hook *my_completion_hook = weechat_hook_completion ("extension_item", - "ma complétion !", - &my_completion_cb, NULL, NULL); ----- - -Script (Python) : - -[source,python] ----- -# prototype -hook = weechat.hook_completion(completion_item, description, callback, callback_data) - -# exemple -def my_completion_cb(data, completion_item, buffer, completion): - weechat.hook_completion_list_add(completion, "mot1", 0, weechat.WEECHAT_LIST_POS_SORT) - weechat.hook_completion_list_add(completion, "test_mot2", 0, weechat.WEECHAT_LIST_POS_SORT) - return weechat.WEECHAT_RC_OK - -hook = weechat.hook_completion("extension_item", "ma complétion !", - "my_completion_cb", "") ----- - -==== hook_completion_get_string - -_WeeChat ≥ 0.3.4._ - -Retourner la valeur d'une propriété de la complétion sous forme de chaîne. - -Prototype : - -[source,C] ----- -const char *weechat_hook_completion_get_string (struct t_gui_completion *completion, - const char *property); ----- - -Paramètres : - -* _completion_ : pointeur vers la complétion -* _property_ : nom de la propriété : -** _base_command_ : commande utilisée pour la complétion -** _base_word_ : le mot qui va être complété -** _args_ : paramètres de la commande (incluant le mot de base "base_word") - -Exemple en C : - -[source,C] ----- -int -my_completion_cb (const void *pointer, void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - /* récupère les paramètres de la commande */ - const char *args = weechat_hook_completion_get_string (completion, "args"); - - /* complétion selon les paramètres */ - /* ... */ - - return WEECHAT_RC_OK; -} ----- - -Script (Python) : - -[source,python] ----- -# prototype -value = weechat.hook_completion_get_string(completion, property) - -# exemple -def my_completion_cb(data, completion_item, buffer, completion): - # récupère les paramètres de la commande - args = weechat.hook_completion_get_string(completion, "args") - # complétion selon les paramètres - # ... - return weechat.WEECHAT_RC_OK ----- - -==== hook_completion_list_add - -Ajouter un mot pour une complétion. - -Prototype : - -[source,C] ----- -void weechat_hook_completion_list_add (struct t_gui_completion *completion, - const char *word, - int nick_completion, - const char *where); ----- - -Paramètres : - -* _completion_ : pointeur vers la complétion -* _word_ : mot à ajouter -* _nick_completion_ : 1 si le mot est un pseudo, sinon 0 -* _where_ : position où sera inséré le mot dans la liste : -** _WEECHAT_LIST_POS_SORT_ : n'importe où, pour maintenir la liste triée -** _WEECHAT_LIST_POS_BEGINNING_ : au début de la liste -** _WEECHAT_LIST_POS_END_ : à la fin de la liste - -Exemple en C : voir <<_hook_completion,hook_completion>>. - -Script (Python) : - -[source,python] ----- -# prototype -weechat.hook_completion_list_add(completion, word, nick_completion, where) - -# exemple : voir la fonction hook_completion ci-dessus ----- - ==== hook_modifier _Mis à jour dans la 1.5._ diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index 9249664b5..5264657d2 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -7375,6 +7375,204 @@ hook = weechat.hook_command("myfilter", "descrizione di myfilter", "my_command_cb", "") ---- +==== hook_completion + +// TRANSLATION MISSING +_Updated in 1.5._ + +Hook su un completamento. + +Prototipo: + +[source,C] +---- +struct t_hook *weechat_hook_completion (const char *completion_item, + const char *description, + int (*callback)(const void *pointer, + void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion), + const void *callback_pointer, + void *callback_data); +---- + +Argomenti: + +* _completion_item_: nome dell'elemento del completamento, è possibile usare + in seguito _%(name)_ in un comando con un hook (argomento _completion_) + (priorità consentita, consultare la nota riguardo la + <<hook_priority,priority>>) +* _callback_: funzione chiamata quando viene usato l'elemento completamento + (l'utente sta completando qualcosa usando questo elemento), argomenti e valore + restituito: +** _const void *pointer_: puntatore +** _void *data_: puntatore +** _const char *completion_item_: nome dell'elemento del completamento +** _struct t_gui_buffer *buffer_: buffer dove viene eseguito il completamento +** _struct t_gui_completion *completion_: struttura usata per aggiungere + parole per il completamento (consultare + <<_hook_completion_list_add,hook_completion_list_add>>) +** valore restituito: +*** _WEECHAT_RC_OK_ +*** _WEECHAT_RC_ERROR_ +* _callback_pointer_: puntatore fornito alla callback quando chiamata da WeeChat +// TRANSLATION MISSING +* _callback_data_: puntatore fornito alla callback quando chiamata da WeeChat; + if not NULL, it must have been allocated with malloc (or similar function) + and it is automatically freed when the hook is deleted + +[NOTE] +I nomi del completamento sono globali (condivisi tra WeeChat e plugin). Si +raccomanda pertanto di scegliere un nome con un prefisso unico, come +"plugin_xxx" (dove "xxx" è il nome del proprio elemento). + +// TRANSLATION MISSING +[IMPORTANT] +The callback must only call function +<<_hook_completion_list_add,hook_completion_list_add>> +and must *NOT* update the command line. + +To update the command line when kbd:[Tab] is pressed, you can use the function +<<_hook_command_run,hook_command_run>> with command: +"/input complete_next" (and you must return _WEECHAT_RC_OK_EAT_ if your callback +has updated the command line, so that WeeChat will not perform the completion). + +Valore restituito: + +* puntatore al nuovo hook, NULL in caso di errore + +Esempio in C: + +[source,C] +---- +int +my_completion_cb (const void *pointer, void *data, const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + weechat_hook_completion_list_add (completion, "word1", + 0, WEECHAT_LIST_POS_SORT); + weechat_hook_completion_list_add (completion, "test_word2", + 0, WEECHAT_LIST_POS_SORT); + return WEECHAT_RC_OK; +} + +struct t_hook *my_completion_hook = weechat_hook_completion ("plugin_item", + "my custom completion!", + &my_completion_cb, NULL, NULL); +---- + +Script (Python): + +[source,python] +---- +# prototipo +hook = weechat.hook_completion(completion_item, description, callback, callback_data) + +# esempio +def my_completion_cb(data, completion_item, buffer, completion): + weechat.hook_completion_list_add(completion, "word1", 0, weechat.WEECHAT_LIST_POS_SORT) + weechat.hook_completion_list_add(completion, "test_word2", 0, weechat.WEECHAT_LIST_POS_SORT) + return weechat.WEECHAT_RC_OK + +hook = weechat.hook_completion("plugin_item", "my custom completion!", + "my_completion_cb", "") +---- + +==== hook_completion_get_string + +_Novità nella versioe 0.3.4._ + +Ottiene il completamento di una proprietà come stringa. + +Prototipo: + +[source,C] +---- +const char *weechat_hook_completion_get_string (struct t_gui_completion *completion, + const char *property); +---- + +Argomenti: + +* _completion_: puntatore al completamento +* _property_: nome della proprietà: +** _base_command_: comando usato per il completamento +** _base_word_: parola che viene completata +** _args_: argomenti del comando (inclusa la parola base) + +Esempio in C: + +[source,C] +---- +int +my_completion_cb (const void *pointer, void *data, const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + /* ottiene l'argomento del comando */ + const char *args = weechat_hook_completion_get_string (completion, "args"); + + /* completamento che dipende dagli argomenti */ + /* ... */ + + return WEECHAT_RC_OK; +} +---- + +Script (Python): + +[source,python] +---- +# prototipo +value = weechat.hook_completion_get_string(completion, property) + +# esempio +def my_completion_cb(data, completion_item, buffer, completion): + # ottiene l'argomento del comando + args = weechat.hook_completion_get_string(completion, "args") + # completamento che dipende dagli argomenti + # ... + return weechat.WEECHAT_RC_OK +---- + +==== hook_completion_list_add + +Aggiunge una parola per il completamento. + +Prototipo: + +[source,C] +---- +void weechat_hook_completion_list_add (struct t_gui_completion *completion, + const char *word, + int nick_completion, + const char *where); +---- + +Argomenti: + +* _completion_: puntatore al completamento +* _word_: parola da aggiungere +* _nick_completion_: 1 se la parola è un nick, altrimenti 0 +* _where_: posizione in cui la parola sarà inserita nella lista: +** _WEECHAT_LIST_POS_SORT_: qualunque posizione, per mantenere + la lista ordinata +** _WEECHAT_LIST_POS_BEGINNING_: inizio della lista +** _WEECHAT_LIST_POS_END_: fine della lista + +Esempio in C: consultare <<_hook_completion,hook_completion>>. + +Script (Python): + +[source,python] +---- +# prototipo +weechat.hook_completion_list_add(completion, word, nick_completion, where) + +# esempio: consultare function hook_completion precedente +---- + ==== hook_command_run // TRANSLATION MISSING @@ -9840,204 +10038,6 @@ def my_config_cb(data, option, value): hook = weechat.hook_config("weechat.look.item_time_format", "my_config_cb", "") ---- -==== hook_completion - -// TRANSLATION MISSING -_Updated in 1.5._ - -Hook su un completamento. - -Prototipo: - -[source,C] ----- -struct t_hook *weechat_hook_completion (const char *completion_item, - const char *description, - int (*callback)(const void *pointer, - void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion), - const void *callback_pointer, - void *callback_data); ----- - -Argomenti: - -* _completion_item_: nome dell'elemento del completamento, è possibile usare - in seguito _%(name)_ in un comando con un hook (argomento _completion_) - (priorità consentita, consultare la nota riguardo la - <<hook_priority,priority>>) -* _callback_: funzione chiamata quando viene usato l'elemento completamento - (l'utente sta completando qualcosa usando questo elemento), argomenti e valore - restituito: -** _const void *pointer_: puntatore -** _void *data_: puntatore -** _const char *completion_item_: nome dell'elemento del completamento -** _struct t_gui_buffer *buffer_: buffer dove viene eseguito il completamento -** _struct t_gui_completion *completion_: struttura usata per aggiungere - parole per il completamento (consultare - <<_hook_completion_list_add,hook_completion_list_add>>) -** valore restituito: -*** _WEECHAT_RC_OK_ -*** _WEECHAT_RC_ERROR_ -* _callback_pointer_: puntatore fornito alla callback quando chiamata da WeeChat -// TRANSLATION MISSING -* _callback_data_: puntatore fornito alla callback quando chiamata da WeeChat; - if not NULL, it must have been allocated with malloc (or similar function) - and it is automatically freed when the hook is deleted - -[NOTE] -I nomi del completamento sono globali (condivisi tra WeeChat e plugin). Si -raccomanda pertanto di scegliere un nome con un prefisso unico, come -"plugin_xxx" (dove "xxx" è il nome del proprio elemento). - -// TRANSLATION MISSING -[IMPORTANT] -The callback must only call function -<<_hook_completion_list_add,hook_completion_list_add>> -and must *NOT* update the command line. + -To update the command line when kbd:[Tab] is pressed, you can use the function -<<_hook_command_run,hook_command_run>> with command: -"/input complete_next" (and you must return _WEECHAT_RC_OK_EAT_ if your callback -has updated the command line, so that WeeChat will not perform the completion). - -Valore restituito: - -* puntatore al nuovo hook, NULL in caso di errore - -Esempio in C: - -[source,C] ----- -int -my_completion_cb (const void *pointer, void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - weechat_hook_completion_list_add (completion, "word1", - 0, WEECHAT_LIST_POS_SORT); - weechat_hook_completion_list_add (completion, "test_word2", - 0, WEECHAT_LIST_POS_SORT); - return WEECHAT_RC_OK; -} - -struct t_hook *my_completion_hook = weechat_hook_completion ("plugin_item", - "my custom completion!", - &my_completion_cb, NULL, NULL); ----- - -Script (Python): - -[source,python] ----- -# prototipo -hook = weechat.hook_completion(completion_item, description, callback, callback_data) - -# esempio -def my_completion_cb(data, completion_item, buffer, completion): - weechat.hook_completion_list_add(completion, "word1", 0, weechat.WEECHAT_LIST_POS_SORT) - weechat.hook_completion_list_add(completion, "test_word2", 0, weechat.WEECHAT_LIST_POS_SORT) - return weechat.WEECHAT_RC_OK - -hook = weechat.hook_completion("plugin_item", "my custom completion!", - "my_completion_cb", "") ----- - -==== hook_completion_get_string - -_Novità nella versioe 0.3.4._ - -Ottiene il completamento di una proprietà come stringa. - -Prototipo: - -[source,C] ----- -const char *weechat_hook_completion_get_string (struct t_gui_completion *completion, - const char *property); ----- - -Argomenti: - -* _completion_: puntatore al completamento -* _property_: nome della proprietà: -** _base_command_: comando usato per il completamento -** _base_word_: parola che viene completata -** _args_: argomenti del comando (inclusa la parola base) - -Esempio in C: - -[source,C] ----- -int -my_completion_cb (const void *pointer, void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - /* ottiene l'argomento del comando */ - const char *args = weechat_hook_completion_get_string (completion, "args"); - - /* completamento che dipende dagli argomenti */ - /* ... */ - - return WEECHAT_RC_OK; -} ----- - -Script (Python): - -[source,python] ----- -# prototipo -value = weechat.hook_completion_get_string(completion, property) - -# esempio -def my_completion_cb(data, completion_item, buffer, completion): - # ottiene l'argomento del comando - args = weechat.hook_completion_get_string(completion, "args") - # completamento che dipende dagli argomenti - # ... - return weechat.WEECHAT_RC_OK ----- - -==== hook_completion_list_add - -Aggiunge una parola per il completamento. - -Prototipo: - -[source,C] ----- -void weechat_hook_completion_list_add (struct t_gui_completion *completion, - const char *word, - int nick_completion, - const char *where); ----- - -Argomenti: - -* _completion_: puntatore al completamento -* _word_: parola da aggiungere -* _nick_completion_: 1 se la parola è un nick, altrimenti 0 -* _where_: posizione in cui la parola sarà inserita nella lista: -** _WEECHAT_LIST_POS_SORT_: qualunque posizione, per mantenere - la lista ordinata -** _WEECHAT_LIST_POS_BEGINNING_: inizio della lista -** _WEECHAT_LIST_POS_END_: fine della lista - -Esempio in C: consultare <<_hook_completion,hook_completion>>. - -Script (Python): - -[source,python] ----- -# prototipo -weechat.hook_completion_list_add(completion, word, nick_completion, where) - -# esempio: consultare function hook_completion precedente ----- - ==== hook_modifier // TRANSLATION MISSING diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index b662efea1..3dfb5fefe 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -7192,6 +7192,199 @@ hook = weechat.hook_command("myfilter", "description of myfilter", "my_command_cb", "") ---- +==== hook_completion + +_WeeChat バージョン 1.5 で更新。_ + +補完をフック。 + +プロトタイプ: + +[source,C] +---- +struct t_hook *weechat_hook_completion (const char *completion_item, + const char *description, + int (*callback)(const void *pointer, + void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion), + const void *callback_pointer, + void *callback_data); +---- + +引数: + +* _completion_item_: 補完要素の名前、この後フックされたコマンドで + _%(name)_ を使うことができます (_completion_ 引数) + (優先度の設定が可能、<<hook_priority,優先度>>に関する注意を参照) +* _description_: 補完の説明 +* _callback_: 補完要素 (ユーザはこの要素を使って何かを補完している) + が使われた場合に呼び出すコールバック関数、引数と戻り値: +** _const void *pointer_: ポインタ +** _void *data_: ポインタ +** _const char *completion_item_: 補完要素の名前 +** _struct t_gui_buffer *buffer_: 補完が行われたバッファ +** _struct t_gui_completion *completion_: + 補完に際して単語を追加するために使われる構造体 + (<<_hook_completion_list_add,hook_completion_list_add>> を参照) +** 戻り値: +*** _WEECHAT_RC_OK_ +*** _WEECHAT_RC_ERROR_ +* _callback_pointer_: WeeChat が _callback_ コールバックを呼び出す際にコールバックに渡すポインタ +* _callback_data_: WeeChat が _callback_ コールバックを呼び出す際にコールバックに渡すポインタ; + このポインタが NULL でない場合、このポインタは malloc (または類似の関数) + によって割り当てられたものでなければいけません。さらに、このポインタはここで作成したフックが削除された時点で自動的に開放されます + +[NOTE] +補完名はグローバルです (WeeChat +とプラグインで共有されます)。このため、"plugin_xxx" (ここで "xxx" は要素の名前) +などの一意的なプレフィックスをつけた名前を使うことをおすすめします。 + +[IMPORTANT] +コールバックは +<<_hook_completion_list_add,hook_completion_list_add>> +関数を呼び出すだけで、コマンドラインをコールバックで絶対に *変更しない* でください。 + +kbd:[Tab] が押された時にコマンドラインを更新するためには、関数 +<<_hook_command_run,hook_command_run>> を使ってコマンド +"/input complete_next" をフックしてください (コールバックがコマンドラインを更新する場合は必ず +_WEECHAT_RC_OK_EAT_ を返してください。そうすれば WeeChat は補完を行いません)。 + +戻り値: + +* 新しいフックへのポインタ、エラーが起きた場合は NULL + +C 言語での使用例: + +[source,C] +---- +int +my_completion_cb (const void *pointer, void *data, const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + weechat_hook_completion_list_add (completion, "word1", + 0, WEECHAT_LIST_POS_SORT); + weechat_hook_completion_list_add (completion, "test_word2", + 0, WEECHAT_LIST_POS_SORT); + return WEECHAT_RC_OK; +} + +struct t_hook *my_completion_hook = weechat_hook_completion ("plugin_item", + "my custom completion!", + &my_completion_cb, NULL, NULL); +---- + +スクリプト (Python) での使用例: + +[source,python] +---- +# プロトタイプ +hook = weechat.hook_completion(completion_item, description, callback, callback_data) + +# 例 +def my_completion_cb(data, completion_item, buffer, completion): + weechat.hook_completion_list_add(completion, "word1", 0, weechat.WEECHAT_LIST_POS_SORT) + weechat.hook_completion_list_add(completion, "test_word2", 0, weechat.WEECHAT_LIST_POS_SORT) + return weechat.WEECHAT_RC_OK + +hook = weechat.hook_completion("plugin_item", "my custom completion!", + "my_completion_cb", "") +---- + +==== hook_completion_get_string + +_WeeChat バージョン 0.3.4 以上で利用可。_ + +補完プロパティを文字列で取得。 + +プロトタイプ: + +[source,C] +---- +const char *weechat_hook_completion_get_string (struct t_gui_completion *completion, + const char *property); +---- + +引数: + +* _completion_: 補完へのポインタ +* _property_: プロパティ名: +** _base_command_: 補完に使ったコマンド +** _base_word_: 補完された単語 +** _args_: コマンド引数 (元の単語を含む) + +C 言語での使用例: + +[source,C] +---- +int +my_completion_cb (const void *pointer, void *data, const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + /* get arguments of command */ + const char *args = weechat_hook_completion_get_string (completion, "args"); + + /* completion depending on args */ + /* ... */ + + return WEECHAT_RC_OK; +} +---- + +スクリプト (Python) での使用例: + +[source,python] +---- +# プロトタイプ +value = weechat.hook_completion_get_string(completion, property) + +# 例 +def my_completion_cb(data, completion_item, buffer, completion): + # get arguments of command + args = weechat.hook_completion_get_string(completion, "args") + # completion depending on args + # ... + return weechat.WEECHAT_RC_OK +---- + +==== hook_completion_list_add + +補完用に単語を追加。 + +プロトタイプ: + +[source,C] +---- +void weechat_hook_completion_list_add (struct t_gui_completion *completion, + const char *word, + int nick_completion, + const char *where); +---- + +引数: + +* _completion_: 補完へのポインタ +* _word_: 追加する単語 +* _nick_completion_: 単語がニックネームの場合は 1、そうでなければ 0 +* _where_: 単語を追加するリスト上での位置: +** _WEECHAT_LIST_POS_SORT_: リストがソートされた状態になるような位置 +** _WEECHAT_LIST_POS_BEGINNING_: リストの最初 +** _WEECHAT_LIST_POS_END_: リストの最後 + +C 言語での使用例: <<_hook_completion,hook_completion>> を参照。 + +スクリプト (Python) での使用例: + +[source,python] +---- +# プロトタイプ +weechat.hook_completion_list_add(completion, word, nick_completion, where) + +# 例: 前の hook_completion 関数を参照 +---- + ==== hook_command_run _WeeChat バージョン 1.5 で更新。_ @@ -9499,199 +9692,6 @@ def my_config_cb(data, option, value): hook = weechat.hook_config("weechat.look.item_time_format", "my_config_cb", "") ---- -==== hook_completion - -_WeeChat バージョン 1.5 で更新。_ - -補完をフック。 - -プロトタイプ: - -[source,C] ----- -struct t_hook *weechat_hook_completion (const char *completion_item, - const char *description, - int (*callback)(const void *pointer, - void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion), - const void *callback_pointer, - void *callback_data); ----- - -引数: - -* _completion_item_: 補完要素の名前、この後フックされたコマンドで - _%(name)_ を使うことができます (_completion_ 引数) - (優先度の設定が可能、<<hook_priority,優先度>>に関する注意を参照) -* _description_: 補完の説明 -* _callback_: 補完要素 (ユーザはこの要素を使って何かを補完している) - が使われた場合に呼び出すコールバック関数、引数と戻り値: -** _const void *pointer_: ポインタ -** _void *data_: ポインタ -** _const char *completion_item_: 補完要素の名前 -** _struct t_gui_buffer *buffer_: 補完が行われたバッファ -** _struct t_gui_completion *completion_: - 補完に際して単語を追加するために使われる構造体 - (<<_hook_completion_list_add,hook_completion_list_add>> を参照) -** 戻り値: -*** _WEECHAT_RC_OK_ -*** _WEECHAT_RC_ERROR_ -* _callback_pointer_: WeeChat が _callback_ コールバックを呼び出す際にコールバックに渡すポインタ -* _callback_data_: WeeChat が _callback_ コールバックを呼び出す際にコールバックに渡すポインタ; - このポインタが NULL でない場合、このポインタは malloc (または類似の関数) - によって割り当てられたものでなければいけません。さらに、このポインタはここで作成したフックが削除された時点で自動的に開放されます - -[NOTE] -補完名はグローバルです (WeeChat -とプラグインで共有されます)。このため、"plugin_xxx" (ここで "xxx" は要素の名前) -などの一意的なプレフィックスをつけた名前を使うことをおすすめします。 - -[IMPORTANT] -コールバックは -<<_hook_completion_list_add,hook_completion_list_add>> -関数を呼び出すだけで、コマンドラインをコールバックで絶対に *変更しない* でください。 + -kbd:[Tab] が押された時にコマンドラインを更新するためには、関数 -<<_hook_command_run,hook_command_run>> を使ってコマンド -"/input complete_next" をフックしてください (コールバックがコマンドラインを更新する場合は必ず -_WEECHAT_RC_OK_EAT_ を返してください。そうすれば WeeChat は補完を行いません)。 - -戻り値: - -* 新しいフックへのポインタ、エラーが起きた場合は NULL - -C 言語での使用例: - -[source,C] ----- -int -my_completion_cb (const void *pointer, void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - weechat_hook_completion_list_add (completion, "word1", - 0, WEECHAT_LIST_POS_SORT); - weechat_hook_completion_list_add (completion, "test_word2", - 0, WEECHAT_LIST_POS_SORT); - return WEECHAT_RC_OK; -} - -struct t_hook *my_completion_hook = weechat_hook_completion ("plugin_item", - "my custom completion!", - &my_completion_cb, NULL, NULL); ----- - -スクリプト (Python) での使用例: - -[source,python] ----- -# プロトタイプ -hook = weechat.hook_completion(completion_item, description, callback, callback_data) - -# 例 -def my_completion_cb(data, completion_item, buffer, completion): - weechat.hook_completion_list_add(completion, "word1", 0, weechat.WEECHAT_LIST_POS_SORT) - weechat.hook_completion_list_add(completion, "test_word2", 0, weechat.WEECHAT_LIST_POS_SORT) - return weechat.WEECHAT_RC_OK - -hook = weechat.hook_completion("plugin_item", "my custom completion!", - "my_completion_cb", "") ----- - -==== hook_completion_get_string - -_WeeChat バージョン 0.3.4 以上で利用可。_ - -補完プロパティを文字列で取得。 - -プロトタイプ: - -[source,C] ----- -const char *weechat_hook_completion_get_string (struct t_gui_completion *completion, - const char *property); ----- - -引数: - -* _completion_: 補完へのポインタ -* _property_: プロパティ名: -** _base_command_: 補完に使ったコマンド -** _base_word_: 補完された単語 -** _args_: コマンド引数 (元の単語を含む) - -C 言語での使用例: - -[source,C] ----- -int -my_completion_cb (const void *pointer, void *data, const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - /* get arguments of command */ - const char *args = weechat_hook_completion_get_string (completion, "args"); - - /* completion depending on args */ - /* ... */ - - return WEECHAT_RC_OK; -} ----- - -スクリプト (Python) での使用例: - -[source,python] ----- -# プロトタイプ -value = weechat.hook_completion_get_string(completion, property) - -# 例 -def my_completion_cb(data, completion_item, buffer, completion): - # get arguments of command - args = weechat.hook_completion_get_string(completion, "args") - # completion depending on args - # ... - return weechat.WEECHAT_RC_OK ----- - -==== hook_completion_list_add - -補完用に単語を追加。 - -プロトタイプ: - -[source,C] ----- -void weechat_hook_completion_list_add (struct t_gui_completion *completion, - const char *word, - int nick_completion, - const char *where); ----- - -引数: - -* _completion_: 補完へのポインタ -* _word_: 追加する単語 -* _nick_completion_: 単語がニックネームの場合は 1、そうでなければ 0 -* _where_: 単語を追加するリスト上での位置: -** _WEECHAT_LIST_POS_SORT_: リストがソートされた状態になるような位置 -** _WEECHAT_LIST_POS_BEGINNING_: リストの最初 -** _WEECHAT_LIST_POS_END_: リストの最後 - -C 言語での使用例: <<_hook_completion,hook_completion>> を参照。 - -スクリプト (Python) での使用例: - -[source,python] ----- -# プロトタイプ -weechat.hook_completion_list_add(completion, word, nick_completion, where) - -# 例: 前の hook_completion 関数を参照 ----- - ==== hook_modifier _WeeChat バージョン 1.5 で更新。_ diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c index acf0f8080..0199ec4fc 100644 --- a/src/plugins/guile/weechat-guile-api.c +++ b/src/plugins/guile/weechat-guile-api.c @@ -1974,6 +1974,107 @@ weechat_guile_api_hook_command (SCM command, SCM description, SCM args, } int +weechat_guile_api_hook_completion_cb (const void *pointer, void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + struct t_plugin_script *script; + void *func_argv[4]; + char empty_arg[1] = { '\0' }; + const char *ptr_function, *ptr_data; + int *rc, ret; + + script = (struct t_plugin_script *)pointer; + plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); + + if (ptr_function && ptr_function[0]) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; + func_argv[2] = API_PTR2STR(buffer); + func_argv[3] = API_PTR2STR(completion); + + rc = (int *) weechat_guile_exec (script, + WEECHAT_SCRIPT_EXEC_INT, + ptr_function, + "ssss", func_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (func_argv[2]) + free (func_argv[2]); + if (func_argv[3]) + free (func_argv[3]); + + return ret; + } + + return WEECHAT_RC_ERROR; +} + +SCM +weechat_guile_api_hook_completion (SCM completion, SCM description, + SCM function, SCM data) +{ + char *result; + SCM return_value; + + API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); + if (!scm_is_string (completion) || !scm_is_string (description) + || !scm_is_string (function) || !scm_is_string (data)) + API_WRONG_ARGS(API_RETURN_EMPTY); + + result = API_PTR2STR(plugin_script_api_hook_completion (weechat_guile_plugin, + guile_current_script, + API_SCM_TO_STRING(completion), + API_SCM_TO_STRING(description), + &weechat_guile_api_hook_completion_cb, + API_SCM_TO_STRING(function), + API_SCM_TO_STRING(data))); + + API_RETURN_STRING_FREE(result); +} + +SCM +weechat_guile_api_hook_completion_get_string (SCM completion, SCM property) +{ + const char *result; + + API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); + if (!scm_is_string (completion) || !scm_is_string (property)) + API_WRONG_ARGS(API_RETURN_EMPTY); + + result = weechat_hook_completion_get_string ( + API_STR2PTR(API_SCM_TO_STRING(completion)), + API_SCM_TO_STRING(property)); + + API_RETURN_STRING(result); +} + +SCM +weechat_guile_api_hook_completion_list_add (SCM completion, SCM word, + SCM nick_completion, SCM where) +{ + API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); + if (!scm_is_string (completion) || !scm_is_string (word) + || !scm_is_integer (nick_completion) || !scm_is_string (where)) + API_WRONG_ARGS(API_RETURN_ERROR); + + weechat_hook_completion_list_add (API_STR2PTR(API_SCM_TO_STRING(completion)), + API_SCM_TO_STRING(word), + scm_to_int (nick_completion), + API_SCM_TO_STRING(where)); + + API_RETURN_OK; +} + +int weechat_guile_api_hook_command_run_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, const char *command) @@ -2715,107 +2816,6 @@ weechat_guile_api_hook_config (SCM option, SCM function, SCM data) API_RETURN_STRING_FREE(result); } -int -weechat_guile_api_hook_completion_cb (const void *pointer, void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_plugin_script *script; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - const char *ptr_function, *ptr_data; - int *rc, ret; - - script = (struct t_plugin_script *)pointer; - plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - - if (ptr_function && ptr_function[0]) - { - func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = API_PTR2STR(buffer); - func_argv[3] = API_PTR2STR(completion); - - rc = (int *) weechat_guile_exec (script, - WEECHAT_SCRIPT_EXEC_INT, - ptr_function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -SCM -weechat_guile_api_hook_completion (SCM completion, SCM description, - SCM function, SCM data) -{ - char *result; - SCM return_value; - - API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); - if (!scm_is_string (completion) || !scm_is_string (description) - || !scm_is_string (function) || !scm_is_string (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = API_PTR2STR(plugin_script_api_hook_completion (weechat_guile_plugin, - guile_current_script, - API_SCM_TO_STRING(completion), - API_SCM_TO_STRING(description), - &weechat_guile_api_hook_completion_cb, - API_SCM_TO_STRING(function), - API_SCM_TO_STRING(data))); - - API_RETURN_STRING_FREE(result); -} - -SCM -weechat_guile_api_hook_completion_get_string (SCM completion, SCM property) -{ - const char *result; - - API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); - if (!scm_is_string (completion) || !scm_is_string (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_hook_completion_get_string ( - API_STR2PTR(API_SCM_TO_STRING(completion)), - API_SCM_TO_STRING(property)); - - API_RETURN_STRING(result); -} - -SCM -weechat_guile_api_hook_completion_list_add (SCM completion, SCM word, - SCM nick_completion, SCM where) -{ - API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); - if (!scm_is_string (completion) || !scm_is_string (word) - || !scm_is_integer (nick_completion) || !scm_is_string (where)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_hook_completion_list_add (API_STR2PTR(API_SCM_TO_STRING(completion)), - API_SCM_TO_STRING(word), - scm_to_int (nick_completion), - API_SCM_TO_STRING(where)); - - API_RETURN_OK; -} - char * weechat_guile_api_hook_modifier_cb (const void *pointer, void *data, const char *modifier, @@ -4886,6 +4886,9 @@ weechat_guile_api_module_init (void *data) API_DEF_FUNC(print_y, 3); API_DEF_FUNC(log_print, 1); API_DEF_FUNC(hook_command, 7); + API_DEF_FUNC(hook_completion, 4); + API_DEF_FUNC(hook_completion_get_string, 2); + API_DEF_FUNC(hook_completion_list_add, 4); API_DEF_FUNC(hook_command_run, 3); API_DEF_FUNC(hook_timer, 5); API_DEF_FUNC(hook_fd, 6); @@ -4898,9 +4901,6 @@ weechat_guile_api_module_init (void *data) API_DEF_FUNC(hook_hsignal, 3); API_DEF_FUNC(hook_hsignal_send, 2); API_DEF_FUNC(hook_config, 3); - API_DEF_FUNC(hook_completion, 4); - API_DEF_FUNC(hook_completion_get_string, 2); - API_DEF_FUNC(hook_completion_list_add, 4); API_DEF_FUNC(hook_modifier, 3); API_DEF_FUNC(hook_modifier_exec, 3); API_DEF_FUNC(hook_info, 5); diff --git a/src/plugins/javascript/weechat-js-api.cpp b/src/plugins/javascript/weechat-js-api.cpp index 4a09b130b..7199dee8b 100644 --- a/src/plugins/javascript/weechat-js-api.cpp +++ b/src/plugins/javascript/weechat-js-api.cpp @@ -1882,6 +1882,111 @@ API_FUNC(hook_command) } int +weechat_js_api_hook_completion_cb (const void *pointer, void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + struct t_plugin_script *script; + void *func_argv[4]; + char empty_arg[1] = { '\0' }; + const char *ptr_function, *ptr_data; + int *rc, ret; + + script = (struct t_plugin_script *)pointer; + plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); + + if (ptr_function && ptr_function[0]) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; + func_argv[2] = API_PTR2STR(buffer); + func_argv[3] = API_PTR2STR(completion); + + rc = (int *)weechat_js_exec (script, + WEECHAT_SCRIPT_EXEC_INT, + ptr_function, + "ssss", func_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (func_argv[2]) + free (func_argv[2]); + if (func_argv[3]) + free (func_argv[3]); + + return ret; + } + + return WEECHAT_RC_ERROR; +} + +API_FUNC(hook_completion) +{ + char *result; + + API_INIT_FUNC(1, "hook_completion", "ssss", API_RETURN_EMPTY); + + v8::String::Utf8Value completion(args[0]); + v8::String::Utf8Value description(args[1]); + v8::String::Utf8Value function(args[2]); + v8::String::Utf8Value data(args[3]); + + result = API_PTR2STR( + plugin_script_api_hook_completion ( + weechat_js_plugin, + js_current_script, + *completion, + *description, + &weechat_js_api_hook_completion_cb, + *function, + *data)); + + API_RETURN_STRING_FREE(result); +} + +API_FUNC(hook_completion_get_string) +{ + const char *result; + + API_INIT_FUNC(1, "hook_completion_get_string", "ss", API_RETURN_EMPTY); + + v8::String::Utf8Value completion(args[0]); + v8::String::Utf8Value property(args[1]); + + result = weechat_hook_completion_get_string ( + (struct t_gui_completion *)API_STR2PTR(*completion), + *property); + + API_RETURN_STRING(result); +} + +API_FUNC(hook_completion_list_add) +{ + int nick_completion; + + API_INIT_FUNC(1, "hook_completion_list_add", "ssis", API_RETURN_ERROR); + + v8::String::Utf8Value completion(args[0]); + v8::String::Utf8Value word(args[1]); + nick_completion = args[2]->IntegerValue(); + v8::String::Utf8Value where(args[3]); + + weechat_hook_completion_list_add ( + (struct t_gui_completion *)API_STR2PTR(*completion), + *word, + nick_completion, + *where); + + API_RETURN_OK; +} + +int weechat_js_api_hook_command_run_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, const char *command) @@ -2635,111 +2740,6 @@ API_FUNC(hook_config) API_RETURN_STRING_FREE(result); } -int -weechat_js_api_hook_completion_cb (const void *pointer, void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_plugin_script *script; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - const char *ptr_function, *ptr_data; - int *rc, ret; - - script = (struct t_plugin_script *)pointer; - plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - - if (ptr_function && ptr_function[0]) - { - func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = API_PTR2STR(buffer); - func_argv[3] = API_PTR2STR(completion); - - rc = (int *)weechat_js_exec (script, - WEECHAT_SCRIPT_EXEC_INT, - ptr_function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -API_FUNC(hook_completion) -{ - char *result; - - API_INIT_FUNC(1, "hook_completion", "ssss", API_RETURN_EMPTY); - - v8::String::Utf8Value completion(args[0]); - v8::String::Utf8Value description(args[1]); - v8::String::Utf8Value function(args[2]); - v8::String::Utf8Value data(args[3]); - - result = API_PTR2STR( - plugin_script_api_hook_completion ( - weechat_js_plugin, - js_current_script, - *completion, - *description, - &weechat_js_api_hook_completion_cb, - *function, - *data)); - - API_RETURN_STRING_FREE(result); -} - -API_FUNC(hook_completion_get_string) -{ - const char *result; - - API_INIT_FUNC(1, "hook_completion_get_string", "ss", API_RETURN_EMPTY); - - v8::String::Utf8Value completion(args[0]); - v8::String::Utf8Value property(args[1]); - - result = weechat_hook_completion_get_string ( - (struct t_gui_completion *)API_STR2PTR(*completion), - *property); - - API_RETURN_STRING(result); -} - -API_FUNC(hook_completion_list_add) -{ - int nick_completion; - - API_INIT_FUNC(1, "hook_completion_list_add", "ssis", API_RETURN_ERROR); - - v8::String::Utf8Value completion(args[0]); - v8::String::Utf8Value word(args[1]); - nick_completion = args[2]->IntegerValue(); - v8::String::Utf8Value where(args[3]); - - weechat_hook_completion_list_add ( - (struct t_gui_completion *)API_STR2PTR(*completion), - *word, - nick_completion, - *where); - - API_RETURN_OK; -} - char * weechat_js_api_hook_modifier_cb (const void *pointer, void *data, const char *modifier, @@ -4861,6 +4861,9 @@ WeechatJsV8::loadLibs() API_DEF_FUNC(print_y); API_DEF_FUNC(log_print); API_DEF_FUNC(hook_command); + API_DEF_FUNC(hook_completion); + API_DEF_FUNC(hook_completion_get_string); + API_DEF_FUNC(hook_completion_list_add); API_DEF_FUNC(hook_command_run); API_DEF_FUNC(hook_timer); API_DEF_FUNC(hook_fd); @@ -4873,9 +4876,6 @@ WeechatJsV8::loadLibs() API_DEF_FUNC(hook_hsignal); API_DEF_FUNC(hook_hsignal_send); API_DEF_FUNC(hook_config); - API_DEF_FUNC(hook_completion); - API_DEF_FUNC(hook_completion_get_string); - API_DEF_FUNC(hook_completion_list_add); API_DEF_FUNC(hook_modifier); API_DEF_FUNC(hook_modifier_exec); API_DEF_FUNC(hook_info); diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c index ab3dcc163..8f0addf14 100644 --- a/src/plugins/lua/weechat-lua-api.c +++ b/src/plugins/lua/weechat-lua-api.c @@ -2071,6 +2071,115 @@ API_FUNC(hook_command) } int +weechat_lua_api_hook_completion_cb (const void *pointer, void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + struct t_plugin_script *script; + void *func_argv[4]; + char empty_arg[1] = { '\0' }; + const char *ptr_function, *ptr_data; + int *rc, ret; + + script = (struct t_plugin_script *)pointer; + plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); + + if (ptr_function && ptr_function[0]) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; + func_argv[2] = API_PTR2STR(buffer); + func_argv[3] = API_PTR2STR(completion); + + rc = (int *) weechat_lua_exec (script, + WEECHAT_SCRIPT_EXEC_INT, + ptr_function, + "ssss", func_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (func_argv[2]) + free (func_argv[2]); + if (func_argv[3]) + free (func_argv[3]); + + return ret; + } + + return WEECHAT_RC_ERROR; +} + +API_FUNC(hook_completion) +{ + const char *completion, *description, *function, *data; + char *result; + + API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); + if (lua_gettop (L) < 4) + API_WRONG_ARGS(API_RETURN_EMPTY); + + completion = lua_tostring (L, -4); + description = lua_tostring (L, -3); + function = lua_tostring (L, -2); + data = lua_tostring (L, -1); + + result = API_PTR2STR(plugin_script_api_hook_completion (weechat_lua_plugin, + lua_current_script, + completion, + description, + &weechat_lua_api_hook_completion_cb, + function, + data)); + + API_RETURN_STRING_FREE(result); +} + +API_FUNC(hook_completion_get_string) +{ + const char *completion, *property, *result; + + API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); + if (lua_gettop (L) < 2) + API_WRONG_ARGS(API_RETURN_EMPTY); + + completion = lua_tostring (L, -2); + property = lua_tostring (L, -1); + + result = weechat_hook_completion_get_string (API_STR2PTR(completion), + property); + + API_RETURN_STRING(result); +} + +API_FUNC(hook_completion_list_add) +{ + const char *completion, *word, *where; + int nick_completion; + + API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); + if (lua_gettop (L) < 4) + API_WRONG_ARGS(API_RETURN_ERROR); + + completion = lua_tostring (L, -4); + word = lua_tostring (L, -3); + nick_completion = lua_tonumber (L, -2); + where = lua_tostring (L, -1); + + weechat_hook_completion_list_add (API_STR2PTR(completion), + word, + nick_completion, + where); + + API_RETURN_OK; +} + +int weechat_lua_api_hook_command_run_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, const char *command) @@ -2836,115 +2945,6 @@ API_FUNC(hook_config) API_RETURN_STRING_FREE(result); } -int -weechat_lua_api_hook_completion_cb (const void *pointer, void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_plugin_script *script; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - const char *ptr_function, *ptr_data; - int *rc, ret; - - script = (struct t_plugin_script *)pointer; - plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - - if (ptr_function && ptr_function[0]) - { - func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = API_PTR2STR(buffer); - func_argv[3] = API_PTR2STR(completion); - - rc = (int *) weechat_lua_exec (script, - WEECHAT_SCRIPT_EXEC_INT, - ptr_function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -API_FUNC(hook_completion) -{ - const char *completion, *description, *function, *data; - char *result; - - API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); - if (lua_gettop (L) < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - completion = lua_tostring (L, -4); - description = lua_tostring (L, -3); - function = lua_tostring (L, -2); - data = lua_tostring (L, -1); - - result = API_PTR2STR(plugin_script_api_hook_completion (weechat_lua_plugin, - lua_current_script, - completion, - description, - &weechat_lua_api_hook_completion_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -API_FUNC(hook_completion_get_string) -{ - const char *completion, *property, *result; - - API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); - if (lua_gettop (L) < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - completion = lua_tostring (L, -2); - property = lua_tostring (L, -1); - - result = weechat_hook_completion_get_string (API_STR2PTR(completion), - property); - - API_RETURN_STRING(result); -} - -API_FUNC(hook_completion_list_add) -{ - const char *completion, *word, *where; - int nick_completion; - - API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); - if (lua_gettop (L) < 4) - API_WRONG_ARGS(API_RETURN_ERROR); - - completion = lua_tostring (L, -4); - word = lua_tostring (L, -3); - nick_completion = lua_tonumber (L, -2); - where = lua_tostring (L, -1); - - weechat_hook_completion_list_add (API_STR2PTR(completion), - word, - nick_completion, - where); - - API_RETURN_OK; -} - char * weechat_lua_api_hook_modifier_cb (const void *pointer, void *data, const char *modifier, @@ -5184,6 +5184,9 @@ const struct luaL_Reg weechat_lua_api_funcs[] = { API_DEF_FUNC(print_y), API_DEF_FUNC(log_print), API_DEF_FUNC(hook_command), + API_DEF_FUNC(hook_completion), + API_DEF_FUNC(hook_completion_get_string), + API_DEF_FUNC(hook_completion_list_add), API_DEF_FUNC(hook_command_run), API_DEF_FUNC(hook_timer), API_DEF_FUNC(hook_fd), @@ -5196,9 +5199,6 @@ const struct luaL_Reg weechat_lua_api_funcs[] = { API_DEF_FUNC(hook_hsignal), API_DEF_FUNC(hook_hsignal_send), API_DEF_FUNC(hook_config), - API_DEF_FUNC(hook_completion), - API_DEF_FUNC(hook_completion_get_string), - API_DEF_FUNC(hook_completion_list_add), API_DEF_FUNC(hook_modifier), API_DEF_FUNC(hook_modifier_exec), API_DEF_FUNC(hook_info), diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c index 4233f70c6..1de7fad67 100644 --- a/src/plugins/perl/weechat-perl-api.c +++ b/src/plugins/perl/weechat-perl-api.c @@ -2007,6 +2007,116 @@ API_FUNC(hook_command) } int +weechat_perl_api_hook_completion_cb (const void *pointer, void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + struct t_plugin_script *script; + void *func_argv[4]; + char empty_arg[1] = { '\0' }; + const char *ptr_function, *ptr_data; + int *rc, ret; + + script = (struct t_plugin_script *)pointer; + plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); + + if (ptr_function && ptr_function[0]) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; + func_argv[2] = API_PTR2STR(buffer); + func_argv[3] = API_PTR2STR(completion); + + rc = (int *) weechat_perl_exec (script, + WEECHAT_SCRIPT_EXEC_INT, + ptr_function, + "ssss", func_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (func_argv[2]) + free (func_argv[2]); + if (func_argv[3]) + free (func_argv[3]); + + return ret; + } + + return WEECHAT_RC_ERROR; +} + +API_FUNC(hook_completion) +{ + char *result, *completion, *description, *function, *data; + dXSARGS; + + API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); + if (items < 4) + API_WRONG_ARGS(API_RETURN_EMPTY); + + completion = SvPV_nolen (ST (0)); + description = SvPV_nolen (ST (1)); + function = SvPV_nolen (ST (2)); + data = SvPV_nolen (ST (3)); + + result = API_PTR2STR(plugin_script_api_hook_completion (weechat_perl_plugin, + perl_current_script, + completion, + description, + &weechat_perl_api_hook_completion_cb, + function, + data)); + + API_RETURN_STRING_FREE(result); +} + +API_FUNC(hook_completion_get_string) +{ + char *completion, *property; + const char *result; + dXSARGS; + + API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); + if (items < 2) + API_WRONG_ARGS(API_RETURN_EMPTY); + + completion = SvPV_nolen (ST (0)); + property = SvPV_nolen (ST (1)); + + result = weechat_hook_completion_get_string (API_STR2PTR(completion), + property); + + API_RETURN_STRING(result); +} + +API_FUNC(hook_completion_list_add) +{ + char *completion, *word, *where; + dXSARGS; + + API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); + if (items < 4) + API_WRONG_ARGS(API_RETURN_ERROR); + + completion = SvPV_nolen (ST (0)); + word = SvPV_nolen (ST (1)); + where = SvPV_nolen (ST (3)); + + weechat_hook_completion_list_add (API_STR2PTR(completion), + word, + SvIV (ST (2)), /* nick_completion */ + where); + + API_RETURN_OK; +} + +int weechat_perl_api_hook_command_run_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, const char *command) @@ -2749,116 +2859,6 @@ API_FUNC(hook_config) API_RETURN_STRING_FREE(result); } -int -weechat_perl_api_hook_completion_cb (const void *pointer, void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_plugin_script *script; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - const char *ptr_function, *ptr_data; - int *rc, ret; - - script = (struct t_plugin_script *)pointer; - plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - - if (ptr_function && ptr_function[0]) - { - func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = API_PTR2STR(buffer); - func_argv[3] = API_PTR2STR(completion); - - rc = (int *) weechat_perl_exec (script, - WEECHAT_SCRIPT_EXEC_INT, - ptr_function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -API_FUNC(hook_completion) -{ - char *result, *completion, *description, *function, *data; - dXSARGS; - - API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); - if (items < 4) - API_WRONG_ARGS(API_RETURN_EMPTY); - - completion = SvPV_nolen (ST (0)); - description = SvPV_nolen (ST (1)); - function = SvPV_nolen (ST (2)); - data = SvPV_nolen (ST (3)); - - result = API_PTR2STR(plugin_script_api_hook_completion (weechat_perl_plugin, - perl_current_script, - completion, - description, - &weechat_perl_api_hook_completion_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -API_FUNC(hook_completion_get_string) -{ - char *completion, *property; - const char *result; - dXSARGS; - - API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); - if (items < 2) - API_WRONG_ARGS(API_RETURN_EMPTY); - - completion = SvPV_nolen (ST (0)); - property = SvPV_nolen (ST (1)); - - result = weechat_hook_completion_get_string (API_STR2PTR(completion), - property); - - API_RETURN_STRING(result); -} - -API_FUNC(hook_completion_list_add) -{ - char *completion, *word, *where; - dXSARGS; - - API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); - if (items < 4) - API_WRONG_ARGS(API_RETURN_ERROR); - - completion = SvPV_nolen (ST (0)); - word = SvPV_nolen (ST (1)); - where = SvPV_nolen (ST (3)); - - weechat_hook_completion_list_add (API_STR2PTR(completion), - word, - SvIV (ST (2)), /* nick_completion */ - where); - - API_RETURN_OK; -} - char * weechat_perl_api_hook_modifier_cb (const void *pointer, void *data, const char *modifier, @@ -5124,6 +5124,9 @@ weechat_perl_api_init (pTHX) API_DEF_FUNC(print_y); API_DEF_FUNC(log_print); API_DEF_FUNC(hook_command); + API_DEF_FUNC(hook_completion); + API_DEF_FUNC(hook_completion_get_string); + API_DEF_FUNC(hook_completion_list_add); API_DEF_FUNC(hook_command_run); API_DEF_FUNC(hook_timer); API_DEF_FUNC(hook_fd); @@ -5136,9 +5139,6 @@ weechat_perl_api_init (pTHX) API_DEF_FUNC(hook_hsignal); API_DEF_FUNC(hook_hsignal_send); API_DEF_FUNC(hook_config); - API_DEF_FUNC(hook_completion); - API_DEF_FUNC(hook_completion_get_string); - API_DEF_FUNC(hook_completion_list_add); API_DEF_FUNC(hook_modifier); API_DEF_FUNC(hook_modifier_exec); API_DEF_FUNC(hook_info); diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c index 23acaba0b..d9cd74862 100644 --- a/src/plugins/python/weechat-python-api.c +++ b/src/plugins/python/weechat-python-api.c @@ -2003,6 +2003,115 @@ API_FUNC(hook_command) } int +weechat_python_api_hook_completion_cb (const void *pointer, void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + struct t_plugin_script *script; + void *func_argv[4]; + char empty_arg[1] = { '\0' }; + const char *ptr_function, *ptr_data; + int *rc, ret; + + script = (struct t_plugin_script *)pointer; + plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); + + if (ptr_function && ptr_function[0]) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; + func_argv[2] = API_PTR2STR(buffer); + func_argv[3] = API_PTR2STR(completion); + + rc = (int *) weechat_python_exec (script, + WEECHAT_SCRIPT_EXEC_INT, + ptr_function, + "ssss", func_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (func_argv[2]) + free (func_argv[2]); + if (func_argv[3]) + free (func_argv[3]); + + return ret; + } + + return WEECHAT_RC_ERROR; +} + +API_FUNC(hook_completion) +{ + char *completion, *description, *function, *data, *result; + PyObject *return_value; + + API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); + completion = NULL; + description = NULL; + function = NULL; + data = NULL; + if (!PyArg_ParseTuple (args, "ssss", &completion, &description, &function, + &data)) + API_WRONG_ARGS(API_RETURN_EMPTY); + + result = API_PTR2STR(plugin_script_api_hook_completion (weechat_python_plugin, + python_current_script, + completion, + description, + &weechat_python_api_hook_completion_cb, + function, + data)); + + API_RETURN_STRING_FREE(result); +} + +API_FUNC(hook_completion_get_string) +{ + char *completion, *property; + const char *result; + + API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); + completion = NULL; + property = NULL; + if (!PyArg_ParseTuple (args, "ss", &completion, &property)) + API_WRONG_ARGS(API_RETURN_EMPTY); + + result = weechat_hook_completion_get_string (API_STR2PTR(completion), + property); + + API_RETURN_STRING(result); +} + +API_FUNC(hook_completion_list_add) +{ + char *completion, *word, *where; + int nick_completion; + + API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); + completion = NULL; + word = NULL; + nick_completion = 0; + where = NULL; + if (!PyArg_ParseTuple (args, "ssis", &completion, &word, &nick_completion, + &where)) + API_WRONG_ARGS(API_RETURN_ERROR); + + weechat_hook_completion_list_add (API_STR2PTR(completion), + word, + nick_completion, + where); + + API_RETURN_OK; +} + +int weechat_python_api_hook_command_run_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, const char *command) @@ -2782,115 +2891,6 @@ API_FUNC(hook_config) API_RETURN_STRING_FREE(result); } -int -weechat_python_api_hook_completion_cb (const void *pointer, void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_plugin_script *script; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - const char *ptr_function, *ptr_data; - int *rc, ret; - - script = (struct t_plugin_script *)pointer; - plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - - if (ptr_function && ptr_function[0]) - { - func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = API_PTR2STR(buffer); - func_argv[3] = API_PTR2STR(completion); - - rc = (int *) weechat_python_exec (script, - WEECHAT_SCRIPT_EXEC_INT, - ptr_function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -API_FUNC(hook_completion) -{ - char *completion, *description, *function, *data, *result; - PyObject *return_value; - - API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); - completion = NULL; - description = NULL; - function = NULL; - data = NULL; - if (!PyArg_ParseTuple (args, "ssss", &completion, &description, &function, - &data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = API_PTR2STR(plugin_script_api_hook_completion (weechat_python_plugin, - python_current_script, - completion, - description, - &weechat_python_api_hook_completion_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -API_FUNC(hook_completion_get_string) -{ - char *completion, *property; - const char *result; - - API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); - completion = NULL; - property = NULL; - if (!PyArg_ParseTuple (args, "ss", &completion, &property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - result = weechat_hook_completion_get_string (API_STR2PTR(completion), - property); - - API_RETURN_STRING(result); -} - -API_FUNC(hook_completion_list_add) -{ - char *completion, *word, *where; - int nick_completion; - - API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); - completion = NULL; - word = NULL; - nick_completion = 0; - where = NULL; - if (!PyArg_ParseTuple (args, "ssis", &completion, &word, &nick_completion, - &where)) - API_WRONG_ARGS(API_RETURN_ERROR); - - weechat_hook_completion_list_add (API_STR2PTR(completion), - word, - nick_completion, - where); - - API_RETURN_OK; -} - char * weechat_python_api_hook_modifier_cb (const void *pointer, void *data, const char *modifier, @@ -5100,6 +5100,9 @@ PyMethodDef weechat_python_funcs[] = API_DEF_FUNC(prnt_y), API_DEF_FUNC(log_print), API_DEF_FUNC(hook_command), + API_DEF_FUNC(hook_completion), + API_DEF_FUNC(hook_completion_get_string), + API_DEF_FUNC(hook_completion_list_add), API_DEF_FUNC(hook_command_run), API_DEF_FUNC(hook_timer), API_DEF_FUNC(hook_fd), @@ -5112,9 +5115,6 @@ PyMethodDef weechat_python_funcs[] = API_DEF_FUNC(hook_hsignal), API_DEF_FUNC(hook_hsignal_send), API_DEF_FUNC(hook_config), - API_DEF_FUNC(hook_completion), - API_DEF_FUNC(hook_completion_get_string), - API_DEF_FUNC(hook_completion_list_add), API_DEF_FUNC(hook_modifier), API_DEF_FUNC(hook_modifier_exec), API_DEF_FUNC(hook_info), diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c index 9b705afba..38324aa68 100644 --- a/src/plugins/ruby/weechat-ruby-api.c +++ b/src/plugins/ruby/weechat-ruby-api.c @@ -2451,6 +2451,139 @@ weechat_ruby_api_hook_command (VALUE class, VALUE command, VALUE description, } int +weechat_ruby_api_hook_completion_cb (const void *pointer, void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + struct t_plugin_script *script; + void *func_argv[4]; + char empty_arg[1] = { '\0' }; + const char *ptr_function, *ptr_data; + int *rc, ret; + + script = (struct t_plugin_script *)pointer; + plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); + + if (ptr_function && ptr_function[0]) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; + func_argv[2] = API_PTR2STR(buffer); + func_argv[3] = API_PTR2STR(completion); + + rc = (int *) weechat_ruby_exec (script, + WEECHAT_SCRIPT_EXEC_INT, + ptr_function, + "ssss", func_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (func_argv[2]) + free (func_argv[2]); + if (func_argv[3]) + free (func_argv[3]); + + return ret; + } + + return WEECHAT_RC_ERROR; +} + +static VALUE +weechat_ruby_api_hook_completion (VALUE class, VALUE completion, + VALUE description, VALUE function, + VALUE data) +{ + char *c_completion, *c_description, *c_function, *c_data, *result; + VALUE return_value; + + API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); + if (NIL_P (completion) || NIL_P (description) || NIL_P (function) + || NIL_P (data)) + API_WRONG_ARGS(API_RETURN_EMPTY); + + Check_Type (completion, T_STRING); + Check_Type (description, T_STRING); + Check_Type (function, T_STRING); + Check_Type (data, T_STRING); + + c_completion = StringValuePtr (completion); + c_description = StringValuePtr (description); + c_function = StringValuePtr (function); + c_data = StringValuePtr (data); + + result = API_PTR2STR(plugin_script_api_hook_completion (weechat_ruby_plugin, + ruby_current_script, + c_completion, + c_description, + &weechat_ruby_api_hook_completion_cb, + c_function, + c_data)); + + API_RETURN_STRING_FREE(result); +} + +static VALUE +weechat_ruby_api_hook_completion_get_string (VALUE class, VALUE completion, + VALUE property) +{ + char *c_completion, *c_property; + const char *result; + + API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); + if (NIL_P (completion) || NIL_P (property)) + API_WRONG_ARGS(API_RETURN_EMPTY); + + Check_Type (completion, T_STRING); + Check_Type (property, T_STRING); + + c_completion = StringValuePtr (completion); + c_property = StringValuePtr (property); + + result = weechat_hook_completion_get_string (API_STR2PTR(c_completion), + c_property); + + API_RETURN_STRING(result); +} + +static VALUE +weechat_ruby_api_hook_completion_list_add (VALUE class, VALUE completion, + VALUE word, VALUE nick_completion, + VALUE where) +{ + char *c_completion, *c_word, *c_where; + int c_nick_completion; + + API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); + if (NIL_P (completion) || NIL_P (word) || NIL_P (nick_completion) + || NIL_P (where)) + API_WRONG_ARGS(API_RETURN_ERROR); + + Check_Type (completion, T_STRING); + Check_Type (word, T_STRING); + Check_Type (nick_completion, T_FIXNUM); + Check_Type (where, T_STRING); + + c_completion = StringValuePtr (completion); + c_word = StringValuePtr (word); + c_nick_completion = FIX2INT (nick_completion); + c_where = StringValuePtr (where); + + weechat_hook_completion_list_add (API_STR2PTR(c_completion), + c_word, + c_nick_completion, + c_where); + + API_RETURN_OK; +} + +int weechat_ruby_api_hook_command_run_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, const char *command) @@ -3312,139 +3445,6 @@ weechat_ruby_api_hook_config (VALUE class, VALUE option, VALUE function, API_RETURN_STRING_FREE(result); } -int -weechat_ruby_api_hook_completion_cb (const void *pointer, void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_plugin_script *script; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - const char *ptr_function, *ptr_data; - int *rc, ret; - - script = (struct t_plugin_script *)pointer; - plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - - if (ptr_function && ptr_function[0]) - { - func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = API_PTR2STR(buffer); - func_argv[3] = API_PTR2STR(completion); - - rc = (int *) weechat_ruby_exec (script, - WEECHAT_SCRIPT_EXEC_INT, - ptr_function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -static VALUE -weechat_ruby_api_hook_completion (VALUE class, VALUE completion, - VALUE description, VALUE function, - VALUE data) -{ - char *c_completion, *c_description, *c_function, *c_data, *result; - VALUE return_value; - - API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); - if (NIL_P (completion) || NIL_P (description) || NIL_P (function) - || NIL_P (data)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (completion, T_STRING); - Check_Type (description, T_STRING); - Check_Type (function, T_STRING); - Check_Type (data, T_STRING); - - c_completion = StringValuePtr (completion); - c_description = StringValuePtr (description); - c_function = StringValuePtr (function); - c_data = StringValuePtr (data); - - result = API_PTR2STR(plugin_script_api_hook_completion (weechat_ruby_plugin, - ruby_current_script, - c_completion, - c_description, - &weechat_ruby_api_hook_completion_cb, - c_function, - c_data)); - - API_RETURN_STRING_FREE(result); -} - -static VALUE -weechat_ruby_api_hook_completion_get_string (VALUE class, VALUE completion, - VALUE property) -{ - char *c_completion, *c_property; - const char *result; - - API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); - if (NIL_P (completion) || NIL_P (property)) - API_WRONG_ARGS(API_RETURN_EMPTY); - - Check_Type (completion, T_STRING); - Check_Type (property, T_STRING); - - c_completion = StringValuePtr (completion); - c_property = StringValuePtr (property); - - result = weechat_hook_completion_get_string (API_STR2PTR(c_completion), - c_property); - - API_RETURN_STRING(result); -} - -static VALUE -weechat_ruby_api_hook_completion_list_add (VALUE class, VALUE completion, - VALUE word, VALUE nick_completion, - VALUE where) -{ - char *c_completion, *c_word, *c_where; - int c_nick_completion; - - API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); - if (NIL_P (completion) || NIL_P (word) || NIL_P (nick_completion) - || NIL_P (where)) - API_WRONG_ARGS(API_RETURN_ERROR); - - Check_Type (completion, T_STRING); - Check_Type (word, T_STRING); - Check_Type (nick_completion, T_FIXNUM); - Check_Type (where, T_STRING); - - c_completion = StringValuePtr (completion); - c_word = StringValuePtr (word); - c_nick_completion = FIX2INT (nick_completion); - c_where = StringValuePtr (where); - - weechat_hook_completion_list_add (API_STR2PTR(c_completion), - c_word, - c_nick_completion, - c_where); - - API_RETURN_OK; -} - char * weechat_ruby_api_hook_modifier_cb (const void *pointer, void *data, const char *modifier, @@ -6246,6 +6246,9 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) API_DEF_FUNC(print_y, 3); API_DEF_FUNC(log_print, 1); API_DEF_FUNC(hook_command, 7); + API_DEF_FUNC(hook_completion, 4); + API_DEF_FUNC(hook_completion_get_string, 2); + API_DEF_FUNC(hook_completion_list_add, 4); API_DEF_FUNC(hook_command_run, 3); API_DEF_FUNC(hook_timer, 5); API_DEF_FUNC(hook_fd, 6); @@ -6258,9 +6261,6 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) API_DEF_FUNC(hook_hsignal, 3); API_DEF_FUNC(hook_hsignal_send, 2); API_DEF_FUNC(hook_config, 3); - API_DEF_FUNC(hook_completion, 4); - API_DEF_FUNC(hook_completion_get_string, 2); - API_DEF_FUNC(hook_completion_list_add, 4); API_DEF_FUNC(hook_modifier, 3); API_DEF_FUNC(hook_modifier_exec, 3); API_DEF_FUNC(hook_info, 5); diff --git a/src/plugins/tcl/weechat-tcl-api.c b/src/plugins/tcl/weechat-tcl-api.c index 75db35ab3..f9b23cc5f 100644 --- a/src/plugins/tcl/weechat-tcl-api.c +++ b/src/plugins/tcl/weechat-tcl-api.c @@ -2244,6 +2244,122 @@ API_FUNC(hook_command) } int +weechat_tcl_api_hook_completion_cb (const void *pointer, void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + struct t_plugin_script *script; + void *func_argv[4]; + char empty_arg[1] = { '\0' }; + const char *ptr_function, *ptr_data; + int *rc, ret; + + script = (struct t_plugin_script *)pointer; + plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); + + if (ptr_function && ptr_function[0]) + { + func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; + func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; + func_argv[2] = API_PTR2STR(buffer); + func_argv[3] = API_PTR2STR(completion); + + rc = (int *) weechat_tcl_exec (script, + WEECHAT_SCRIPT_EXEC_INT, + ptr_function, + "ssss", func_argv); + + if (!rc) + ret = WEECHAT_RC_ERROR; + else + { + ret = *rc; + free (rc); + } + if (func_argv[2]) + free (func_argv[2]); + if (func_argv[3]) + free (func_argv[3]); + + return ret; + } + + return WEECHAT_RC_ERROR; +} + +API_FUNC(hook_completion) +{ + Tcl_Obj *objp; + char *result, *completion, *description, *function, *data; + int i; + + API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); + if (objc < 5) + API_WRONG_ARGS(API_RETURN_EMPTY); + + completion = Tcl_GetStringFromObj (objv[1], &i); + description = Tcl_GetStringFromObj (objv[2], &i); + function = Tcl_GetStringFromObj (objv[3], &i); + data = Tcl_GetStringFromObj (objv[4], &i); + + result = API_PTR2STR(plugin_script_api_hook_completion (weechat_tcl_plugin, + tcl_current_script, + completion, + description, + &weechat_tcl_api_hook_completion_cb, + function, + data)); + + API_RETURN_STRING_FREE(result); +} + +API_FUNC(hook_completion_get_string) +{ + Tcl_Obj *objp; + char *completion, *property; + const char *result; + int i; + + API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); + if (objc < 3) + API_WRONG_ARGS(API_RETURN_EMPTY); + + completion = Tcl_GetStringFromObj (objv[1], &i); + property = Tcl_GetStringFromObj (objv[2], &i); + + result = weechat_hook_completion_get_string (API_STR2PTR(completion), + property); + + API_RETURN_STRING(result); +} + +API_FUNC(hook_completion_list_add) +{ + Tcl_Obj *objp; + char *completion, *word, *where; + int i, nick_completion; + + API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); + if (objc < 5) + API_WRONG_ARGS(API_RETURN_ERROR); + + if (Tcl_GetIntFromObj (interp, objv[3], &nick_completion) != TCL_OK) + API_WRONG_ARGS(API_RETURN_ERROR); + + completion = Tcl_GetStringFromObj (objv[1], &i); + word = Tcl_GetStringFromObj (objv[2], &i); + where = Tcl_GetStringFromObj (objv[4], &i); + + weechat_hook_completion_list_add (API_STR2PTR(completion), + word, + nick_completion, /* nick_completion */ + where); + + API_RETURN_OK; +} + +int weechat_tcl_api_hook_command_run_cb (const void *pointer, void *data, struct t_gui_buffer *buffer, const char *command) @@ -3025,122 +3141,6 @@ API_FUNC(hook_config) API_RETURN_STRING_FREE(result); } -int -weechat_tcl_api_hook_completion_cb (const void *pointer, void *data, - const char *completion_item, - struct t_gui_buffer *buffer, - struct t_gui_completion *completion) -{ - struct t_plugin_script *script; - void *func_argv[4]; - char empty_arg[1] = { '\0' }; - const char *ptr_function, *ptr_data; - int *rc, ret; - - script = (struct t_plugin_script *)pointer; - plugin_script_get_function_and_data (data, &ptr_function, &ptr_data); - - if (ptr_function && ptr_function[0]) - { - func_argv[0] = (ptr_data) ? (char *)ptr_data : empty_arg; - func_argv[1] = (completion_item) ? (char *)completion_item : empty_arg; - func_argv[2] = API_PTR2STR(buffer); - func_argv[3] = API_PTR2STR(completion); - - rc = (int *) weechat_tcl_exec (script, - WEECHAT_SCRIPT_EXEC_INT, - ptr_function, - "ssss", func_argv); - - if (!rc) - ret = WEECHAT_RC_ERROR; - else - { - ret = *rc; - free (rc); - } - if (func_argv[2]) - free (func_argv[2]); - if (func_argv[3]) - free (func_argv[3]); - - return ret; - } - - return WEECHAT_RC_ERROR; -} - -API_FUNC(hook_completion) -{ - Tcl_Obj *objp; - char *result, *completion, *description, *function, *data; - int i; - - API_INIT_FUNC(1, "hook_completion", API_RETURN_EMPTY); - if (objc < 5) - API_WRONG_ARGS(API_RETURN_EMPTY); - - completion = Tcl_GetStringFromObj (objv[1], &i); - description = Tcl_GetStringFromObj (objv[2], &i); - function = Tcl_GetStringFromObj (objv[3], &i); - data = Tcl_GetStringFromObj (objv[4], &i); - - result = API_PTR2STR(plugin_script_api_hook_completion (weechat_tcl_plugin, - tcl_current_script, - completion, - description, - &weechat_tcl_api_hook_completion_cb, - function, - data)); - - API_RETURN_STRING_FREE(result); -} - -API_FUNC(hook_completion_get_string) -{ - Tcl_Obj *objp; - char *completion, *property; - const char *result; - int i; - - API_INIT_FUNC(1, "hook_completion_get_string", API_RETURN_EMPTY); - if (objc < 3) - API_WRONG_ARGS(API_RETURN_EMPTY); - - completion = Tcl_GetStringFromObj (objv[1], &i); - property = Tcl_GetStringFromObj (objv[2], &i); - - result = weechat_hook_completion_get_string (API_STR2PTR(completion), - property); - - API_RETURN_STRING(result); -} - -API_FUNC(hook_completion_list_add) -{ - Tcl_Obj *objp; - char *completion, *word, *where; - int i, nick_completion; - - API_INIT_FUNC(1, "hook_completion_list_add", API_RETURN_ERROR); - if (objc < 5) - API_WRONG_ARGS(API_RETURN_ERROR); - - if (Tcl_GetIntFromObj (interp, objv[3], &nick_completion) != TCL_OK) - API_WRONG_ARGS(API_RETURN_ERROR); - - completion = Tcl_GetStringFromObj (objv[1], &i); - word = Tcl_GetStringFromObj (objv[2], &i); - where = Tcl_GetStringFromObj (objv[4], &i); - - weechat_hook_completion_list_add (API_STR2PTR(completion), - word, - nick_completion, /* nick_completion */ - where); - - API_RETURN_OK; -} - char * weechat_tcl_api_hook_modifier_cb (const void *pointer, void *data, const char *modifier, @@ -5587,6 +5587,9 @@ void weechat_tcl_api_init (Tcl_Interp *interp) API_DEF_FUNC(print_y); API_DEF_FUNC(log_print); API_DEF_FUNC(hook_command); + API_DEF_FUNC(hook_completion); + API_DEF_FUNC(hook_completion_get_string); + API_DEF_FUNC(hook_completion_list_add); API_DEF_FUNC(hook_command_run); API_DEF_FUNC(hook_timer); API_DEF_FUNC(hook_fd); @@ -5599,9 +5602,6 @@ void weechat_tcl_api_init (Tcl_Interp *interp) API_DEF_FUNC(hook_hsignal); API_DEF_FUNC(hook_hsignal_send); API_DEF_FUNC(hook_config); - API_DEF_FUNC(hook_completion); - API_DEF_FUNC(hook_completion_get_string); - API_DEF_FUNC(hook_completion_list_add); API_DEF_FUNC(hook_modifier); API_DEF_FUNC(hook_modifier_exec); API_DEF_FUNC(hook_info); |