diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ec99268e..63b80b4fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - core: add hdata count in evaluation of expressions with `hdata_count:name[list]` or `hdata_count:name[pointer]` - core: add completion "bars_items" - api: add hashtable type "longlong" +- api: add function line_search_by_id - doc: add doc on "api" relay ### Fixed diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index 4375ead9f..294c457d2 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -15201,6 +15201,46 @@ if buffer: weechat.prnt("", "%d" % weechat.buffer_match_list(buffer, "irc.oftc.*,python.*")) # 0 ---- +[[buffer_lines]] +=== Buffer lines + +Functions for buffer lines. + +==== line_search_by_id + +_WeeChat ≥ 4.4.0._ + +Search line in buffer by identifier. + +Prototype: + +[source,c] +---- +struct t_gui_line *weechat_line_search_by_id (struct t_gui_buffer *buffer, int id); +---- + +Return value: + +* pointer to line found, NULL if not found + +C example: + +[source,c] +---- +struct t_gui_line *line = weechat_line_search_by_id (buffer, 123); +---- + +Script (Python): + +[source,python] +---- +# prototype +def line_search_by_id(buffer: str, line_id: int) -> str: ... + +# example +line = weechat.line_search_by_id(buffer, 123) +---- + [[windows]] === Windows diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index bbc503d41..8a3e74cbf 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -15532,6 +15532,46 @@ if buffer: weechat.prnt("", "%d" % weechat.buffer_match_list(buffer, "irc.oftc.*,python.*")) # 0 ---- +[[buffer_lines]] +=== Lignes de tampons + +Fonctions pour les lignes de tampons. + +==== line_search_by_id + +_WeeChat ≥ 4.4.0._ + +Rechercher une ligne du tampon par son identifiant. + +Prototype : + +[source,c] +---- +struct t_gui_line *weechat_line_search_by_id (struct t_gui_buffer *buffer, int id); +---- + +Valeur de retour : + +* pointeur vers la ligne trouvée, NULL si non trouvée + +Exemple en C : + +[source,c] +---- +struct t_gui_line *line = weechat_line_search_by_id (buffer, 123); +---- + +Script (Python) : + +[source,python] +---- +# prototype +def line_search_by_id(buffer: str, line_id: int) -> str: ... + +# exemple +line = weechat.line_search_by_id(buffer, 123) +---- + [[windows]] === Fenêtres diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index 18a24d1d4..f74983840 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -15954,6 +15954,50 @@ if buffer: weechat.prnt("", "%d" % weechat.buffer_match_list(buffer, "irc.oftc.*,python.*")) # 0 ---- +// TRANSLATION MISSING +[[buffer_lines]] +=== Buffer lines + +// TRANSLATION MISSING +Functions for buffer lines. + +==== line_search_by_id + +_WeeChat ≥ 4.4.0._ + +// TRANSLATION MISSING +Search line in buffer by identifier. + +Prototipo: + +[source,c] +---- +struct t_gui_line *weechat_line_search_by_id (struct t_gui_buffer *buffer, int id); +---- + +Valore restituito: + +// TRANSLATION MISSING +* pointer to line found, NULL if not found + +Esempio in C: + +[source,c] +---- +struct t_gui_line *line = weechat_line_search_by_id (buffer, 123); +---- + +Script (Python): + +[source,python] +---- +# prototipo +def line_search_by_id(buffer: str, line_id: int) -> str: ... + +# esempio +line = weechat.line_search_by_id(buffer, 123) +---- + [[windows]] === Finestre diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index 0d7667695..2932be359 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -15453,6 +15453,50 @@ if buffer: weechat.prnt("", "%d" % weechat.buffer_match_list(buffer, "irc.oftc.*,python.*")) # 0 ---- +// TRANSLATION MISSING +[[buffer_lines]] +=== Buffer lines + +// TRANSLATION MISSING +Functions for buffer lines. + +==== line_search_by_id + +_WeeChat ≥ 4.4.0._ + +// TRANSLATION MISSING +Search line in buffer by identifier. + +プロトタイプ: + +[source,c] +---- +struct t_gui_line *weechat_line_search_by_id (struct t_gui_buffer *buffer, int id); +---- + +戻り値: + +// TRANSLATION MISSING +* pointer to line found, NULL if not found + +C 言語での使用例: + +[source,c] +---- +struct t_gui_line *line = weechat_line_search_by_id (buffer, 123); +---- + +スクリプト (Python) での使用例: + +[source,python] +---- +# プロトタイプ +def line_search_by_id(buffer: str, line_id: int) -> str: ... + +# 例 +line = weechat.line_search_by_id(buffer, 123) +---- + [[windows]] === ウィンドウ diff --git a/doc/sr/weechat_plugin_api.sr.adoc b/doc/sr/weechat_plugin_api.sr.adoc index d1e636243..a1f6a7810 100644 --- a/doc/sr/weechat_plugin_api.sr.adoc +++ b/doc/sr/weechat_plugin_api.sr.adoc @@ -14777,6 +14777,50 @@ if buffer: weechat.prnt("", "%d" % weechat.buffer_match_list(buffer, "irc.oftc.*,python.*")) # 0 ---- +// TRANSLATION MISSING +[[buffer_lines]] +=== Buffer lines + +// TRANSLATION MISSING +Functions for buffer lines. + +==== line_search_by_id + +_WeeChat ≥ 4.4.0._ + +// TRANSLATION MISSING +Search line in buffer by identifier. + +Прототип: + +[source,c] +---- +struct t_gui_line *weechat_line_search_by_id (struct t_gui_buffer *buffer, int id); +---- + +Повратна вредност: + +// TRANSLATION MISSING +* pointer to line found, NULL if not found + +C пример: + +[source,c] +---- +struct t_gui_line *line = weechat_line_search_by_id (buffer, 123); +---- + +Скрипта (Python): + +[source,python] +---- +# прототип +def line_search_by_id(buffer: str, line_id: int) -> str: ... + +# пример +line = weechat.line_search_by_id(buffer, 123) +---- + [[windows]] === Прозори diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c index 226c38d85..c5d5fa3e8 100644 --- a/src/gui/gui-line.c +++ b/src/gui/gui-line.c @@ -602,6 +602,31 @@ gui_line_get_next_displayed (struct t_gui_line *line) return line; } +/* + * Searches a line by id. + * + * Returns pointer to line found, NULL if not found. + */ + +struct t_gui_line * +gui_line_search_by_id (struct t_gui_buffer *buffer, int id) +{ + struct t_gui_line *ptr_line; + + if (!buffer || !buffer->own_lines) + return NULL; + + for (ptr_line = buffer->own_lines->last_line; ptr_line; + ptr_line = ptr_line->prev_line) + { + if (ptr_line->data && (ptr_line->data->id == id)) + return ptr_line; + } + + /* line not found */ + return NULL; +} + /* * Searches for text in a line. * diff --git a/src/gui/gui-line.h b/src/gui/gui-line.h index 50932eb1c..579a85120 100644 --- a/src/gui/gui-line.h +++ b/src/gui/gui-line.h @@ -97,6 +97,8 @@ extern struct t_gui_line *gui_line_get_first_displayed (struct t_gui_buffer *buf extern struct t_gui_line *gui_line_get_last_displayed (struct t_gui_buffer *buffer); extern struct t_gui_line *gui_line_get_prev_displayed (struct t_gui_line *line); extern struct t_gui_line *gui_line_get_next_displayed (struct t_gui_line *line); +extern struct t_gui_line *gui_line_search_by_id (struct t_gui_buffer *buffer, + int id); extern int gui_line_search_text (struct t_gui_buffer *buffer, struct t_gui_line *line); extern int gui_line_match_regex (struct t_gui_line_data *line_data, diff --git a/src/plugins/guile/weechat-guile-api.c b/src/plugins/guile/weechat-guile-api.c index 015ab42c5..f17d6a8e9 100644 --- a/src/plugins/guile/weechat-guile-api.c +++ b/src/plugins/guile/weechat-guile-api.c @@ -3875,6 +3875,22 @@ weechat_guile_api_buffer_match_list (SCM buffer, SCM string) API_RETURN_INT(value); } +SCM +weechat_guile_api_line_search_by_id (SCM buffer, SCM id) +{ + const char *result; + SCM return_value; + + API_INIT_FUNC(1, "line_search_by_id", API_RETURN_EMPTY); + if (!scm_is_string (buffer) || !scm_is_integer (id)) + API_WRONG_ARGS(API_RETURN_EMPTY); + + result = API_PTR2STR(weechat_line_search_by_id (API_STR2PTR(API_SCM_TO_STRING(buffer)), + scm_to_int (id))); + + API_RETURN_STRING(result); +} + SCM weechat_guile_api_current_window () { @@ -5557,6 +5573,7 @@ weechat_guile_api_module_init (void *data) API_DEF_FUNC(buffer_set, 3); API_DEF_FUNC(buffer_string_replace_local_var, 2); API_DEF_FUNC(buffer_match_list, 2); + API_DEF_FUNC(line_search_by_id, 2); API_DEF_FUNC(current_window, 0); API_DEF_FUNC(window_search_with_buffer, 1); API_DEF_FUNC(window_get_integer, 2); diff --git a/src/plugins/javascript/weechat-js-api.cpp b/src/plugins/javascript/weechat-js-api.cpp index 3cea774df..a9bbfb3b3 100644 --- a/src/plugins/javascript/weechat-js-api.cpp +++ b/src/plugins/javascript/weechat-js-api.cpp @@ -3808,6 +3808,22 @@ API_FUNC(buffer_match_list) API_RETURN_INT(value); } +API_FUNC(line_search_by_id) +{ + const char *result; + int id; + + API_INIT_FUNC(1, "line_search_by_id", "si", API_RETURN_EMPTY); + + v8::String::Utf8Value buffer(args[0]); + id = args[1]->IntegerValue(); + + result = API_PTR2STR( + weechat_line_search_by_id ((struct t_gui_buffer *)API_STR2PTR(*buffer), id)); + + API_RETURN_STRING(result); +} + API_FUNC(current_window) { const char *result; @@ -5487,6 +5503,7 @@ WeechatJsV8::loadLibs() API_DEF_FUNC(buffer_set); API_DEF_FUNC(buffer_string_replace_local_var); API_DEF_FUNC(buffer_match_list); + API_DEF_FUNC(line_search_by_id); API_DEF_FUNC(current_window); API_DEF_FUNC(window_search_with_buffer); API_DEF_FUNC(window_get_integer); diff --git a/src/plugins/lua/weechat-lua-api.c b/src/plugins/lua/weechat-lua-api.c index 356d769fa..9fe53d69e 100644 --- a/src/plugins/lua/weechat-lua-api.c +++ b/src/plugins/lua/weechat-lua-api.c @@ -4083,6 +4083,23 @@ API_FUNC(buffer_match_list) API_RETURN_INT(value); } +API_FUNC(line_search_by_id) +{ + const char *buffer, *result; + int id; + + API_INIT_FUNC(1, "line_search_by_id", API_RETURN_EMPTY); + if (lua_gettop (L) < 2) + API_WRONG_ARGS(API_RETURN_EMPTY); + + buffer = lua_tostring (L, -2); + id = lua_tonumber (L, -1); + + result = API_PTR2STR(weechat_line_search_by_id (API_STR2PTR(buffer), id)); + + API_RETURN_STRING(result); +} + API_FUNC(current_window) { const char *result; @@ -5879,6 +5896,7 @@ const struct luaL_Reg weechat_lua_api_funcs[] = { API_DEF_FUNC(buffer_set), API_DEF_FUNC(buffer_string_replace_local_var), API_DEF_FUNC(buffer_match_list), + API_DEF_FUNC(line_search_by_id), API_DEF_FUNC(current_window), API_DEF_FUNC(window_search_with_buffer), API_DEF_FUNC(window_get_integer), diff --git a/src/plugins/perl/weechat-perl-api.c b/src/plugins/perl/weechat-perl-api.c index 0c547c28a..c35c6e280 100644 --- a/src/plugins/perl/weechat-perl-api.c +++ b/src/plugins/perl/weechat-perl-api.c @@ -3976,6 +3976,23 @@ API_FUNC(buffer_match_list) API_RETURN_INT(value); } +API_FUNC(line_search_by_id) +{ + const char *result; + dXSARGS; + + API_INIT_FUNC(1, "line_search_by_id", API_RETURN_EMPTY); + if (items < 2) + API_WRONG_ARGS(API_RETURN_EMPTY); + + result = API_PTR2STR( + weechat_line_search_by_id ( + API_STR2PTR(SvPV_nolen (ST (0))), /* buffer */ + SvIV (ST (1)))); /* id */ + + API_RETURN_STRING(result); +} + API_FUNC(current_window) { const char *result; @@ -5817,6 +5834,7 @@ weechat_perl_api_init (pTHX) API_DEF_FUNC(buffer_set); API_DEF_FUNC(buffer_string_replace_local_var); API_DEF_FUNC(buffer_match_list); + API_DEF_FUNC(line_search_by_id); API_DEF_FUNC(current_window); API_DEF_FUNC(window_search_with_buffer); API_DEF_FUNC(window_get_integer); diff --git a/src/plugins/php/weechat-php-api.c b/src/plugins/php/weechat-php-api.c index 289d50ea4..c6cedc827 100644 --- a/src/plugins/php/weechat-php-api.c +++ b/src/plugins/php/weechat-php-api.c @@ -3976,6 +3976,27 @@ API_FUNC(buffer_match_list) API_RETURN_INT(result); } +API_FUNC(line_search_by_id) +{ + zend_string *z_buffer; + zend_long z_id; + struct t_gui_buffer *buffer; + int id; + const char *result; + + API_INIT_FUNC(1, "line_search_by_id", API_RETURN_EMPTY); + if (zend_parse_parameters (ZEND_NUM_ARGS(), "Sl", &z_buffer, + &z_id) == FAILURE) + API_WRONG_ARGS(API_RETURN_EMPTY); + + buffer = (struct t_gui_buffer *)API_STR2PTR(ZSTR_VAL(z_buffer)); + id = (int)z_id; + + result = API_PTR2STR(weechat_line_search_by_id (buffer, id)); + + API_RETURN_STRING(result); +} + API_FUNC(current_window) { const char *result; diff --git a/src/plugins/php/weechat-php-api.h b/src/plugins/php/weechat-php-api.h index 40d30d4a6..c15e26039 100644 --- a/src/plugins/php/weechat-php-api.h +++ b/src/plugins/php/weechat-php-api.h @@ -183,6 +183,7 @@ PHP_FUNCTION(weechat_buffer_get_pointer); PHP_FUNCTION(weechat_buffer_set); PHP_FUNCTION(weechat_buffer_string_replace_local_var); PHP_FUNCTION(weechat_buffer_match_list); +PHP_FUNCTION(weechat_line_search_by_id); PHP_FUNCTION(weechat_current_window); PHP_FUNCTION(weechat_window_search_with_buffer); PHP_FUNCTION(weechat_window_get_integer); diff --git a/src/plugins/php/weechat-php.c b/src/plugins/php/weechat-php.c index 9cd1b8416..6ca80e766 100644 --- a/src/plugins/php/weechat-php.c +++ b/src/plugins/php/weechat-php.c @@ -241,6 +241,7 @@ const zend_function_entry weechat_functions[] = { PHP_FE(weechat_buffer_set, arginfo_weechat_buffer_set) PHP_FE(weechat_buffer_string_replace_local_var, arginfo_weechat_buffer_string_replace_local_var) PHP_FE(weechat_buffer_match_list, arginfo_weechat_buffer_match_list) + PHP_FE(weechat_line_search_by_id, arginfo_weechat_line_search_by_id) PHP_FE(weechat_current_window, arginfo_weechat_current_window) PHP_FE(weechat_window_search_with_buffer, arginfo_weechat_window_search_with_buffer) PHP_FE(weechat_window_get_integer, arginfo_weechat_window_get_integer) diff --git a/src/plugins/php/weechat-php.stub.php b/src/plugins/php/weechat-php.stub.php index 82dee73df..f9d37f6a1 100644 --- a/src/plugins/php/weechat-php.stub.php +++ b/src/plugins/php/weechat-php.stub.php @@ -149,6 +149,7 @@ function weechat_buffer_get_pointer(string $p0, string $p1): string {} function weechat_buffer_set(string $p0, string $p1, string $p2): int {} function weechat_buffer_string_replace_local_var(string $p0, string $p1): string {} function weechat_buffer_match_list(string $p0, string $p1): int {} +function weechat_line_search_by_id(string $p0, int $p1): string {} function weechat_current_window(): string {} function weechat_window_search_with_buffer(string $p0): string {} function weechat_window_get_integer(string $p0, string $p1): int {} diff --git a/src/plugins/php/weechat-php_arginfo.h b/src/plugins/php/weechat-php_arginfo.h index f5353b4d6..c56676fe3 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: cf4a06ff974bca04f671e75e22f7d16534ca643f */ + * Stub hash: ac17ccd00483eea80bd3dc22ec07ab3bf41dec88 */ 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) @@ -439,6 +439,8 @@ ZEND_END_ARG_INFO() #define arginfo_weechat_buffer_match_list arginfo_weechat_string_has_highlight +#define arginfo_weechat_line_search_by_id arginfo_weechat_list_get + #define arginfo_weechat_current_window arginfo_weechat_list_new #define arginfo_weechat_window_search_with_buffer arginfo_weechat_plugin_get_name diff --git a/src/plugins/php/weechat-php_legacy_arginfo.h b/src/plugins/php/weechat-php_legacy_arginfo.h index 36716de6c..0fafa17bc 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: cf4a06ff974bca04f671e75e22f7d16534ca643f */ + * Stub hash: ac17ccd00483eea80bd3dc22ec07ab3bf41dec88 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_weechat_register, 0, 0, 7) ZEND_ARG_INFO(0, p0) @@ -313,6 +313,8 @@ ZEND_END_ARG_INFO() #define arginfo_weechat_buffer_match_list arginfo_weechat_iconv_to_internal +#define arginfo_weechat_line_search_by_id arginfo_weechat_iconv_to_internal + #define arginfo_weechat_current_window arginfo_weechat_list_new #define arginfo_weechat_window_search_with_buffer arginfo_weechat_plugin_get_name diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 0f77ac3c6..28f69181c 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -58,6 +58,7 @@ #include "../gui/gui-color.h" #include "../gui/gui-completion.h" #include "../gui/gui-key.h" +#include "../gui/gui-line.h" #include "../gui/gui-nicklist.h" #include "../gui/gui-window.h" #include "plugin.h" @@ -845,6 +846,8 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv) new_plugin->buffer_string_replace_local_var = &gui_buffer_string_replace_local_var; new_plugin->buffer_match_list = &gui_buffer_match_list; + new_plugin->line_search_by_id = &gui_line_search_by_id; + new_plugin->window_search_with_buffer = &gui_window_search_with_buffer; new_plugin->window_get_integer = &gui_window_get_integer; new_plugin->window_get_string = &gui_window_get_string; diff --git a/src/plugins/python/weechat-python-api.c b/src/plugins/python/weechat-python-api.c index 7ce78ee90..f2548ae3f 100644 --- a/src/plugins/python/weechat-python-api.c +++ b/src/plugins/python/weechat-python-api.c @@ -3990,6 +3990,23 @@ API_FUNC(buffer_match_list) API_RETURN_INT(value); } +API_FUNC(line_search_by_id) +{ + char *buffer; + int id; + const char *result; + + API_INIT_FUNC(1, "line_search_by_id", API_RETURN_EMPTY); + buffer = NULL; + id = 0; + if (!PyArg_ParseTuple (args, "si", &buffer, &id)) + API_WRONG_ARGS(API_RETURN_EMPTY); + + result = API_PTR2STR(weechat_line_search_by_id (API_STR2PTR(buffer), id)); + + API_RETURN_STRING(result); +} + API_FUNC(current_window) { const char *result; @@ -5745,6 +5762,7 @@ PyMethodDef weechat_python_funcs[] = API_DEF_FUNC(buffer_set), API_DEF_FUNC(buffer_string_replace_local_var), API_DEF_FUNC(buffer_match_list), + API_DEF_FUNC(line_search_by_id), API_DEF_FUNC(current_window), API_DEF_FUNC(window_search_with_buffer), API_DEF_FUNC(window_get_integer), diff --git a/src/plugins/python/weechat.pyi b/src/plugins/python/weechat.pyi index c8bc02f33..b190eb8f0 100644 --- a/src/plugins/python/weechat.pyi +++ b/src/plugins/python/weechat.pyi @@ -1926,6 +1926,16 @@ def buffer_match_list(buffer: str, string: str) -> int: ... +def line_search_by_id(buffer: str, line_id: int) -> str: + """`line_search_by_id in WeeChat plugin API reference `_ + :: + + # example + line = weechat.line_search_by_id(buffer, 123) + """ + ... + + def current_window() -> str: """`current_window in WeeChat plugin API reference `_ :: diff --git a/src/plugins/ruby/weechat-ruby-api.c b/src/plugins/ruby/weechat-ruby-api.c index 01729432b..03cc06ed7 100644 --- a/src/plugins/ruby/weechat-ruby-api.c +++ b/src/plugins/ruby/weechat-ruby-api.c @@ -4822,6 +4822,29 @@ weechat_ruby_api_buffer_match_list (VALUE class, VALUE buffer, VALUE string) API_RETURN_INT(value); } +static VALUE +weechat_ruby_api_line_search_by_id (VALUE class, VALUE buffer, VALUE id) +{ + char *c_buffer; + int c_id; + const char *result; + + API_INIT_FUNC(1, "line_search_by_id", API_RETURN_EMPTY); + if (NIL_P (buffer) || NIL_P (id)) + API_WRONG_ARGS(API_RETURN_EMPTY); + + Check_Type (buffer, T_STRING); + CHECK_INTEGER(id); + + c_buffer = StringValuePtr (buffer); + c_id = NUM2INT (id); + + result = API_PTR2STR(weechat_line_search_by_id (API_STR2PTR(c_buffer), + c_id)); + + API_RETURN_STRING(result); +} + static VALUE weechat_ruby_api_current_window (VALUE class) { @@ -7081,6 +7104,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat) API_DEF_FUNC(buffer_set, 3); API_DEF_FUNC(buffer_string_replace_local_var, 2); API_DEF_FUNC(buffer_match_list, 2); + API_DEF_FUNC(line_search_by_id, 2); API_DEF_FUNC(current_window, 0); API_DEF_FUNC(window_search_with_buffer, 1); API_DEF_FUNC(window_get_integer, 2); diff --git a/src/plugins/tcl/weechat-tcl-api.c b/src/plugins/tcl/weechat-tcl-api.c index 6bef61433..5984a1ccf 100644 --- a/src/plugins/tcl/weechat-tcl-api.c +++ b/src/plugins/tcl/weechat-tcl-api.c @@ -4043,6 +4043,25 @@ API_FUNC(buffer_match_list) API_RETURN_INT(result); } +API_FUNC(line_search_by_id) +{ + char *buffer; + int id; + const char *result; + + API_INIT_FUNC(1, "line_search_by_id", API_RETURN_EMPTY); + if (objc < 3) + API_WRONG_ARGS(API_RETURN_EMPTY); + + buffer = Tcl_GetString (objv[1]); + if (Tcl_GetIntFromObj (interp, objv[2], &id) != TCL_OK) + API_WRONG_ARGS(API_RETURN_ERROR); + + result = API_PTR2STR(weechat_line_search_by_id (API_STR2PTR(buffer), id)); + + API_RETURN_STRING(result); +} + API_FUNC(current_window) { const char *result; @@ -5821,6 +5840,7 @@ void weechat_tcl_api_init (Tcl_Interp *interp) API_DEF_FUNC(buffer_set); API_DEF_FUNC(buffer_string_replace_local_var); API_DEF_FUNC(buffer_match_list); + API_DEF_FUNC(line_search_by_id); API_DEF_FUNC(current_window); API_DEF_FUNC(window_search_with_buffer); API_DEF_FUNC(window_get_integer); diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 19ab81afa..f2a58038c 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 "20240610-01" +#define WEECHAT_PLUGIN_API_VERSION "20240627-01" /* macros for defining plugin infos */ #define WEECHAT_PLUGIN_NAME(__name) \ @@ -1008,6 +1008,9 @@ struct t_weechat_plugin const char *string); int (*buffer_match_list) (struct t_gui_buffer *buffer, const char *string); + /* buffer lines */ + struct t_gui_line *(*line_search_by_id) (struct t_gui_buffer *buffer, int id); + /* windows */ struct t_gui_window *(*window_search_with_buffer) (struct t_gui_buffer *buffer); int (*window_get_integer) (struct t_gui_window *window, @@ -2067,6 +2070,10 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); #define weechat_buffer_match_list(__buffer, __string) \ (weechat_plugin->buffer_match_list)(__buffer, __string) +/* buffer lines */ +#define weechat_line_search_by_id(__buffer, __id) \ + (weechat_plugin->line_search_by_id)(__buffer, __id) + /* windows */ #define weechat_window_search_with_buffer(__buffer) \ (weechat_plugin->window_search_with_buffer)(__buffer) diff --git a/tests/scripts/python/testapi.py b/tests/scripts/python/testapi.py index 7865c75fa..08544bcf8 100644 --- a/tests/scripts/python/testapi.py +++ b/tests/scripts/python/testapi.py @@ -680,6 +680,14 @@ def test_buffers(): weechat.buffer_close(buffer2) +def test_lines(): + """Test line functions.""" + buffer = weechat.buffer_search_main() + check(weechat.line_search_by_id(buffer, -1) == '') + check(weechat.line_search_by_id(buffer, 1234567) == '') + check(weechat.line_search_by_id(buffer, 0) != '') + + def test_windows(): """Test window functions.""" window = weechat.current_window() @@ -864,6 +872,7 @@ def cmd_test_cb(data, buf, args): test_display() test_hooks() test_buffers() + test_lines() test_windows() test_command() test_infolist() diff --git a/tests/unit/gui/test-gui-line.cpp b/tests/unit/gui/test-gui-line.cpp index a0bee35e4..f61a589ad 100644 --- a/tests/unit/gui/test-gui-line.cpp +++ b/tests/unit/gui/test-gui-line.cpp @@ -382,6 +382,22 @@ TEST(GuiLine, GetNextDisplayed) /* TODO: write tests */ } +/* + * Tests functions: + * gui_line_search_by_id + */ + +TEST(GuiLine, SearchById) +{ + POINTERS_EQUAL(NULL, gui_line_search_by_id (NULL, -1)); + POINTERS_EQUAL(NULL, gui_line_search_by_id (gui_buffers, -1)); + + POINTERS_EQUAL( + gui_buffers->own_lines->last_line, + gui_line_search_by_id (gui_buffers, + gui_buffers->own_lines->last_line->data->id)); +} + /* * Tests functions: * gui_line_search_text