summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-09-07 11:38:26 +0200
committerSébastien Helleu <flashcode@flashtux.org>2023-09-07 11:38:26 +0200
commit374262a8d71ed6b9302db4e2f527adb50352d815 (patch)
tree624ae49518a53a85d11810b4e0b3c405093ba1b7
parent89739421cf39d588c63c7b3da0a8204df4a0b62e (diff)
downloadweechat-374262a8d71ed6b9302db4e2f527adb50352d815.zip
core: add completion "eval_variables", used in completion of `/eval`
-rw-r--r--ChangeLog.adoc1
-rw-r--r--src/core/wee-command.c2
-rw-r--r--src/core/wee-completion.c116
3 files changed, 118 insertions, 1 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc
index a1193d944..e8f7fd018 100644
--- a/ChangeLog.adoc
+++ b/ChangeLog.adoc
@@ -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`
diff --git a/src/core/wee-command.c b/src/core/wee-command.c
index 7cbaa0bdb..d98b36541 100644
--- a/src/core/wee-command.c
+++ b/src/core/wee-command.c
@@ -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",
diff --git a/src/core/wee-completion.c b/src/core/wee-completion.c
index f82271d82..d7ee764e2 100644
--- a/src/core/wee-completion.c
+++ b/src/core/wee-completion.c
@@ -2072,6 +2072,119 @@ completion_list_add_env_value_cb (const void *pointer, void *data,
}
/*
+ * 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);
}