mirror of
https://github.com/weechat/weechat.git
synced 2026-06-25 20:36:38 +02:00
Add new option weechat.look.command_chars, add functions string_is_command_char and string_input_for_buffer in plugin and script API
This commit is contained in:
@@ -402,6 +402,81 @@ weechat_lua_api_string_remove_color (lua_State *L)
|
||||
LUA_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_string_is_command_char: check if first char of string is a
|
||||
* command char
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_api_string_is_command_char (lua_State *L)
|
||||
{
|
||||
const char *string;
|
||||
int n, value;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, "string_is_command_char");
|
||||
LUA_RETURN_INT(0);
|
||||
}
|
||||
|
||||
string = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n < 1)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "string_is_command_char");
|
||||
LUA_RETURN_INT(0);
|
||||
}
|
||||
|
||||
string = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
value = weechat_string_is_command_char (string);
|
||||
|
||||
LUA_RETURN_INT(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_string_input_for_buffer: return string with input text
|
||||
* for buffer or empty string if
|
||||
* it's a command
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_lua_api_string_input_for_buffer (lua_State *L)
|
||||
{
|
||||
const char *string, *result;
|
||||
int n;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) L;
|
||||
|
||||
if (!lua_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(LUA_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
string = NULL;
|
||||
|
||||
n = lua_gettop (lua_current_interpreter);
|
||||
|
||||
if (n < 1)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(LUA_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
|
||||
LUA_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
string = lua_tostring (lua_current_interpreter, -1);
|
||||
|
||||
result = weechat_string_input_for_buffer (string);
|
||||
|
||||
LUA_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_lua_api_mkdir_home: create a directory in WeeChat home
|
||||
*/
|
||||
@@ -7232,6 +7307,8 @@ const struct luaL_reg weechat_lua_api_funcs[] = {
|
||||
{ "gettext", &weechat_lua_api_gettext },
|
||||
{ "ngettext", &weechat_lua_api_ngettext },
|
||||
{ "string_remove_color", &weechat_lua_api_string_remove_color },
|
||||
{ "string_is_command_char", &weechat_lua_api_string_is_command_char },
|
||||
{ "string_input_for_buffer", &weechat_lua_api_string_input_for_buffer },
|
||||
{ "mkdir_home", &weechat_lua_api_mkdir_home },
|
||||
{ "mkdir", &weechat_lua_api_mkdir },
|
||||
{ "mkdir_parents", &weechat_lua_api_mkdir_parents },
|
||||
|
||||
@@ -345,6 +345,66 @@ XS (XS_weechat_api_string_remove_color)
|
||||
PERL_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::string_is_command_char: check if first char of string is a command
|
||||
* char
|
||||
*/
|
||||
|
||||
XS (XS_weechat_api_string_is_command_char)
|
||||
{
|
||||
int value;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "string_is_command_char");
|
||||
PERL_RETURN_INT(0);
|
||||
}
|
||||
|
||||
if (items < 1)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "string_is_command_char");
|
||||
PERL_RETURN_INT(0);
|
||||
}
|
||||
|
||||
value = weechat_string_is_command_char (SvPV (ST (0), PL_na)); /* string */
|
||||
|
||||
PERL_RETURN_INT(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::string_input_for_buffer: return string with input text for buffer
|
||||
* or empty string if it's a command
|
||||
*/
|
||||
|
||||
XS (XS_weechat_api_string_input_for_buffer)
|
||||
{
|
||||
const char *result;
|
||||
dXSARGS;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) cv;
|
||||
|
||||
if (!perl_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(PERL_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (items < 1)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PERL_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
|
||||
PERL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
result = weechat_string_input_for_buffer (SvPV (ST (0), PL_na)); /* string */
|
||||
|
||||
PERL_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat::mkdir_home: create a directory in WeeChat home
|
||||
*/
|
||||
@@ -5790,6 +5850,8 @@ weechat_perl_api_init (pTHX)
|
||||
newXS ("weechat::gettext", XS_weechat_api_gettext, "weechat");
|
||||
newXS ("weechat::ngettext", XS_weechat_api_ngettext, "weechat");
|
||||
newXS ("weechat::string_remove_color", XS_weechat_api_string_remove_color, "weechat");
|
||||
newXS ("weechat::string_is_command_char", XS_weechat_api_string_is_command_char, "weechat");
|
||||
newXS ("weechat::string_input_for_buffer", XS_weechat_api_string_input_for_buffer, "weechat");
|
||||
newXS ("weechat::mkdir_home", XS_weechat_api_mkdir_home, "weechat");
|
||||
newXS ("weechat::mkdir", XS_weechat_api_mkdir, "weechat");
|
||||
newXS ("weechat::mkdir_parents", XS_weechat_api_mkdir_parents, "weechat");
|
||||
|
||||
@@ -350,6 +350,73 @@ weechat_python_api_string_remove_color (PyObject *self, PyObject *args)
|
||||
PYTHON_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_string_is_command_char: check if first char of string is
|
||||
* a command char
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_api_string_is_command_char (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *string;
|
||||
int value;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "string_is_command_char");
|
||||
PYTHON_RETURN_INT(0);
|
||||
}
|
||||
|
||||
string = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s", &string))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "string_is_command_char");
|
||||
PYTHON_RETURN_INT(0);
|
||||
}
|
||||
|
||||
value = weechat_string_is_command_char (string);
|
||||
|
||||
PYTHON_RETURN_INT(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_string_input_for_buffer: return string with input text
|
||||
* for buffer or empty string if
|
||||
* it's a command
|
||||
*/
|
||||
|
||||
static PyObject *
|
||||
weechat_python_api_string_input_for_buffer (PyObject *self, PyObject *args)
|
||||
{
|
||||
char *string;
|
||||
const char *result;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) self;
|
||||
|
||||
if (!python_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(PYTHON_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
string = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple (args, "s", &string))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(PYTHON_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
|
||||
PYTHON_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
result = weechat_string_input_for_buffer (string);
|
||||
|
||||
PYTHON_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_python_api_mkdir_home: create a directory in WeeChat home
|
||||
*/
|
||||
@@ -6081,6 +6148,8 @@ PyMethodDef weechat_python_funcs[] =
|
||||
{ "gettext", &weechat_python_api_gettext, METH_VARARGS, "" },
|
||||
{ "ngettext", &weechat_python_api_ngettext, METH_VARARGS, "" },
|
||||
{ "string_remove_color", &weechat_python_api_string_remove_color, METH_VARARGS, "" },
|
||||
{ "string_is_command_char", &weechat_python_api_string_is_command_char, METH_VARARGS, "" },
|
||||
{ "string_input_for_buffer", &weechat_python_api_string_input_for_buffer, METH_VARARGS, "" },
|
||||
{ "mkdir_home", &weechat_python_api_mkdir_home, METH_VARARGS, "" },
|
||||
{ "mkdir", &weechat_python_api_mkdir, METH_VARARGS, "" },
|
||||
{ "mkdir_parents", &weechat_python_api_mkdir_parents, METH_VARARGS, "" },
|
||||
|
||||
@@ -407,6 +407,81 @@ weechat_ruby_api_string_remove_color (VALUE class, VALUE string,
|
||||
RUBY_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_string_is_command_char: check if first char of string is a
|
||||
* command char
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_string_is_command_char (VALUE class, VALUE string)
|
||||
{
|
||||
char *c_string;
|
||||
int value;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "string_is_command_char");
|
||||
RUBY_RETURN_INT(0);
|
||||
}
|
||||
|
||||
c_string = NULL;
|
||||
|
||||
if (NIL_P (string))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "string_is_command_char");
|
||||
RUBY_RETURN_INT(0);
|
||||
}
|
||||
|
||||
Check_Type (string, T_STRING);
|
||||
|
||||
c_string = STR2CSTR (string);
|
||||
|
||||
value = weechat_string_is_command_char (c_string);
|
||||
|
||||
RUBY_RETURN_INT(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_string_input_for_buffer: return string with input text
|
||||
* for buffer or empty string if
|
||||
* it's a command
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
weechat_ruby_api_string_input_for_buffer (VALUE class, VALUE string)
|
||||
{
|
||||
char *c_string;
|
||||
const char *result;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) class;
|
||||
|
||||
if (!ruby_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(RUBY_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
c_string = NULL;
|
||||
|
||||
if (NIL_P (string))
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(RUBY_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
|
||||
RUBY_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
Check_Type (string, T_STRING);
|
||||
|
||||
c_string = STR2CSTR (string);
|
||||
|
||||
result = weechat_string_input_for_buffer (c_string);
|
||||
|
||||
RUBY_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_ruby_api_mkdir_home: create a directory in WeeChat home
|
||||
*/
|
||||
@@ -7023,6 +7098,8 @@ weechat_ruby_api_init (VALUE ruby_mWeechat)
|
||||
rb_define_module_function (ruby_mWeechat, "gettext", &weechat_ruby_api_gettext, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "ngettext", &weechat_ruby_api_ngettext, 3);
|
||||
rb_define_module_function (ruby_mWeechat, "string_remove_color", &weechat_ruby_api_string_remove_color, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "string_is_command_char", &weechat_ruby_api_string_is_command_char, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "string_input_for_buffer", &weechat_ruby_api_string_input_for_buffer, 1);
|
||||
rb_define_module_function (ruby_mWeechat, "mkdir_home", &weechat_ruby_api_mkdir_home, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "mkdir", &weechat_ruby_api_mkdir, 2);
|
||||
rb_define_module_function (ruby_mWeechat, "mkdir_parents", &weechat_ruby_api_mkdir_parents, 2);
|
||||
|
||||
@@ -446,7 +446,7 @@ weechat_tcl_api_string_remove_color (ClientData clientData, Tcl_Interp *interp,
|
||||
{
|
||||
Tcl_Obj* objp;
|
||||
char *result, *replacement, *string;
|
||||
int i;
|
||||
int i;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) clientData;
|
||||
@@ -471,6 +471,72 @@ weechat_tcl_api_string_remove_color (ClientData clientData, Tcl_Interp *interp,
|
||||
TCL_RETURN_STRING_FREE(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_tcl_api_string_is_command_char: check if first char of string is a
|
||||
* command char
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_tcl_api_string_is_command_char (ClientData clientData, Tcl_Interp *interp,
|
||||
int objc, Tcl_Obj *CONST objv[])
|
||||
{
|
||||
Tcl_Obj* objp;
|
||||
int result, i;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) clientData;
|
||||
|
||||
if (!tcl_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "string_is_command_char");
|
||||
TCL_RETURN_INT(0);
|
||||
}
|
||||
|
||||
if (objc < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "string_is_command_char");
|
||||
TCL_RETURN_INT(0);
|
||||
}
|
||||
|
||||
result = weechat_string_is_command_char (Tcl_GetStringFromObj (objv[1], &i)); /* string */
|
||||
|
||||
TCL_RETURN_INT(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_tcl_api_string_input_for_buffer: return string with input text
|
||||
* for buffer or empty string if
|
||||
* it's a command
|
||||
*/
|
||||
|
||||
static int
|
||||
weechat_tcl_api_string_input_for_buffer (ClientData clientData, Tcl_Interp *interp,
|
||||
int objc, Tcl_Obj *CONST objv[])
|
||||
{
|
||||
Tcl_Obj* objp;
|
||||
const char *result;
|
||||
int i;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) clientData;
|
||||
|
||||
if (!tcl_current_script)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_NOT_INIT(TCL_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
|
||||
TCL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
if (objc < 2)
|
||||
{
|
||||
WEECHAT_SCRIPT_MSG_WRONG_ARGS(TCL_CURRENT_SCRIPT_NAME, "string_input_for_buffer");
|
||||
TCL_RETURN_EMPTY;
|
||||
}
|
||||
|
||||
result = weechat_string_input_for_buffer (Tcl_GetStringFromObj (objv[1], &i));
|
||||
|
||||
TCL_RETURN_STRING(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* weechat_tcl_api_mkdir_home: create a directory in WeeChat home
|
||||
*/
|
||||
@@ -6552,6 +6618,10 @@ void weechat_tcl_api_init (Tcl_Interp *interp)
|
||||
weechat_tcl_api_ngettext, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::string_remove_color",
|
||||
weechat_tcl_api_string_remove_color, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::string_is_command_char",
|
||||
weechat_tcl_api_string_is_command_char, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::string_input_for_buffer",
|
||||
weechat_tcl_api_string_input_for_buffer, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::mkdir_home",
|
||||
weechat_tcl_api_mkdir_home, (ClientData)NULL, (Tcl_CmdDeleteProc*)NULL);
|
||||
Tcl_CreateObjCommand (interp, "weechat::mkdir",
|
||||
|
||||
Reference in New Issue
Block a user