From 7e2396ade81d6778e87ef50698efce5adfb4032e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 19 Dec 2020 17:07:52 +0100 Subject: core: add options "setvar" and "delvar" in command /buffer, rename option "localvar" to "listvar" The option "localvar" (introduced long time ago, in WeeChat 0.3.0) is still recognized by WeeChat, to stay compatible with any extension/script calling it (or referencing it in the documentation). It is deprecated and will be removed in a future release. --- src/core/wee-command.c | 53 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) (limited to 'src/core/wee-command.c') diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 3798979da..0d9648990 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -1136,8 +1136,15 @@ COMMAND_CALLBACK(buffer) return WEECHAT_RC_OK; } - /* display local variables on buffer */ - if (string_strcasecmp (argv[1], "localvar") == 0) + /* + * display buffer local variables + * + * (note: option "localvar" has been replaced by "listvar" in WeeChat 3.1 + * but is still accepted for compatibility with WeeChat ≤ 3.0; + * it is now deprecated and will be removed in a future version) + */ + if ((string_strcasecmp (argv[1], "listvar") == 0) + || (string_strcasecmp (argv[1], "localvar") == 0)) { if (argc > 2) ptr_buffer = gui_buffer_search_by_number_or_name (argv[2]); @@ -1168,6 +1175,34 @@ COMMAND_CALLBACK(buffer) return WEECHAT_RC_OK; } + /* set a local variable in buffer */ + if (string_strcasecmp (argv[1], "setvar") == 0) + { + COMMAND_MIN_ARGS(3, "setvar"); + if (argc == 3) + { + gui_buffer_local_var_add (buffer, argv[2], ""); + } + else + { + value = string_remove_quotes (argv_eol[3], "'\""); + gui_buffer_local_var_add (buffer, + argv[2], + (value) ? value : argv_eol[3]); + if (value) + free (value); + } + return WEECHAT_RC_OK; + } + + /* delete a local variable from a buffer */ + if (string_strcasecmp (argv[1], "delvar") == 0) + { + COMMAND_MIN_ARGS(3, "delvar"); + gui_buffer_local_var_remove (buffer, argv[2]); + return WEECHAT_RC_OK; + } + /* set a property on buffer */ if (string_strcasecmp (argv[1], "set") == 0) { @@ -7178,7 +7213,9 @@ command_init () " || renumber [ [ []]]" " || close [[-]|...]" " || notify []" - " || localvar [|]" + " || listvar [|]" + " || setvar []" + " || delvar " " || set []" " || get " " || |-|+|"), @@ -7209,8 +7246,10 @@ command_init () " message: for messages from users + highlights\n" " all: all messages\n" " reset: reset to default value (all)\n" - "localvar: display local variables for the buffer\n" - " set: set a property for current buffer\n" + " listvar: display local variables in a buffer\n" + " setvar: set a local variable in the current buffer\n" + " delvar: delete a local variable from the current buffer\n" + " set: set a property in the current buffer\n" " get: display a property of current buffer\n" " number: jump to buffer by number, possible prefix:\n" " '+': relative jump, add number to current\n" @@ -7265,7 +7304,9 @@ command_init () " || close %(buffers_plugins_names)|%*" " || list" " || notify reset|none|highlight|message|all" - " || localvar %(buffers_numbers)|%(buffers_plugins_names)" + " || listvar %(buffers_numbers)|%(buffers_plugins_names)" + " || setvar %(buffer_local_variables) %(buffer_local_variable_value)" + " || delvar %(buffer_local_variables)" " || set %(buffer_properties_set)" " || get %(buffer_properties_get)" " || %(buffers_plugins_names)|%(buffers_names)|%(irc_channels)|" -- cgit v1.2.3