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

Add new options for completion, optional stop instead of cycling with words found

This commit is contained in:
Sebastien Helleu
2008-06-18 16:47:09 +02:00
parent 47c9c68b40
commit 66e8d703bd
38 changed files with 1190 additions and 517 deletions
+50 -4
View File
@@ -2882,9 +2882,9 @@ weechat_lua_api_hook_config (lua_State *L)
*/
int
weechat_lua_api_hook_completion_cb (void *data, const char *completion,
weechat_lua_api_hook_completion_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_weelist *list)
struct t_gui_completion *completion)
{
struct t_script_callback *script_callback;
char *lua_argv[4];
@@ -2892,9 +2892,9 @@ weechat_lua_api_hook_completion_cb (void *data, const char *completion,
script_callback = (struct t_script_callback *)data;
lua_argv[0] = (char *)completion;
lua_argv[0] = (char *)completion_item;
lua_argv[1] = script_ptr2str (buffer);
lua_argv[2] = script_ptr2str (list);
lua_argv[2] = script_ptr2str (completion);
lua_argv[3] = NULL;
rc = (int *) weechat_lua_exec (script_callback->script,
@@ -2960,6 +2960,51 @@ weechat_lua_api_hook_completion (lua_State *L)
LUA_RETURN_STRING_FREE(result);
}
/*
* weechat_lua_api_hook_completion_list_add: add a word to list for a completion
*/
static int
weechat_lua_api_hook_completion_list_add (lua_State *L)
{
const char *completion, *word, *where;
int n, nick_completion;
/* make C compiler happy */
(void) L;
if (!lua_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_completion_list_add");
LUA_RETURN_ERROR;
}
completion = NULL;
word = NULL;
nick_completion = 0;
where = NULL;
n = lua_gettop (lua_current_interpreter);
if (n < 4)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_completion_list_add");
LUA_RETURN_ERROR;
}
completion = lua_tostring (lua_current_interpreter, -4);
word = lua_tostring (lua_current_interpreter, -3);
nick_completion = lua_tonumber (lua_current_interpreter, -2);
where = lua_tostring (lua_current_interpreter, -1);
weechat_hook_completion_list_add (script_str2ptr (completion),
word,
nick_completion,
where);
LUA_RETURN_OK;
}
/*
* weechat_lua_api_hook_modifier_cb: callback for modifier hooked
*/
@@ -4999,6 +5044,7 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
{ "hook_signal_send", &weechat_lua_api_hook_signal_send },
{ "hook_config", &weechat_lua_api_hook_config },
{ "hook_completion", &weechat_lua_api_hook_completion },
{ "hook_completion_list_add", &weechat_lua_api_hook_completion_list_add },
{ "hook_modifier", &weechat_lua_api_hook_modifier },
{ "hook_modifier_exec", &weechat_lua_api_hook_modifier_exec },
{ "unhook", &weechat_lua_api_unhook },
+4 -4
View File
@@ -413,16 +413,16 @@ weechat_lua_command_cb (void *data, struct t_gui_buffer *buffer,
*/
int
weechat_lua_completion_cb (void *data, const char *completion,
weechat_lua_completion_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_weelist *list)
struct t_gui_completion *completion)
{
/* make C compiler happy */
(void) data;
(void) completion;
(void) completion_item;
(void) buffer;
script_completion (weechat_lua_plugin, list, lua_scripts);
script_completion (weechat_lua_plugin, completion, lua_scripts);
return WEECHAT_RC_OK;
}
+41 -4
View File
@@ -2398,9 +2398,9 @@ static XS (XS_weechat_hook_config)
*/
int
weechat_perl_api_hook_completion_cb (void *data, const char *completion,
weechat_perl_api_hook_completion_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_weelist *list)
struct t_gui_completion *completion)
{
struct t_script_callback *script_callback;
char *perl_argv[4];
@@ -2408,9 +2408,9 @@ weechat_perl_api_hook_completion_cb (void *data, const char *completion,
script_callback = (struct t_script_callback *)data;
perl_argv[0] = (char *)completion;
perl_argv[0] = (char *)completion_item;
perl_argv[1] = script_ptr2str (buffer);
perl_argv[2] = script_ptr2str (list);
perl_argv[2] = script_ptr2str (completion);
perl_argv[3] = NULL;
rc = (int *) weechat_perl_exec (script_callback->script,
@@ -2468,6 +2468,42 @@ static XS (XS_weechat_hook_completion)
PERL_RETURN_STRING_FREE(result);
}
/*
* weechat::hook_completion_list_add: add a word to list for a completion
*/
static XS (XS_weechat_hook_completion_list_add)
{
char *completion, *word, *where;
dXSARGS;
/* make C compiler happy */
(void) cv;
if (!perl_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_completion_list_add");
PERL_RETURN_ERROR;
}
if (items < 4)
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_completion_list_add");
PERL_RETURN_ERROR;
}
completion = SvPV (ST (0), PL_na);
word = SvPV (ST (1), PL_na);
where = SvPV (ST (3), PL_na);
weechat_hook_completion_list_add (script_str2ptr (completion),
word,
SvIV (ST (2)), /* nick_completion */
where);
PERL_RETURN_OK;
}
/*
* weechat_perl_api_hook_modifier_cb: callback for modifier hooked
*/
@@ -3922,6 +3958,7 @@ weechat_perl_api_init (pTHX)
newXS ("weechat::hook_signal_send", XS_weechat_hook_signal_send, "weechat");
newXS ("weechat::hook_config", XS_weechat_hook_config, "weechat");
newXS ("weechat::hook_completion", XS_weechat_hook_completion, "weechat");
newXS ("weechat::hook_completion_list_add", XS_weechat_hook_completion_list_add, "weechat");
newXS ("weechat::hook_modifier", XS_weechat_hook_modifier, "weechat");
newXS ("weechat::hook_modifier_exec", XS_weechat_hook_modifier_exec, "weechat");
newXS ("weechat::unhook", XS_weechat_unhook, "weechat");
+4 -4
View File
@@ -554,16 +554,16 @@ weechat_perl_command_cb (void *data, struct t_gui_buffer *buffer,
*/
int
weechat_perl_completion_cb (void *data, const char *completion,
weechat_perl_completion_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_weelist *list)
struct t_gui_completion *completion)
{
/* make C compiler happy */
(void) data;
(void) completion;
(void) completion_item;
(void) buffer;
script_completion (weechat_perl_plugin, list, perl_scripts);
script_completion (weechat_perl_plugin, completion, perl_scripts);
return WEECHAT_RC_OK;
}
@@ -2552,9 +2552,9 @@ weechat_python_api_hook_config (PyObject *self, PyObject *args)
*/
int
weechat_python_api_hook_completion_cb (void *data, const char *completion,
weechat_python_api_hook_completion_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_weelist *list)
struct t_gui_completion *completion)
{
struct t_script_callback *script_callback;
char *python_argv[4];
@@ -2562,9 +2562,9 @@ weechat_python_api_hook_completion_cb (void *data, const char *completion,
script_callback = (struct t_script_callback *)data;
python_argv[0] = (char *)completion;
python_argv[0] = (char *)completion_item;
python_argv[1] = script_ptr2str (buffer);
python_argv[2] = script_ptr2str (list);
python_argv[2] = script_ptr2str (completion);
python_argv[3] = NULL;
rc = (int *) weechat_python_exec (script_callback->script,
@@ -2624,6 +2624,45 @@ weechat_python_api_hook_completion (PyObject *self, PyObject *args)
PYTHON_RETURN_STRING_FREE(result);
}
/*
* weechat_python_api_hook_completion_list_add: add a word to list for a completion
*/
static PyObject *
weechat_python_api_hook_completion_list_add (PyObject *self, PyObject *args)
{
char *completion, *word, *where;
int nick_completion;
/* make C compiler happy */
(void) self;
if (!python_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_completion_list_add");
PYTHON_RETURN_ERROR;
}
completion = NULL;
word = NULL;
nick_completion = 0;
where = NULL;
if (!PyArg_ParseTuple (args, "ssis", &completion, &word, &nick_completion,
&where))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_completion_list_add");
PYTHON_RETURN_ERROR;
}
weechat_hook_completion_list_add (script_str2ptr (completion),
word,
nick_completion,
where);
PYTHON_RETURN_OK;
}
/*
* weechat_python_api_hook_modifier_cb: callback for modifier hooked
*/
@@ -4169,6 +4208,7 @@ PyMethodDef weechat_python_funcs[] =
{ "hook_signal_send", &weechat_python_api_hook_signal_send, METH_VARARGS, "" },
{ "hook_config", &weechat_python_api_hook_config, METH_VARARGS, "" },
{ "hook_completion", &weechat_python_api_hook_completion, METH_VARARGS, "" },
{ "hook_completion_list_add", &weechat_python_api_hook_completion_list_add, METH_VARARGS, "" },
{ "hook_modifier", &weechat_python_api_hook_modifier, METH_VARARGS, "" },
{ "hook_modifier_exec", &weechat_python_api_hook_modifier_exec, METH_VARARGS, "" },
{ "unhook", &weechat_python_api_unhook, METH_VARARGS, "" },
+4 -4
View File
@@ -605,16 +605,16 @@ weechat_python_command_cb (void *data, struct t_gui_buffer *buffer,
*/
int
weechat_python_completion_cb (void *data, const char *completion,
weechat_python_completion_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_weelist *list)
struct t_gui_completion *completion)
{
/* make C compiler happy */
(void) data;
(void) completion;
(void) completion_item;
(void) buffer;
script_completion (weechat_python_plugin, list, python_scripts);
script_completion (weechat_python_plugin, completion, python_scripts);
return WEECHAT_RC_OK;
}
+56 -4
View File
@@ -2939,9 +2939,9 @@ weechat_ruby_api_hook_config (VALUE class, VALUE option, VALUE function)
*/
int
weechat_ruby_api_hook_completion_cb (void *data, const char *completion,
weechat_ruby_api_hook_completion_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_weelist *list)
struct t_gui_completion *completion)
{
struct t_script_callback *script_callback;
char *ruby_argv[4];
@@ -2949,9 +2949,9 @@ weechat_ruby_api_hook_completion_cb (void *data, const char *completion,
script_callback = (struct t_script_callback *)data;
ruby_argv[0] = (char *)completion;
ruby_argv[0] = (char *)completion_item;
ruby_argv[1] = script_ptr2str (buffer);
ruby_argv[2] = script_ptr2str (list);
ruby_argv[2] = script_ptr2str (completion);
ruby_argv[3] = NULL;
rc = (int *) weechat_ruby_exec (script_callback->script,
@@ -3018,6 +3018,57 @@ weechat_ruby_api_hook_completion (VALUE class, VALUE completion,
RUBY_RETURN_STRING_FREE(result);
}
/*
* weechat_ruby_api_hook_completion_list_add: add a word to list for a completion
*/
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;
/* make C compiler happy */
(void) class;
if (!ruby_current_script)
{
WEECHAT_SCRIPT_MSG_NOT_INITIALIZED("hook_completion_list_add");
RUBY_RETURN_ERROR;
}
c_completion = NULL;
c_word = NULL;
c_nick_completion = 0;
c_where = NULL;
if (NIL_P (completion) || NIL_P (word) || NIL_P (nick_completion)
|| NIL_P (where))
{
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_completion_list_add");
RUBY_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 = STR2CSTR (completion);
c_word = STR2CSTR (word);
c_nick_completion = FIX2INT (nick_completion);
c_where = STR2CSTR (where);
weechat_hook_completion_list_add (script_str2ptr (c_completion),
c_word,
c_nick_completion,
c_where);
RUBY_RETURN_OK;
}
/*
* weechat_ruby_api_hook_modifier_cb: callback for modifier hooked
*/
@@ -4800,6 +4851,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
rb_define_module_function (ruby_mWeechat, "hook_signal_send", &weechat_ruby_api_hook_signal_send, 3);
rb_define_module_function (ruby_mWeechat, "hook_config", &weechat_ruby_api_hook_config, 2);
rb_define_module_function (ruby_mWeechat, "hook_completion", &weechat_ruby_api_hook_completion, 2);
rb_define_module_function (ruby_mWeechat, "hook_completion_list_add", &weechat_ruby_api_hook_completion_list_add, 4);
rb_define_module_function (ruby_mWeechat, "hook_modifier", &weechat_ruby_api_hook_modifier, 2);
rb_define_module_function (ruby_mWeechat, "hook_modifier_exec", &weechat_ruby_api_hook_modifier_exec, 3);
rb_define_module_function (ruby_mWeechat, "unhook", &weechat_ruby_api_unhook, 1);
+4 -4
View File
@@ -589,16 +589,16 @@ weechat_ruby_command_cb (void *data, struct t_gui_buffer *buffer,
*/
int
weechat_ruby_completion_cb (void *data, const char *completion,
weechat_ruby_completion_cb (void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_weelist *list)
struct t_gui_completion *completion)
{
/* make C compiler happy */
(void) data;
(void) completion;
(void) completion_item;
(void) buffer;
script_completion (weechat_ruby_plugin, list, ruby_scripts);
script_completion (weechat_ruby_plugin, completion, ruby_scripts);
return WEECHAT_RC_OK;
}
+3 -2
View File
@@ -832,9 +832,10 @@ struct t_hook *
script_api_hook_completion (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
const char *completion,
int (*callback)(void *data, const char *completion,
int (*callback)(void *data,
const char *completion_item,
struct t_gui_buffer *buffer,
struct t_weelist *list),
struct t_gui_completion *completion),
const char *function)
{
struct t_script_callback *new_script_callback;
+2 -2
View File
@@ -142,9 +142,9 @@ extern struct t_hook *script_api_hook_completion (struct t_weechat_plugin *weech
struct t_plugin_script *script,
const char *completion,
int (*callback)(void *data,
const char *completion,
const char *completion_item,
struct t_gui_buffer *buffer,
struct t_weelist *list),
struct t_gui_completion *completion),
const char *function);
extern struct t_hook *script_api_hook_modifier (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *script,
+5 -4
View File
@@ -84,9 +84,9 @@ script_init (struct t_weechat_plugin *weechat_plugin,
struct t_gui_buffer *buffer,
int argc, char **argv,
char **argv_eol),
int (*callback_completion)(void *data, const char *completion,
int (*callback_completion)(void *data, const char *completion_item,
struct t_gui_buffer *buffer,
struct t_weelist *list),
struct t_gui_completion *completion),
int (*callback_signal_debug_dump)(void *data, const char *signal,
const char *type_data,
void *signal_data),
@@ -525,7 +525,7 @@ script_remove (struct t_weechat_plugin *weechat_plugin,
void
script_completion (struct t_weechat_plugin *weechat_plugin,
struct t_weelist *list,
struct t_gui_completion *completion,
struct t_plugin_script *scripts)
{
struct t_plugin_script *ptr_script;
@@ -533,7 +533,8 @@ script_completion (struct t_weechat_plugin *weechat_plugin,
for (ptr_script = scripts; ptr_script;
ptr_script = ptr_script->next_script)
{
weechat_list_add (list, ptr_script->name, WEECHAT_LIST_POS_SORT);
weechat_hook_completion_list_add (completion, ptr_script->name,
0, WEECHAT_LIST_POS_SORT);
}
}
+4 -3
View File
@@ -61,9 +61,10 @@ extern void script_init (struct t_weechat_plugin *weechat_plugin,
struct t_gui_buffer *buffer,
int argc, char **argv,
char **argv_eol),
int (*callback_completion)(void *data, const char *completion,
int (*callback_completion)(void *data,
const char *completion_item,
struct t_gui_buffer *buffer,
struct t_weelist *list),
struct t_gui_completion *completion),
int (*callback_signal_debug_dump)(void *data,
const char *signal,
const char *type_data,
@@ -94,7 +95,7 @@ extern void script_remove (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script **scripts,
struct t_plugin_script *script);
extern void script_completion (struct t_weechat_plugin *weechat_plugin,
struct t_weelist *list,
struct t_gui_completion *completion,
struct t_plugin_script *scripts);
extern void script_display_list (struct t_weechat_plugin *weechat_plugin,
struct t_plugin_script *scripts,