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

api: return integer in function gui_completion_search (issue #1484)

This commit is contained in:
Sébastien Helleu
2020-04-28 10:46:49 +02:00
parent 2bd8e91b54
commit d1a427b67f
16 changed files with 139 additions and 95 deletions
+13 -5
View File
@@ -14993,8 +14993,8 @@ Prototype:
[source,C]
----
void weechat_completion_search (struct t_gui_completion *completion, const char *data,
int position, int direction);
int weechat_completion_search (struct t_gui_completion *completion, const char *data,
int position, int direction);
----
Arguments:
@@ -15004,12 +15004,19 @@ Arguments:
* _position_: index of the char in string to complete (starts to 0)
* _direction_: 1 for next completion, -1 for previous completion
Return value:
* 1 if OK, 0 if error
C example:
[source,C]
----
struct t_gui_completion *completion = weechat_completion_new (weechat_buffer_search_main ());
weechat_completion_search (completion, "/help filt", 10, 1);
if (weechat_completion_search (completion, "/help filt", 10, 1))
{
/* ... */
}
----
Script (Python):
@@ -15017,11 +15024,12 @@ Script (Python):
[source,python]
----
# prototype
weechat.completion_search(completion, data, position, direction)
rc = weechat.completion_search(completion, data, position, direction)
# example
completion = weechat.completion_new(weechat.buffer_search_main())
weechat.completion_search(completion, "/help filt", 10, 1);
if weechat.completion_search(completion, "/help filt", 10, 1):
# ...
----
==== completion_free
+13 -5
View File
@@ -15312,8 +15312,8 @@ Prototype :
[source,C]
----
void weechat_completion_search (struct t_gui_completion *completion, const char *data,
int position, int direction);
int weechat_completion_search (struct t_gui_completion *completion, const char *data,
int position, int direction);
----
Paramètres :
@@ -15323,12 +15323,19 @@ Paramètres :
* _position_ : index du caractère dans la chaîne à compléter (commence à 0)
* _direction_ : 1 pour la complétion suivante, -1 pour la complétion précédente
Valeur de retour :
* 1 si OK, 0 si erreur
Exemple en C :
[source,C]
----
struct t_gui_completion *completion = weechat_completion_new (weechat_buffer_search_main ());
weechat_completion_search (completion, "/help filt", 10, 1);
if (weechat_completion_search (completion, "/help filt", 10, 1))
{
/* ... */
}
----
Script (Python) :
@@ -15336,11 +15343,12 @@ Script (Python) :
[source,python]
----
# prototype
weechat.completion_search(completion, data, position, direction)
rc = weechat.completion_search(completion, data, position, direction)
# exemple
completion = weechat.completion_new(weechat.buffer_search_main())
weechat.completion_search(completion, "/help filt", 10, 1);
if weechat.completion_search(completion, "/help filt", 10, 1):
# ...
----
==== completion_free
+14 -5
View File
@@ -15593,8 +15593,8 @@ Prototipo:
[source,C]
----
void weechat_completion_search (struct t_gui_completion *completion, const char *data,
int position, int direction);
int weechat_completion_search (struct t_gui_completion *completion, const char *data,
int position, int direction);
----
Argomenti:
@@ -15604,12 +15604,20 @@ Argomenti:
* _position_: index of the char in string to complete (starts to 0)
* _direction_: 1 for next completion, -1 for previous completion
Valore restituito:
// TRANSLATION MISSING
* 1 if OK, 0 if error
Esempio in C:
[source,C]
----
struct t_gui_completion *completion = weechat_completion_new (weechat_buffer_search_main ());
weechat_completion_search (completion, "/help filt", 10, 1);
if (weechat_completion_search (completion, "/help filt", 10, 1))
{
/* ... */
}
----
Script (Python):
@@ -15617,11 +15625,12 @@ Script (Python):
[source,python]
----
# prototipo
weechat.completion_search(completion, data, position, direction)
rc = weechat.completion_search(completion, data, position, direction)
# esempio
completion = weechat.completion_new(weechat.buffer_search_main())
weechat.completion_search(completion, "/help filt", 10, 1);
if weechat.completion_search(completion, "/help filt", 10, 1):
# ...
----
// TRANSLATION MISSING
+13 -5
View File
@@ -14978,8 +14978,8 @@ context.
[source,C]
----
void weechat_completion_search (struct t_gui_completion *completion, const char *data,
int position, int direction);
int weechat_completion_search (struct t_gui_completion *completion, const char *data,
int position, int direction);
----
引数:
@@ -14989,12 +14989,19 @@ void weechat_completion_search (struct t_gui_completion *completion, const char
* _position_: index of the char in string to complete (starts to 0)
* _direction_: 1 for next completion, -1 for previous completion
戻り値:
* 成功した場合は 1、失敗した場合は 0
C 言語での使用例:
[source,C]
----
struct t_gui_completion *completion = weechat_completion_new (weechat_buffer_search_main ());
weechat_completion_search (completion, "/help filt", 10, 1);
if (weechat_completion_search (completion, "/help filt", 10, 1))
{
/* ... */
}
----
スクリプト (Python) での使用例:
@@ -15002,11 +15009,12 @@ weechat_completion_search (completion, "/help filt", 10, 1);
[source,python]
----
# prototype
weechat.completion_search(completion, data, position, direction)
rc = weechat.completion_search(completion, data, position, direction)
# example
completion = weechat.completion_new(weechat.buffer_search_main())
weechat.completion_search(completion, "/help filt", 10, 1);
if weechat.completion_search(completion, "/help filt", 10, 1):
# ...
----
// TRANSLATION MISSING
+6 -4
View File
@@ -1370,15 +1370,15 @@ gui_completion_auto (struct t_gui_completion *completion)
* Completes word according to context.
*/
void
int
gui_completion_search (struct t_gui_completion *completion, const char *data,
int position, int direction)
{
char *old_word_found;
int real_position;
if (!data)
return;
if (!completion || !data || (position < 0))
return 0;
real_position = utf8_real_pos (data, position);
@@ -1404,7 +1404,7 @@ gui_completion_search (struct t_gui_completion *completion, const char *data,
/* should never be executed */
if (old_word_found)
free (old_word_found);
return;
return 0;
case GUI_COMPLETION_COMMAND:
gui_completion_command (completion);
break;
@@ -1440,6 +1440,8 @@ gui_completion_search (struct t_gui_completion *completion, const char *data,
}
if (old_word_found)
free (old_word_found);
return 1;
}
/*
+3 -3
View File
@@ -88,9 +88,9 @@ extern void gui_completion_stop (struct t_gui_completion *completion);
extern void gui_completion_list_add (struct t_gui_completion *completion,
const char *word,
int nick_completion, const char *where);
extern void gui_completion_search (struct t_gui_completion *completion,
const char *data, int position,
int direction);
extern int gui_completion_search (struct t_gui_completion *completion,
const char *data, int position,
int direction);
extern const char *gui_completion_get_string (struct t_gui_completion *completion,
const char *property);
extern struct t_hdata *gui_completion_hdata_completion_cb (const void *pointer,
+22 -16
View File
@@ -532,14 +532,17 @@ gui_input_complete_next (struct t_gui_buffer *buffer)
&& (buffer->text_search == GUI_TEXT_SEARCH_DISABLED))
{
gui_buffer_undo_snap (buffer);
gui_completion_search (buffer->completion,
buffer->input_buffer,
buffer->input_buffer_pos,
1);
gui_input_complete (buffer);
gui_input_text_changed_modifier_and_signal (buffer,
1, /* save undo */
0); /* stop completion */
if (gui_completion_search (buffer->completion,
buffer->input_buffer,
buffer->input_buffer_pos,
1))
{
gui_input_complete (buffer);
gui_input_text_changed_modifier_and_signal (
buffer,
1, /* save undo */
0); /* stop completion */
}
}
}
@@ -554,14 +557,17 @@ gui_input_complete_previous (struct t_gui_buffer *buffer)
&& (buffer->text_search == GUI_TEXT_SEARCH_DISABLED))
{
gui_buffer_undo_snap (buffer);
gui_completion_search (buffer->completion,
buffer->input_buffer,
buffer->input_buffer_pos,
-1);
gui_input_complete (buffer);
gui_input_text_changed_modifier_and_signal (buffer,
1, /* save undo */
0); /* stop completion */
if (gui_completion_search (buffer->completion,
buffer->input_buffer,
buffer->input_buffer_pos,
-1))
{
gui_input_complete (buffer);
gui_input_text_changed_modifier_and_signal (
buffer,
1, /* save undo */
0); /* stop completion */
}
}
}
+9 -7
View File
@@ -4122,17 +4122,19 @@ SCM
weechat_guile_api_completion_search (SCM completion, SCM data, SCM position,
SCM direction)
{
API_INIT_FUNC(1, "completion_search", API_RETURN_ERROR);
int rc;
API_INIT_FUNC(1, "completion_search", API_RETURN_INT(0));
if (!scm_is_string (completion) || !scm_is_string (data)
|| !scm_is_integer (position) || !scm_is_integer (direction))
API_WRONG_ARGS(API_RETURN_ERROR);
API_WRONG_ARGS(API_RETURN_INT(0));
weechat_completion_search (API_STR2PTR(API_SCM_TO_STRING(completion)),
API_SCM_TO_STRING(data),
scm_to_int (position),
scm_to_int (direction));
rc = weechat_completion_search (API_STR2PTR(API_SCM_TO_STRING(completion)),
API_SCM_TO_STRING(data),
scm_to_int (position),
scm_to_int (direction));
API_RETURN_OK;
API_RETURN_INT(rc);
}
SCM
+4 -4
View File
@@ -4015,22 +4015,22 @@ API_FUNC(completion_new)
API_FUNC(completion_search)
{
int position, direction;
int position, direction, rc;
API_INIT_FUNC(1, "completion_search", "ssii", API_RETURN_ERROR);
API_INIT_FUNC(1, "completion_search", "ssii", API_RETURN_INT(0));
v8::String::Utf8Value completion(args[0]);
v8::String::Utf8Value data(args[1]);
position = args[2]->IntegerValue();
direction = args[3]->IntegerValue();
weechat_completion_search (
rc = weechat_completion_search (
(struct t_gui_completion *)API_STR2PTR(*completion),
(const char *)(*data),
position,
direction);
API_RETURN_OK;
API_RETURN_INT(rc);
}
API_FUNC(completion_free)
+6 -6
View File
@@ -4356,21 +4356,21 @@ API_FUNC(completion_new)
API_FUNC(completion_search)
{
const char *completion, *data;
int position, direction;
int position, direction, rc;
API_INIT_FUNC(1, "completion_search", API_RETURN_ERROR);
API_INIT_FUNC(1, "completion_search", API_RETURN_INT(0));
if (lua_gettop (L) < 4)
API_WRONG_ARGS(API_RETURN_ERROR);
API_WRONG_ARGS(API_RETURN_INT(0));
completion = lua_tostring (L, -4);
data = lua_tostring (L, -3);
position = lua_tonumber (L, -2);
direction = lua_tonumber (L, -1);
weechat_completion_search (API_STR2PTR(completion), data, position,
direction);
rc = weechat_completion_search (API_STR2PTR(completion), data, position,
direction);
API_RETURN_OK;
API_RETURN_INT(rc);
}
API_FUNC(completion_free)
+8 -7
View File
@@ -4278,21 +4278,22 @@ API_FUNC(completion_new)
API_FUNC(completion_search)
{
char *completion, *data;
int rc;
dXSARGS;
API_INIT_FUNC(1, "completion_search", API_RETURN_ERROR);
API_INIT_FUNC(1, "completion_search", API_RETURN_INT(0));
if (items < 4)
API_WRONG_ARGS(API_RETURN_ERROR);
API_WRONG_ARGS(API_RETURN_INT(0));
completion = SvPV_nolen (ST (0));
data = SvPV_nolen (ST (1));
weechat_completion_search (API_STR2PTR(completion),
data,
SvIV (ST (2)), /* position */
SvIV (ST (3))); /* direction */
rc = weechat_completion_search (API_STR2PTR(completion),
data,
SvIV (ST (2)), /* position */
SvIV (ST (3))); /* direction */
API_RETURN_OK;
API_RETURN_INT(rc);
}
API_FUNC(completion_free)
+5 -5
View File
@@ -4291,21 +4291,21 @@ API_FUNC(completion_search)
zend_long z_position, z_direction;
char *data;
struct t_gui_completion *completion;
int position, direction;
int position, direction, rc;
API_INIT_FUNC(1, "completion_search", API_RETURN_ERROR);
API_INIT_FUNC(1, "completion_search", API_RETURN_INT(0));
if (zend_parse_parameters (ZEND_NUM_ARGS(), "SSll", &z_completion, &z_data,
&z_position, &z_direction) == FAILURE)
API_WRONG_ARGS(API_RETURN_ERROR);
API_WRONG_ARGS(API_RETURN_INT(0));
completion = (struct t_gui_completion *)API_STR2PTR(ZSTR_VAL(z_completion));
data = ZSTR_VAL(z_data);
position = (int)z_position;
direction = (int)z_direction;
weechat_completion_search (completion, data, position, direction);
rc = weechat_completion_search (completion, data, position, direction);
API_RETURN_OK;
API_RETURN_INT(rc);
}
API_FUNC(completion_free)
+8 -8
View File
@@ -4290,22 +4290,22 @@ API_FUNC(completion_new)
API_FUNC(completion_search)
{
char *completion, *data;
int position, direction;
int position, direction, rc;
API_INIT_FUNC(1, "completion_search", API_RETURN_ERROR);
API_INIT_FUNC(1, "completion_search", API_RETURN_INT(0));
completion = NULL;
position = 0;
direction = 1;
if (!PyArg_ParseTuple (args, "ssii", &completion, &data, &position,
&direction))
API_WRONG_ARGS(API_RETURN_ERROR);
API_WRONG_ARGS(API_RETURN_INT(0));
weechat_completion_search (API_STR2PTR(completion),
data,
position,
direction);
rc = weechat_completion_search (API_STR2PTR(completion),
data,
position,
direction);
API_RETURN_OK;
API_RETURN_INT(rc);
}
API_FUNC(completion_free)
+6 -6
View File
@@ -5174,12 +5174,12 @@ weechat_ruby_api_completion_search (VALUE class, VALUE completion, VALUE data,
VALUE position, VALUE direction)
{
char *c_completion, *c_data;
int c_position, c_direction;
int c_position, c_direction, rc;
API_INIT_FUNC(1, "completion_search", API_RETURN_ERROR);
API_INIT_FUNC(1, "completion_search", API_RETURN_INT(0));
if (NIL_P (completion) || NIL_P (data) || NIL_P(position)
|| NIL_P(direction))
API_WRONG_ARGS(API_RETURN_ERROR);
API_WRONG_ARGS(API_RETURN_INT(0));
Check_Type (completion, T_STRING);
Check_Type (data, T_STRING);
@@ -5191,10 +5191,10 @@ weechat_ruby_api_completion_search (VALUE class, VALUE completion, VALUE data,
c_position = NUM2INT (position);
c_direction = NUM2INT (direction);
weechat_completion_search (API_STR2PTR(c_completion), c_data, c_position,
c_direction);
rc = weechat_completion_search (API_STR2PTR(c_completion), c_data,
c_position, c_direction);
API_RETURN_OK;
API_RETURN_INT(rc);
}
static VALUE
+6 -6
View File
@@ -4646,11 +4646,11 @@ API_FUNC(completion_search)
{
Tcl_Obj *objp;
char *completion, *data;
int i, position, direction;
int i, position, direction, rc;
API_INIT_FUNC(1, "completion_search", API_RETURN_ERROR);
API_INIT_FUNC(1, "completion_search", API_RETURN_INT(0));
if (objc < 5)
API_WRONG_ARGS(API_RETURN_ERROR);
API_WRONG_ARGS(API_RETURN_INT(0));
completion = Tcl_GetStringFromObj (objv[1], &i);
data = Tcl_GetStringFromObj (objv[2], &i);
@@ -4659,10 +4659,10 @@ API_FUNC(completion_search)
|| (Tcl_GetIntFromObj (interp, objv[4], &direction) != TCL_OK))
API_WRONG_ARGS(API_RETURN_ERROR);
weechat_completion_search (API_STR2PTR(completion), data, position,
direction);
rc = weechat_completion_search (API_STR2PTR(completion), data, position,
direction);
API_RETURN_OK;
API_RETURN_INT(rc);
}
API_FUNC(info_get)
+3 -3
View File
@@ -67,7 +67,7 @@ struct timeval;
* please change the date with current one; for a second change at same
* date, increment the 01, otherwise please keep 01.
*/
#define WEECHAT_PLUGIN_API_VERSION "20200426-01"
#define WEECHAT_PLUGIN_API_VERSION "20200428-01"
/* macros for defining plugin infos */
#define WEECHAT_PLUGIN_NAME(__name) \
@@ -1012,8 +1012,8 @@ struct t_weechat_plugin
/* completion */
struct t_gui_completion *(*completion_new) (struct t_weechat_plugin *plugin,
struct t_gui_buffer *buffer);
void (*completion_search) (struct t_gui_completion *completion,
const char *data, int position, int direction);
int (*completion_search) (struct t_gui_completion *completion,
const char *data, int position, int direction);
void (*completion_free) (struct t_gui_completion *completion);
/* network */