mirror of
https://github.com/weechat/weechat.git
synced 2026-06-26 04:46:37 +02:00
Add support of many templates for completion of command arguments, rename default completion items
This commit is contained in:
@@ -3930,7 +3930,7 @@ weechat_lua_api_hook_completion_cb (void *data, const char *completion_item,
|
||||
static int
|
||||
weechat_lua_api_hook_completion (lua_State *L)
|
||||
{
|
||||
const char *completion, *function;
|
||||
const char *completion, *description, *function;
|
||||
char *result;
|
||||
int n;
|
||||
|
||||
@@ -3944,22 +3944,25 @@ weechat_lua_api_hook_completion (lua_State *L)
|
||||
}
|
||||
|
||||
completion = NULL;
|
||||
description = NULL;
|
||||
function = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n < 2)
|
||||
if (n < 3)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_completion");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
completion = lua_tostring (lua_current_interpreter, -2);
|
||||
completion = lua_tostring (lua_current_interpreter, -3);
|
||||
description = lua_tostring (lua_current_interpreter, -2);
|
||||
function = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
result = script_ptr2str (script_api_hook_completion (weechat_lua_plugin,
|
||||
lua_current_script,
|
||||
completion,
|
||||
description,
|
||||
&weechat_lua_api_hook_completion_cb,
|
||||
function));
|
||||
|
||||
|
||||
@@ -3317,7 +3317,7 @@ weechat_perl_api_hook_completion_cb (void *data, const char *completion_item,
|
||||
|
||||
static XS (XS_weechat_api_hook_completion)
|
||||
{
|
||||
char *result, *completion, *function;
|
||||
char *result, *completion, *description, *function;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -3329,17 +3329,19 @@ static XS (XS_weechat_api_hook_completion)
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (items < 2)
|
||||
if (items < 3)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_completion");
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
completion = SvPV (ST (0), PL_na);
|
||||
function = SvPV (ST (1), PL_na);
|
||||
description = SvPV (ST (1), PL_na);
|
||||
function = SvPV (ST (2), PL_na);
|
||||
result = script_ptr2str (script_api_hook_completion (weechat_perl_plugin,
|
||||
perl_current_script,
|
||||
completion,
|
||||
description,
|
||||
&weechat_perl_api_hook_completion_cb,
|
||||
function));
|
||||
|
||||
|
||||
@@ -3527,7 +3527,7 @@ weechat_python_api_hook_completion_cb (void *data, const char *completion_item,
|
||||
static PyObject *
|
||||
weechat_python_api_hook_completion (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *completion, *function, *result;
|
||||
char *completion, *description, *function, *result;
|
||||
PyObject *object;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -3540,9 +3540,10 @@ weechat_python_api_hook_completion (PyObject *self, PyObject *args)
|
||||
}
|
||||
|
||||
completion = NULL;
|
||||
description = NULL;
|
||||
function = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "ss", &completion, &function))
|
||||
if (!PyArg_ParseTuple (args, "sss", &completion, &description, &function))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_completion");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
@@ -3551,6 +3552,7 @@ weechat_python_api_hook_completion (PyObject *self, PyObject *args)
|
||||
result = script_ptr2str(script_api_hook_completion (weechat_python_plugin,
|
||||
python_current_script,
|
||||
completion,
|
||||
description,
|
||||
&weechat_python_api_hook_completion_cb,
|
||||
function));
|
||||
|
||||
|
||||
@@ -4020,9 +4020,9 @@ weechat_ruby_api_hook_completion_cb (void *data, const char *completion_item,
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_hook_completion (VALUE class, VALUE completion,
|
||||
VALUE function)
|
||||
VALUE description, VALUE function)
|
||||
{
|
||||
char *c_completion, *c_function, *result;
|
||||
char *c_completion, *c_description, *c_function, *result;
|
||||
VALUE return_value;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -4035,23 +4035,27 @@ weechat_ruby_api_hook_completion (VALUE class, VALUE completion,
|
||||
}
|
||||
|
||||
c_completion = NULL;
|
||||
c_description = NULL;
|
||||
c_function = NULL;
|
||||
|
||||
if (NIL_P (completion) || NIL_P (function))
|
||||
if (NIL_P (completion) || NIL_P (description) || NIL_P (function))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_completion");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
Check_Type (completion, T_STRING);
|
||||
Check_Type (description, T_STRING);
|
||||
Check_Type (function, T_STRING);
|
||||
|
||||
c_completion = STR2CSTR (completion);
|
||||
c_description = STR2CSTR (description);
|
||||
c_function = STR2CSTR (function);
|
||||
|
||||
result = script_ptr2str (script_api_hook_completion (weechat_ruby_plugin,
|
||||
ruby_current_script,
|
||||
c_completion,
|
||||
c_description,
|
||||
&weechat_ruby_api_hook_completion_cb,
|
||||
c_function));
|
||||
|
||||
@@ -6657,7 +6661,7 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
|
||||
rb_define_module_function (ruby_mWeechat, "hook_signal", &weechat_ruby_api_hook_signal, 2);
|
||||
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", &weechat_ruby_api_hook_completion, 3);
|
||||
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);
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include "../weechat-plugin.h"
|
||||
#include "script.h"
|
||||
#include "script-api.h"
|
||||
#include "script-callback.h"
|
||||
|
||||
|
||||
@@ -1076,6 +1077,7 @@ struct t_hook *
|
||||
script_api_hook_completion (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
const char *completion,
|
||||
const char *description,
|
||||
int (*callback)(void *data,
|
||||
const char *completion_item,
|
||||
struct t_gui_buffer *buffer,
|
||||
@@ -1089,7 +1091,8 @@ script_api_hook_completion (struct t_weechat_plugin *weechat_plugin,
|
||||
if (!new_script_callback)
|
||||
return NULL;
|
||||
|
||||
new_hook = weechat_hook_completion (completion, callback, new_script_callback);
|
||||
new_hook = weechat_hook_completion (completion, description,
|
||||
callback, new_script_callback);
|
||||
if (!new_hook)
|
||||
{
|
||||
script_callback_free_data (new_script_callback);
|
||||
|
||||
@@ -196,6 +196,7 @@ extern struct t_hook *script_api_hook_config (struct t_weechat_plugin *weechat_p
|
||||
extern struct t_hook *script_api_hook_completion (struct t_weechat_plugin *weechat_plugin,
|
||||
struct t_plugin_script *script,
|
||||
const char *completion,
|
||||
const char *description,
|
||||
int (*callback)(void *data,
|
||||
const char *completion_item,
|
||||
struct t_gui_buffer *buffer,
|
||||
|
||||
@@ -105,7 +105,7 @@ script_init (struct t_weechat_plugin *weechat_plugin,
|
||||
void *signal_data),
|
||||
void (*callback_load_file)(void *data, const char *filename))
|
||||
{
|
||||
char *string, *completion = "list|listfull|load|autoload|reload|unload %f";
|
||||
char *string, *completion = "list|listfull|load|autoload|reload|unload %(filename)";
|
||||
char infolist_description[512], signal_name[128];
|
||||
int length;
|
||||
|
||||
@@ -162,7 +162,8 @@ script_init (struct t_weechat_plugin *weechat_plugin,
|
||||
if (string)
|
||||
{
|
||||
snprintf (string, length, "%s_script", weechat_plugin->name);
|
||||
weechat_hook_completion (string, callback_completion, NULL);
|
||||
weechat_hook_completion (string, N_("list of scripts"),
|
||||
callback_completion, NULL);
|
||||
snprintf (infolist_description, sizeof (infolist_description),
|
||||
/* TRANSLATORS: %s is language (for example "perl") */
|
||||
_("list of %s scripts"), weechat_plugin->name);
|
||||
|
||||
@@ -3765,7 +3765,7 @@ weechat_tcl_api_hook_completion (ClientData clientData, Tcl_Interp *interp,
|
||||
int objc, Tcl_Obj *CONST objv[])
|
||||
{
|
||||
Tcl_Obj *objp;
|
||||
char *result, *completion, *function;
|
||||
char *result, *completion, *description, *function;
|
||||
int i;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -3777,17 +3777,19 @@ weechat_tcl_api_hook_completion (ClientData clientData, Tcl_Interp *interp,
|
||||
TCL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (objc < 3)
|
||||
if (objc < 4)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGUMENTS("hook_completion");
|
||||
TCL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
completion = Tcl_GetStringFromObj (objv[1], &i);
|
||||
function = Tcl_GetStringFromObj (objv[2], &i);
|
||||
description = Tcl_GetStringFromObj (objv[2], &i);
|
||||
function = Tcl_GetStringFromObj (objv[3], &i);
|
||||
result = script_ptr2str (script_api_hook_completion (weechat_tcl_plugin,
|
||||
tcl_current_script,
|
||||
completion,
|
||||
description,
|
||||
&weechat_tcl_api_hook_completion_cb,
|
||||
function));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user