From c7d21a3ea6cc96fab4d757c06f99ac1f74c8f7db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 15 Feb 2025 23:22:44 +0100 Subject: [PATCH] api: add function completion_set --- CHANGELOG.md | 1 + doc/en/weechat_plugin_api.en.adoc | 65 ++++++++++++++++++ doc/fr/weechat_plugin_api.fr.adoc | 65 ++++++++++++++++++ doc/it/weechat_plugin_api.it.adoc | 71 ++++++++++++++++++++ doc/ja/weechat_plugin_api.ja.adoc | 68 +++++++++++++++++++ doc/sr/weechat_plugin_api.sr.adoc | 67 ++++++++++++++++++ src/gui/gui-completion.c | 17 +++++ src/gui/gui-completion.h | 2 + src/plugins/guile/weechat-guile-api.c | 16 +++++ src/plugins/javascript/weechat-js-api.cpp | 17 +++++ src/plugins/lua/weechat-lua-api.c | 18 +++++ src/plugins/perl/weechat-perl-api.c | 19 ++++++ src/plugins/php/weechat-php-api.c | 20 ++++++ src/plugins/php/weechat-php-api.h | 1 + src/plugins/php/weechat-php.c | 1 + src/plugins/php/weechat-php.stub.php | 1 + src/plugins/php/weechat-php_arginfo.h | 4 +- src/plugins/php/weechat-php_legacy_arginfo.h | 4 +- src/plugins/plugin.c | 1 + src/plugins/python/weechat-python-api.c | 19 ++++++ src/plugins/python/weechat.pyi | 14 ++++ src/plugins/ruby/weechat-ruby-api.c | 26 +++++++ src/plugins/tcl/weechat-tcl-api.c | 18 +++++ src/plugins/weechat-plugin.h | 6 +- tests/scripts/python/testapi.py | 52 ++++++++++---- 25 files changed, 577 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5de03b77f..fdccdbc6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - core: add command `/pipe` - core: add option `whitespace` in command `/debug`, add options weechat.look.whitespace_char and weechat.look.tab_whitespace_char ([#947](https://github.com/weechat/weechat/issues/947)) +- api: add function completion_set - relay/api: add resource `POST /api/completion` ([#2207](https://github.com/weechat/weechat/issues/2207)) - relay/api: add default key `Alt`+`Ctrl`+`l` (L) to toggle between remote and local commands on remote buffers, add option `togglecmd` in command `/remote`, add options relay.api.remote_input_cmd_local and relay.api.remote_input_cmd_remote ([#2148](https://github.com/weechat/weechat/issues/2148)) diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index 3a516979c..5402541d7 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -17087,6 +17087,71 @@ def my_completion_cb(data: str, completion_item: str, buffer: str, completion: s return weechat.WEECHAT_RC_OK ---- +==== completion_set + +_WeeChat ≥ 4.6.0._ + +Set a completion property. + +Prototype: + +[source,c] +---- +void weechat_completion_get_string (struct t_gui_completion *completion, + const char *property, + const char *value); +---- + +Arguments: + +* _completion_: completion pointer +* _property_: property name (see table below) +* _value_: new value for property + +Properties: + +[width="100%",cols="^2,^1,4,8",options="header"] +|=== +| Name | Min WeeChat | Value | Description + +| add_space | 4.6.0 | "0" or "1" +| "0": do not add space after completion + + "1": add space after completion (default). +|=== + +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) +{ + /* do not add space after completion */ + weechat_completion_set (completion, "add_space", "0"); + + /* ... */ + + return WEECHAT_RC_OK; +} +---- + +Script (Python): + +[source,python] +---- +# prototype +def completion_set(completion: str, property: str, value: str) -> int: ... + +# example +def my_completion_cb(data: str, completion_item: str, buffer: str, completion: str) -> int: + # do not add space after completion + weechat.completion_set(completion, "add_space", "0") + # ... + return weechat.WEECHAT_RC_OK +---- + ==== completion_list_add _WeeChat ≥ 2.9._ diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index de56a97fe..0ed0b94b1 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -17451,6 +17451,71 @@ def my_completion_cb(data: str, completion_item: str, buffer: str, completion: s return weechat.WEECHAT_RC_OK ---- +==== completion_set + +_WeeChat ≥ 4.6.0._ + +Affecter une valeur à une propriété d'une complétion. + +Prototype : + +[source,c] +---- +void weechat_completion_get_string (struct t_gui_completion *completion, + const char *property, + const char *value); +---- + +Paramètres : + +* _completion_ : pointeur vers la complétion +* _property_ : nom de la propriété (voir le tableau ci-dessous) +* _value_ : nouvelle valeur pour la propriété + +Properties: + +[width="100%",cols="^2,^1,4,8",options="header"] +|=== +| Name | Min WeeChat | Value | Description + +| add_space | 4.6.0 | "0" or "1" +| "0": do not add space after completion + + "1": add space after completion (default). +|=== + +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) +{ + /* ne pas ajouter d'espace après la complétion */ + weechat_completion_set (completion, "add_space", "0"); + + /* ... */ + + return WEECHAT_RC_OK; +} +---- + +Script (Python) : + +[source,python] +---- +# prototype +def completion_set(completion: str, property: str, value: str) -> int: ... + +# exemple +def my_completion_cb(data: str, completion_item: str, buffer: str, completion: str) -> int: + # ne pas ajouter d'espace après la complétion + weechat.completion_set(completion, "add_space", "0") + # ... + return weechat.WEECHAT_RC_OK +---- + ==== completion_list_add _WeeChat ≥ 2.9._ diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index 98e7b4a78..d55e4845e 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -17924,6 +17924,77 @@ def my_completion_cb(data: str, completion_item: str, buffer: str, completion: s return weechat.WEECHAT_RC_OK ---- +==== completion_set + +_Novità nella versioe 4.6.0._ + +// TRANSLATION MISSING +Set a completion property. + +Prototipo: + +[source,c] +---- +void weechat_completion_get_string (struct t_gui_completion *completion, + const char *property, + const char *value); +---- + +Argomenti: + +* _completion_: puntatore al completamento +// TRANSLATION MISSING +* _property_: nome della proprietà (see table below) +// TRANSLATION MISSING +* _value_: new value for property + +// TRANSLATION MISSING +Properties: + +[width="100%",cols="^2,^1,4,8",options="header"] +|=== +// TRANSLATION MISSING +| Name | Min WeeChat | Value | Description + +// TRANSLATION MISSING +| add_space | 4.6.0 | "0" or "1" +| "0": do not add space after completion + + "1": add space after completion (default). +|=== + +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) +{ + /* do not add space after completion */ + weechat_completion_set (completion, "add_space", "0"); + + /* ... */ + + return WEECHAT_RC_OK; +} +---- + +Script (Python): + +[source,python] +---- +# prototipo +def completion_set(completion: str, property: str, value: str) -> int: ... + +# esempio +def my_completion_cb(data: str, completion_item: str, buffer: str, completion: str) -> int: + # do not add space after completion + weechat.completion_set(completion, "add_space", "0") + # ... + return weechat.WEECHAT_RC_OK +---- + ==== completion_list_add _Novità nella versioe 2.9._ diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index 8fb64c0e4..b59a3a48d 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -17382,6 +17382,74 @@ def my_completion_cb(data: str, completion_item: str, buffer: str, completion: s return weechat.WEECHAT_RC_OK ---- +==== completion_set + +_WeeChat バージョン 4.6.0 以上で利用可。_ + +// TRANSLATION MISSING +Set a completion property. + +プロトタイプ: + +[source,c] +---- +void weechat_completion_get_string (struct t_gui_completion *completion, + const char *property, + const char *value); +---- + +引数: + +* _completion_: 補完へのポインタ +* _property_: プロパティ名 (以下の表を参照) +* _value_: プロパティの新しい値 + +プロパティ: + +[width="100%",cols="^2,^1,4,8",options="header"] +|=== +// TRANSLATION MISSING +| Name | Min WeeChat | Value | Description + +// TRANSLATION MISSING +| add_space | 4.6.0 | "0" or "1" +| "0": do not add space after completion + + "1": add space after completion (default). +|=== + +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) +{ + /* do not add space after completion */ + weechat_completion_set (completion, "add_space", "0"); + + /* ... */ + + return WEECHAT_RC_OK; +} +---- + +スクリプト (Python) での使用例: + +[source,python] +---- +# prototype +def completion_set(completion: str, property: str, value: str) -> int: ... + +# example +def my_completion_cb(data: str, completion_item: str, buffer: str, completion: str) -> int: + # do not add space after completion + weechat.completion_set(completion, "add_space", "0") + # ... + return weechat.WEECHAT_RC_OK +---- + ==== completion_list_add _WeeChat バージョン 2.9 以上で利用可。_ diff --git a/doc/sr/weechat_plugin_api.sr.adoc b/doc/sr/weechat_plugin_api.sr.adoc index 12b933b86..c4889c8fd 100644 --- a/doc/sr/weechat_plugin_api.sr.adoc +++ b/doc/sr/weechat_plugin_api.sr.adoc @@ -16629,6 +16629,73 @@ def my_completion_cb(data: str, completion_item: str, buffer: str, completion: s return weechat.WEECHAT_RC_OK ---- +==== completion_set + +_WeeChat ≥ 4.6.0._ + +// TRANSLATION MISSING +Set a completion property. + +Прототип: + +[source,c] +---- +void weechat_completion_get_string (struct t_gui_completion *completion, + const char *property, + const char *value); +---- + +Аргументи: + +* _completion_: показивач на довршавање +* _property_: име особине (погледајте табелу испод) +* _value_: нова вредност за особину + +Особине: + +[width="100%",cols="^2,^1,4,8",options="header"] +|=== +| Име | Мин WeeChat | Вредност | Опис + +// TRANSLATION MISSING +| add_space | 4.6.0 | "0" or "1" +| "0": do not add space after completion + + "1": add space after completion (default). +|=== + +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) +{ + /* do not add space after completion */ + weechat_completion_set (completion, "add_space", "0"); + + /* ... */ + + return WEECHAT_RC_OK; +} +---- + +Скрипта (Python): + +[source,python] +---- +# прототип +def completion_set(completion: str, property: str, value: str) -> int: ... + +# пример +def my_completion_cb(data: str, completion_item: str, buffer: str, completion: str) -> int: + # do not add space after completion + weechat.completion_set(completion, "add_space", "0") + # ... + return weechat.WEECHAT_RC_OK +---- + ==== completion_list_add _WeeChat ≥ 2.9._ diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c index ae447101b..1245b0b0b 100644 --- a/src/gui/gui-completion.c +++ b/src/gui/gui-completion.c @@ -1561,6 +1561,23 @@ gui_completion_get_string (struct t_gui_completion *completion, return NULL; } +/* + * Sets a completion property. + */ + +void +gui_completion_set (struct t_gui_completion *completion, + const char *property, const char *value) +{ + if (!completion || !property || !value) + return; + + if (strcmp (property, "add_space") == 0) + { + completion->add_space = (strcmp (value, "1") == 0) ? 1 : 0; + } +} + /* * Returns hdata for completion. */ diff --git a/src/gui/gui-completion.h b/src/gui/gui-completion.h index 89d3a623f..fe804520b 100644 --- a/src/gui/gui-completion.h +++ b/src/gui/gui-completion.h @@ -94,6 +94,8 @@ extern int gui_completion_search (struct t_gui_completion *completion, int direction); extern const char *gui_completion_get_string (struct t_gui_completion *completion, const char *property); +extern void gui_completion_set (struct t_gui_completion *completion, + const char *property, const char *value); extern struct t_hdata *gui_completion_hdata_completion_cb (const void *pointer, void *data, const char *hdata_name); diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c index f7bee1a7a..e2b0c19e2 100644 --- a/src/plugins/guile/weechat-guile-api.c +++ b/src/plugins/guile/weechat-guile-api.c @@ -4566,6 +4566,21 @@ weechat_guile_api_completion_get_string (SCM completion, SCM property) API_RETURN_STRING(result); } +SCM +weechat_guile_api_completion_set (SCM completion, SCM property, SCM value) +{ + API_INIT_FUNC(1, "completion_set", API_RETURN_ERROR); + if (!scm_is_string (completion) || !scm_is_string (property) + || !scm_is_string (value)) + API_WRONG_ARGS(API_RETURN_ERROR); + + weechat_completion_set (API_STR2PTR(API_SCM_TO_STRING(completion)), + API_SCM_TO_STRING(property), + API_SCM_TO_STRING(value)); + + API_RETURN_OK; +} + SCM weechat_guile_api_completion_list_add (SCM completion, SCM word, SCM nick_completion, SCM where) @@ -5609,6 +5624,7 @@ weechat_guile_api_module_init (void *data) API_DEF_FUNC(completion_new, 1); API_DEF_FUNC(completion_search, 4); API_DEF_FUNC(completion_get_string, 2); + API_DEF_FUNC(completion_set, 3); API_DEF_FUNC(completion_list_add, 4); API_DEF_FUNC(completion_free, 1); API_DEF_FUNC(info_get, 2); diff --git a/src/plugins/javascript/weechat-js-api.cpp b/src/plugins/javascript/weechat-js-api.cpp index a914bc14c..2491b3165 100644 --- a/src/plugins/javascript/weechat-js-api.cpp +++ b/src/plugins/javascript/weechat-js-api.cpp @@ -4482,6 +4482,22 @@ API_FUNC(completion_get_string) API_RETURN_STRING(result); } +API_FUNC(completion_set) +{ + API_INIT_FUNC(1, "completion_set", "sss", API_RETURN_ERROR); + + v8::String::Utf8Value completion(args[0]); + v8::String::Utf8Value property(args[1]); + v8::String::Utf8Value value(args[2]); + + weechat_completion_set ( + (struct t_gui_completion *)API_STR2PTR(*completion), + *property, + *value); + + API_RETURN_OK; +} + API_FUNC(completion_list_add) { int nick_completion; @@ -5539,6 +5555,7 @@ WeechatJsV8::loadLibs() API_DEF_FUNC(completion_new); API_DEF_FUNC(completion_search); API_DEF_FUNC(completion_get_string); + API_DEF_FUNC(completion_set); API_DEF_FUNC(completion_list_add); API_DEF_FUNC(completion_free); API_DEF_FUNC(info_get); diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c index dac3dd770..9cd56592f 100644 --- a/src/plugins/lua/weechat-lua-api.c +++ b/src/plugins/lua/weechat-lua-api.c @@ -4831,6 +4831,23 @@ API_FUNC(completion_get_string) API_RETURN_STRING(result); } +API_FUNC(completion_set) +{ + const char *completion, *property, *value; + + API_INIT_FUNC(1, "completion_set", API_RETURN_ERROR); + if (lua_gettop (L) < 3) + API_WRONG_ARGS(API_RETURN_ERROR); + + completion = lua_tostring (L, -3); + property = lua_tostring (L, -2); + value = lua_tostring (L, -1); + + weechat_completion_set (API_STR2PTR(completion), property, value); + + API_RETURN_OK; +} + API_FUNC(completion_list_add) { const char *completion, *word, *where; @@ -5932,6 +5949,7 @@ const struct luaL_Reg weechat_lua_api_funcs[] = { API_DEF_FUNC(completion_new), API_DEF_FUNC(completion_search), API_DEF_FUNC(completion_get_string), + API_DEF_FUNC(completion_set), API_DEF_FUNC(completion_list_add), API_DEF_FUNC(completion_free), API_DEF_FUNC(info_get), diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c index 43f2d224b..2d33746b0 100644 --- a/src/plugins/perl/weechat-perl-api.c +++ b/src/plugins/perl/weechat-perl-api.c @@ -4733,6 +4733,24 @@ API_FUNC(completion_get_string) API_RETURN_STRING(result); } +API_FUNC(completion_set) +{ + char *completion, *property, *value; + dXSARGS; + + API_INIT_FUNC(1, "completion_set", API_RETURN_ERROR); + if (items < 3) + API_WRONG_ARGS(API_RETURN_ERROR); + + completion = SvPV_nolen (ST (0)); + property = SvPV_nolen (ST (1)); + value = SvPV_nolen (ST (2)); + + weechat_completion_set (API_STR2PTR(completion), property, value); + + API_RETURN_OK; +} + API_FUNC(completion_list_add) { char *completion, *word, *where; @@ -5870,6 +5888,7 @@ weechat_perl_api_init (pTHX) API_DEF_FUNC(completion_new); API_DEF_FUNC(completion_search); API_DEF_FUNC(completion_get_string); + API_DEF_FUNC(completion_set); API_DEF_FUNC(completion_list_add); API_DEF_FUNC(completion_free); API_DEF_FUNC(info_get); diff --git a/src/plugins/php/weechat-php-api.c b/src/plugins/php/weechat-php-api.c index e94319975..0a67be1d3 100644 --- a/src/plugins/php/weechat-php-api.c +++ b/src/plugins/php/weechat-php-api.c @@ -4814,6 +4814,26 @@ API_FUNC(completion_get_string) API_RETURN_STRING(result); } +API_FUNC(completion_set) +{ + zend_string *z_completion, *z_property, *z_value; + struct t_gui_completion *completion; + char *property, *value; + + API_INIT_FUNC(1, "completion_set", API_RETURN_ERROR); + if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSS", &z_completion, + &z_property, &z_value) == FAILURE) + API_WRONG_ARGS(API_RETURN_ERROR); + + completion = (struct t_gui_completion *)API_STR2PTR(ZSTR_VAL(z_completion)); + property = ZSTR_VAL(z_property); + value = ZSTR_VAL(z_value); + + weechat_completion_set (completion, (const char *)property, (const char *)value); + + API_RETURN_OK; +} + API_FUNC(completion_list_add) { zend_string *z_completion, *z_word, *z_where; diff --git a/src/plugins/php/weechat-php-api.h b/src/plugins/php/weechat-php-api.h index 01644ebbe..088fe34cf 100644 --- a/src/plugins/php/weechat-php-api.h +++ b/src/plugins/php/weechat-php-api.h @@ -219,6 +219,7 @@ PHP_FUNCTION(weechat_command_options); PHP_FUNCTION(weechat_completion_new); PHP_FUNCTION(weechat_completion_search); PHP_FUNCTION(weechat_completion_get_string); +PHP_FUNCTION(weechat_completion_set); PHP_FUNCTION(weechat_completion_list_add); PHP_FUNCTION(weechat_completion_free); PHP_FUNCTION(weechat_info_get); diff --git a/src/plugins/php/weechat-php.c b/src/plugins/php/weechat-php.c index 8f54b2f9f..7f9310c18 100644 --- a/src/plugins/php/weechat-php.c +++ b/src/plugins/php/weechat-php.c @@ -277,6 +277,7 @@ const zend_function_entry weechat_functions[] = { PHP_FE(weechat_completion_new, arginfo_weechat_completion_new) PHP_FE(weechat_completion_search, arginfo_weechat_completion_search) PHP_FE(weechat_completion_get_string, arginfo_weechat_completion_get_string) + PHP_FE(weechat_completion_set, arginfo_weechat_completion_set) PHP_FE(weechat_completion_list_add, arginfo_weechat_completion_list_add) PHP_FE(weechat_completion_free, arginfo_weechat_completion_free) PHP_FE(weechat_info_get, arginfo_weechat_info_get) diff --git a/src/plugins/php/weechat-php.stub.php b/src/plugins/php/weechat-php.stub.php index f9d37f6a1..fc9132cf2 100644 --- a/src/plugins/php/weechat-php.stub.php +++ b/src/plugins/php/weechat-php.stub.php @@ -185,6 +185,7 @@ function weechat_command_options(string $p0, string $p1, array $p2): int {} function weechat_completion_new(string $p0): string {} function weechat_completion_search(string $p0, string $p1, int $p2, int $p3): int {} function weechat_completion_get_string(string $p0, string $p1): string {} +function weechat_completion_set(string $p0, string $p1, string $p2): int {} function weechat_completion_list_add(string $p0, string $p1, int $p2, string $p3): int {} function weechat_completion_free(string $p0): int {} function weechat_info_get(string $p0, string $p1): string {} diff --git a/src/plugins/php/weechat-php_arginfo.h b/src/plugins/php/weechat-php_arginfo.h index c56676fe3..2345bc686 100644 --- a/src/plugins/php/weechat-php_arginfo.h +++ b/src/plugins/php/weechat-php_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: ac17ccd00483eea80bd3dc22ec07ab3bf41dec88 */ + * Stub hash: b20e387bfdf7c5496a25b4a07f5d3eed456f7992 */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_weechat_register, 0, 7, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, p0, IS_STRING, 0) @@ -539,6 +539,8 @@ ZEND_END_ARG_INFO() #define arginfo_weechat_completion_get_string arginfo_weechat_iconv_to_internal +#define arginfo_weechat_completion_set arginfo_weechat_config_write_line + #define arginfo_weechat_completion_list_add arginfo_weechat_hook_completion_list_add #define arginfo_weechat_completion_free arginfo_weechat_charset_set diff --git a/src/plugins/php/weechat-php_legacy_arginfo.h b/src/plugins/php/weechat-php_legacy_arginfo.h index 0fafa17bc..e8de9d8ac 100644 --- a/src/plugins/php/weechat-php_legacy_arginfo.h +++ b/src/plugins/php/weechat-php_legacy_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: ac17ccd00483eea80bd3dc22ec07ab3bf41dec88 */ + * Stub hash: b20e387bfdf7c5496a25b4a07f5d3eed456f7992 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_weechat_register, 0, 0, 7) ZEND_ARG_INFO(0, p0) @@ -385,6 +385,8 @@ ZEND_END_ARG_INFO() #define arginfo_weechat_completion_get_string arginfo_weechat_iconv_to_internal +#define arginfo_weechat_completion_set arginfo_weechat_ngettext + #define arginfo_weechat_completion_list_add arginfo_weechat_string_eval_expression #define arginfo_weechat_completion_free arginfo_weechat_plugin_get_name diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 82bf4299e..3ce3349d6 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -888,6 +888,7 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv) new_plugin->completion_new = &gui_completion_new; new_plugin->completion_search = &gui_completion_search; new_plugin->completion_get_string = &gui_completion_get_string; + new_plugin->completion_set = &gui_completion_set; new_plugin->completion_list_add = &gui_completion_list_add; new_plugin->completion_free = &gui_completion_free; diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c index 71a9de264..855072f94 100644 --- a/src/plugins/python/weechat-python-api.c +++ b/src/plugins/python/weechat-python-api.c @@ -4718,6 +4718,24 @@ API_FUNC(completion_get_string) API_RETURN_STRING(result); } +API_FUNC(completion_set) +{ + char *completion, *property, *value; + + API_INIT_FUNC(1, "completion_set", API_RETURN_ERROR); + completion = NULL; + property = NULL; + value = NULL; + if (!PyArg_ParseTuple (args, "sss", &completion, &property, &value)) + API_WRONG_ARGS(API_RETURN_ERROR); + + weechat_completion_set (API_STR2PTR(completion), + property, + value); + + API_RETURN_OK; +} + API_FUNC(completion_list_add) { char *completion, *word, *where; @@ -5798,6 +5816,7 @@ PyMethodDef weechat_python_funcs[] = API_DEF_FUNC(completion_new), API_DEF_FUNC(completion_search), API_DEF_FUNC(completion_get_string), + API_DEF_FUNC(completion_set), API_DEF_FUNC(completion_list_add), API_DEF_FUNC(completion_free), API_DEF_FUNC(info_get), diff --git a/src/plugins/python/weechat.pyi b/src/plugins/python/weechat.pyi index e61496307..3cf5bfc1a 100644 --- a/src/plugins/python/weechat.pyi +++ b/src/plugins/python/weechat.pyi @@ -2339,6 +2339,20 @@ def completion_get_string(completion: str, property: str) -> str: ... +def completion_set(completion: str, property: str, value: str) -> int: + """`completion_set in WeeChat plugin API reference `_ + :: + + # example + def my_completion_cb(data: str, completion_item: str, buffer: str, completion: str) -> int: + # do not add space after completion + weechat.completion_set(completion, "add_space", "0") + # ... + return weechat.WEECHAT_RC_OK + """ + ... + + def completion_list_add(completion: str, word: str, nick_completion: int, where: str) -> int: """`completion_list_add in WeeChat plugin API reference `_ :: diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c index 9229df9dd..2594ff7d6 100644 --- a/src/plugins/ruby/weechat-ruby-api.c +++ b/src/plugins/ruby/weechat-ruby-api.c @@ -5785,6 +5785,31 @@ weechat_ruby_api_completion_get_string (VALUE class, VALUE completion, API_RETURN_STRING(result); } +static VALUE +weechat_ruby_api_completion_set (VALUE class, VALUE completion, VALUE property, + VALUE value) +{ + char *c_completion, *c_property, *c_value; + + API_INIT_FUNC(1, "completion_set", API_RETURN_ERROR); + if (NIL_P (completion) || NIL_P (property) || NIL_P (value)) + API_WRONG_ARGS(API_RETURN_ERROR); + + Check_Type (completion, T_STRING); + Check_Type (property, T_STRING); + Check_Type (value, T_STRING); + + c_completion = StringValuePtr (completion); + c_property = StringValuePtr (property); + c_value = StringValuePtr (value); + + weechat_completion_set (API_STR2PTR(c_completion), + c_property, + c_value); + + API_RETURN_OK; +} + static VALUE weechat_ruby_api_completion_list_add (VALUE class, VALUE completion, VALUE word, VALUE nick_completion, @@ -7140,6 +7165,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) API_DEF_FUNC(completion_new, 1); API_DEF_FUNC(completion_search, 4); API_DEF_FUNC(completion_get_string, 2); + API_DEF_FUNC(completion_set, 3); API_DEF_FUNC(completion_list_add, 4); API_DEF_FUNC(completion_free, 1); API_DEF_FUNC(info_get, 2); diff --git a/src/plugins/tcl/weechat-tcl-api.c b/src/plugins/tcl/weechat-tcl-api.c index 63f68d306..5b675f377 100644 --- a/src/plugins/tcl/weechat-tcl-api.c +++ b/src/plugins/tcl/weechat-tcl-api.c @@ -4780,6 +4780,23 @@ API_FUNC(completion_get_string) API_RETURN_STRING(result); } +API_FUNC(completion_set) +{ + char *completion, *property, *value; + + API_INIT_FUNC(1, "completion_set", API_RETURN_ERROR); + if (objc < 4) + API_WRONG_ARGS(API_RETURN_ERROR); + + completion = Tcl_GetString (objv[1]); + property = Tcl_GetString (objv[2]); + value = Tcl_GetString (objv[3]); + + weechat_completion_set (API_STR2PTR(completion), property, value); + + API_RETURN_OK; +} + API_FUNC(completion_list_add) { char *completion, *word, *where; @@ -5876,6 +5893,7 @@ void weechat_tcl_api_init (Tcl_Interp *interp) API_DEF_FUNC(completion_new); API_DEF_FUNC(completion_search); API_DEF_FUNC(completion_get_string); + API_DEF_FUNC(completion_set); API_DEF_FUNC(completion_list_add); API_DEF_FUNC(info_get); API_DEF_FUNC(info_get_hashtable); diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index a30a2034b..535d62a7e 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -74,7 +74,7 @@ struct t_weelist_item; * please change the date with current one; for a second change at same * date, increment the 01, otherwise please keep 01. */ -#define WEECHAT_PLUGIN_API_VERSION "20241124-01" +#define WEECHAT_PLUGIN_API_VERSION "20250215-01" /* macros for defining plugin infos */ #define WEECHAT_PLUGIN_NAME(__name) \ @@ -1133,6 +1133,8 @@ struct t_weechat_plugin const char *data, int position, int direction); const char *(*completion_get_string) (struct t_gui_completion *completion, const char *property); + void (*completion_set) (struct t_gui_completion *completion, + const char *property, const char *value); void (*completion_list_add) (struct t_gui_completion *completion, const char *word, int nick_completion, @@ -2204,6 +2206,8 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); __position, __direction) #define weechat_completion_get_string(__completion, __property) \ (weechat_plugin->completion_get_string)(__completion, __property) +#define weechat_completion_set(__completion, __property, __value) \ + (weechat_plugin->completion_set)(__completion, __property, __value) #define weechat_completion_list_add(__completion, __word, \ __nick_completion, __where) \ (weechat_plugin->completion_list_add)(__completion, __word, \ diff --git a/tests/scripts/python/testapi.py b/tests/scripts/python/testapi.py index 4290ac274..fe3501994 100644 --- a/tests/scripts/python/testapi.py +++ b/tests/scripts/python/testapi.py @@ -578,10 +578,21 @@ def test_display(): weechat.buffer_close(buffer) -def completion_cb(data, completion_item, buf, completion): +def completion1_cb(data, completion_item, buf, completion): """Completion callback.""" check(data == 'completion_data') - check(completion_item == '{SCRIPT_NAME}') + check(completion_item == '{SCRIPT_NAME}1') + check(weechat.completion_get_string(completion, 'args') == 'w') + weechat.completion_set(completion, 'add_space', '0') + weechat.completion_list_add(completion, 'word_completed', + 0, weechat.WEECHAT_LIST_POS_END) + return weechat.WEECHAT_RC_OK + + +def completion2_cb(data, completion_item, buf, completion): + """Completion callback.""" + check(data == 'completion_data') + check(completion_item == '{SCRIPT_NAME}2') check(weechat.completion_get_string(completion, 'args') == 'w') weechat.completion_list_add(completion, 'word_completed', 0, weechat.WEECHAT_LIST_POS_END) @@ -598,7 +609,7 @@ def command_cb(data, buf, args): def command_run_cb(data, buf, command): """Command_run callback.""" check(data == 'command_run_data') - check(command == '/cmd' + '{SCRIPT_NAME}' + ' word_completed') + check(command == '/cmd2' + '{SCRIPT_NAME}' + ' word_completed') return weechat.WEECHAT_RC_OK @@ -609,22 +620,37 @@ def timer_cb(data, remaining_calls): def test_hooks(): """Test hook functions.""" + buffer = weechat.buffer_search_main() # hook_completion / hook_completion_args / and hook_command - hook_cmplt = weechat.hook_completion('{SCRIPT_NAME}', 'description', - 'completion_cb', 'completion_data') - hook_cmd = weechat.hook_command('cmd' + '{SCRIPT_NAME}', 'description', - 'arguments', 'description arguments', - '%(' + '{SCRIPT_NAME}' + ')', - 'command_cb', 'command_data') - weechat.command('', '/input insert /cmd' + '{SCRIPT_NAME}' + ' w') + hook_cmplt1 = weechat.hook_completion('{SCRIPT_NAME}1', 'description', + 'completion1_cb', 'completion_data') + hook_cmd1 = weechat.hook_command('cmd1' + '{SCRIPT_NAME}', 'description', + 'arguments', 'description arguments', + '%(' + '{SCRIPT_NAME}1' + ')', + 'command_cb', 'command_data') + hook_cmplt2 = weechat.hook_completion('{SCRIPT_NAME}2', 'description', + 'completion2_cb', 'completion_data') + hook_cmd2 = weechat.hook_command('cmd2' + '{SCRIPT_NAME}', 'description', + 'arguments', 'description arguments', + '%(' + '{SCRIPT_NAME}2' + ')', + 'command_cb', 'command_data') + weechat.command('', '/input insert /cmd1' + '{SCRIPT_NAME}' + ' w') weechat.command('', '/input complete_next') + check(weechat.buffer_get_string(buffer, 'input') == '/cmd1' + '{SCRIPT_NAME}' + ' word_completed') + weechat.command('', '/input delete_line') + weechat.command('', '/input insert /cmd2' + '{SCRIPT_NAME}' + ' w') + weechat.command('', '/input complete_next') + check(weechat.buffer_get_string(buffer, 'input') == '/cmd2' + '{SCRIPT_NAME}' + ' word_completed ') # hook_command_run - hook_cmd_run = weechat.hook_command_run('/cmd' + '{SCRIPT_NAME}' + '*', + hook_cmd_run = weechat.hook_command_run('/cmd2' + '{SCRIPT_NAME}' + '*', 'command_run_cb', 'command_run_data') weechat.command('', '/input return') weechat.unhook(hook_cmd_run) - weechat.unhook(hook_cmd) - weechat.unhook(hook_cmplt) + weechat.unhook(hook_cmd1) + weechat.unhook(hook_cmplt1) + weechat.unhook(hook_cmd2) + weechat.unhook(hook_cmplt2) + # weechat.unhook(hook_cmplt2) # hook_timer hook_timer = weechat.hook_timer(2000111000, 0, 1, 'timer_cb', 'timer_cb_data')