mirror of
https://github.com/weechat/weechat.git
synced 2026-06-28 22:06:38 +02:00
api: add support of infos with format ${info:name,arguments} in function string_eval_expression and command /eval
This commit is contained in:
@@ -6410,11 +6410,14 @@ command_init ()
|
||||
" 50 > 100 ==> 0\n"
|
||||
" \"50\" > \"100\" ==> 1\n\n"
|
||||
"Some variables are replaced in expression, using the "
|
||||
"format ${variable}, variable can be, by order of priority :\n"
|
||||
" 1. a color (format: color:xxx)\n"
|
||||
" 2. an option (format: file.section.option)\n"
|
||||
" 3. a local variable in buffer\n"
|
||||
" 4. a hdata name/variable (the value is automatically "
|
||||
"format ${variable}, variable can be, by order of "
|
||||
"priority :\n"
|
||||
" 1. a color (format: \"color:xxx\")\n"
|
||||
" 2. an info (format: \"info:name,arguments\", arguments "
|
||||
"are optional)\n"
|
||||
" 3. an option (format: \"file.section.option\")\n"
|
||||
" 4. a local variable in buffer\n"
|
||||
" 5. a hdata name/variable (the value is automatically "
|
||||
"converted to string), by default \"window\" and \"buffer\" "
|
||||
"point to current window/buffer.\n"
|
||||
"Format for hdata can be one of following:\n"
|
||||
@@ -6430,6 +6433,7 @@ command_init ()
|
||||
"For name of hdata and variables, please look at \"Plugin "
|
||||
"API reference\", function \"weechat_hdata_get\".\n\n"
|
||||
"Examples:\n"
|
||||
" /eval -n ${info:version} ==> 0.4.3\n"
|
||||
" /eval -n ${weechat.look.scroll_amount} ==> 3\n"
|
||||
" /eval -n ${window} ==> 0x2549aa0\n"
|
||||
" /eval -n ${window.buffer} ==> 0x2549320\n"
|
||||
|
||||
+25
-5
@@ -235,8 +235,8 @@ eval_replace_vars_cb (void *data, const char *text)
|
||||
struct t_config_option *ptr_option;
|
||||
struct t_gui_buffer *ptr_buffer;
|
||||
char str_value[64], *value, *pos, *pos1, *pos2, *hdata_name, *list_name;
|
||||
char *tmp;
|
||||
const char *ptr_value;
|
||||
char *tmp, *info_name;
|
||||
const char *ptr_value, *ptr_arguments;
|
||||
struct t_hdata *hdata;
|
||||
void *pointer;
|
||||
|
||||
@@ -258,7 +258,27 @@ eval_replace_vars_cb (void *data, const char *text)
|
||||
return strdup ((ptr_value) ? ptr_value : "");
|
||||
}
|
||||
|
||||
/* 3. look for name of option: if found, return this value */
|
||||
/* 3. look for an info */
|
||||
if (strncmp (text, "info:", 5) == 0)
|
||||
{
|
||||
ptr_value = NULL;
|
||||
ptr_arguments = strchr (text + 5, ',');
|
||||
if (ptr_arguments)
|
||||
{
|
||||
info_name = string_strndup (text + 5, ptr_arguments - text - 5);
|
||||
ptr_arguments++;
|
||||
}
|
||||
else
|
||||
info_name = strdup (text + 5);
|
||||
if (info_name)
|
||||
{
|
||||
ptr_value = hook_info_get (NULL, info_name, ptr_arguments);
|
||||
free (info_name);
|
||||
}
|
||||
return strdup ((ptr_value) ? ptr_value : "");
|
||||
}
|
||||
|
||||
/* 4. look for name of option: if found, return this value */
|
||||
if (strncmp (text, "sec.data.", 9) == 0)
|
||||
{
|
||||
ptr_value = hashtable_get (secure_hashtable_data, text + 9);
|
||||
@@ -289,7 +309,7 @@ eval_replace_vars_cb (void *data, const char *text)
|
||||
}
|
||||
}
|
||||
|
||||
/* 4. look for local variable in buffer */
|
||||
/* 5. look for local variable in buffer */
|
||||
ptr_buffer = hashtable_get (pointers, "buffer");
|
||||
if (ptr_buffer)
|
||||
{
|
||||
@@ -298,7 +318,7 @@ eval_replace_vars_cb (void *data, const char *text)
|
||||
return strdup (ptr_value);
|
||||
}
|
||||
|
||||
/* 5. look for hdata */
|
||||
/* 6. look for hdata */
|
||||
value = NULL;
|
||||
hdata_name = NULL;
|
||||
list_name = NULL;
|
||||
|
||||
Reference in New Issue
Block a user