1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-12 14:14:48 +02:00

api: add function line_search_by_id

This commit is contained in:
Sébastien Helleu
2024-06-27 07:03:55 +02:00
parent 0e9ed21edf
commit f076db4767
26 changed files with 448 additions and 3 deletions
+1
View File
@@ -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
+40
View File
@@ -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
+40
View File
@@ -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
+44
View File
@@ -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
+44
View File
@@ -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]]
=== ウィンドウ
+44
View File
@@ -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]]
=== Прозори
+25
View File
@@ -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.
*
+2
View File
@@ -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,
+17
View File
@@ -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);
+17
View File
@@ -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);
+18
View File
@@ -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),
+18
View File
@@ -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);
+21
View File
@@ -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;
+1
View File
@@ -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);
+1
View File
@@ -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)
+1
View File
@@ -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 {}
+3 -1
View File
@@ -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
+3 -1
View File
@@ -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
+3
View File
@@ -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;
+18
View File
@@ -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),
+10
View File
@@ -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 <https://weechat.org/doc/weechat/api/#_line_search_by_id>`_
::
# example
line = weechat.line_search_by_id(buffer, 123)
"""
...
def current_window() -> str:
"""`current_window in WeeChat plugin API reference <https://weechat.org/doc/weechat/api/#_current_window>`_
::
+24
View File
@@ -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);
+20
View File
@@ -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);
+8 -1
View File
@@ -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)
+9
View File
@@ -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()
+16
View File
@@ -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