1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-26 12:56:37 +02:00

core: add completion "eval_variables", used in completion of /eval

This commit is contained in:
Sébastien Helleu
2023-09-07 11:38:26 +02:00
parent 89739421cf
commit 374262a8d7
3 changed files with 118 additions and 1 deletions
+1
View File
@@ -15,6 +15,7 @@ For a list of important changes that require manual actions, please look at rele
New features::
* core: add completion "eval_variables", used in completion of `/eval`
* core: add command `/sys` to show resource limits/usage and suspend WeeChat process, add key kbd:[Ctrl+z] to suspend WeeChat (issue #985)
* core: ignore key bindings with empty command
* core: add support of quotes in commands `/key bind` and `/key bindctxt`
+1 -1
View File
@@ -8414,7 +8414,7 @@ command_init ()
" /eval -n -c abcd !~ abc ==> 0\n"
" /eval -n -c abcd =* a*d ==> 1\n"
" /eval -n -c abcd =- bc ==> 1"),
"-n|-s|-c -n|-s|-c",
"-n|-s|-c|%(eval_variables)|%*",
&command_eval, NULL, NULL);
hook_command (
NULL, "filter",
+116
View File
@@ -2071,6 +2071,119 @@ completion_list_add_env_value_cb (const void *pointer, void *data,
return WEECHAT_RC_OK;
}
/*
* Adds a buffer local variable for /eval to completions list.
*/
void
completion_list_map_eval_buffer_local_variable_cb (void *data,
struct t_hashtable *hashtable,
const void *key, const void *value)
{
char *name;
int length;
/* make C compiler happy */
(void) hashtable;
(void) value;
length = strlen (key) + 3 + 1;
name = malloc (length);
if (name)
{
snprintf (name, length, "${%s}", (const char *)key);
gui_completion_list_add ((struct t_gui_completion *)data,
name, 0, WEECHAT_LIST_POS_SORT);
free (name);
}
}
/*
* Adds /eval variables to completion list.
*/
int
completion_list_add_eval_variables_cb (const void *pointer, void *data,
const char *completion_item,
struct t_gui_buffer *buffer,
struct t_gui_completion *completion)
{
char *eval_variables[] = {
"${\\xxx}",
"${base_decode:base,xxx}",
"${base_encode:base,xxx}",
"${calc:xxx}",
"${chars:range}",
"${color:xxx}",
"${cut:+max,suffix,string}",
"${cut:max,suffix,string}",
"${cutscr:+max,suffix,string}",
"${cutscr:max,suffix,string}",
"${date:format}",
"${date}",
"${define:name,value}",
"${env:XXX}",
"${esc:xxx}",
"${eval:xxx}",
"${eval_cond:xxx}",
"${file.section.option}",
"${hdata.var1.var2}",
"${hdata[list].var1.var2}",
"${hdata[ptr].var1.var2}",
"${hdata[ptr_name].var1.var2}",
"${hide:char,string}",
"${if:condition?value_if_true:value_if_false}",
"${info:name,arguments}",
"${length:xxx}",
"${lengthscr:xxx}",
"${lower:xxx}",
"${modifier:name,data,xxx}",
"${random:min,max}",
"${raw:xxx}",
"${re:+}",
"${re:N}",
"${repeat:count,string}",
"${rev:xxx}",
"${revscr:xxx}",
"${sec.data.xxx}",
"${split:count,separators,flags,xxx}",
"${split:number,separators,flags,xxx}",
"${split:random,separators,flags,xxx}",
"${split_shell:count,xxx}",
"${split_shell:number,xxx}",
"${split_shell:random,xxx}",
"${translate:xxx}",
"${upper:xxx}",
"${weechat_cache_dir}",
"${weechat_config_dir}",
"${weechat_data_dir}",
"${weechat_runtime_dir}",
"${window}",
"${window.buffer}",
"${window.buffer.xxx}",
NULL,
};
int i;
/* make C compiler happy */
(void) pointer;
(void) data;
(void) completion_item;
(void) buffer;
for (i = 0; eval_variables[i]; i++)
{
gui_completion_list_add (completion, eval_variables[i],
0, WEECHAT_LIST_POS_SORT);
}
hashtable_map (completion->buffer->local_variables,
&completion_list_map_eval_buffer_local_variable_cb,
completion);
return WEECHAT_RC_OK;
}
/*
* Adds hooks for completions done by WeeChat core.
*/
@@ -2215,4 +2328,7 @@ completion_init ()
hook_completion (NULL, "env_value",
N_("value of an environment variable"),
&completion_list_add_env_value_cb, NULL, NULL);
hook_completion (NULL, "eval_variables",
N_("variables that can be used in /eval command"),
&completion_list_add_eval_variables_cb, NULL, NULL);
}