mirror of
https://github.com/weechat/weechat.git
synced 2026-07-02 07:46:38 +02:00
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.
This commit is contained in:
+47
-6
@@ -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 [<number1> [<number2> [<start>]]]"
|
||||
" || close [<n1>[-<n2>]|<name>...]"
|
||||
" || notify [<level>]"
|
||||
" || localvar [<number>|<name>]"
|
||||
" || listvar [<number>|<name>]"
|
||||
" || setvar <name> [<value>]"
|
||||
" || delvar <name>"
|
||||
" || set <property> [<value>]"
|
||||
" || get <property>"
|
||||
" || <number>|-|+|<name>"),
|
||||
@@ -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)|"
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
/*
|
||||
* wee-completion.c - completion for WeeChat commands
|
||||
*
|
||||
@@ -201,6 +200,97 @@ completion_list_add_buffers_plugins_names_cb (const void *pointer, void *data,
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds a buffer local variable to completions list.
|
||||
*/
|
||||
|
||||
void
|
||||
completion_list_map_buffer_local_variable_cb (void *data,
|
||||
struct t_hashtable *hashtable,
|
||||
const void *key, const void *value)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) hashtable;
|
||||
(void) value;
|
||||
|
||||
gui_completion_list_add ((struct t_gui_completion *)data,
|
||||
(const char *)key,
|
||||
0, WEECHAT_LIST_POS_SORT);
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds buffer local variables to completion list.
|
||||
*/
|
||||
|
||||
int
|
||||
completion_list_add_buffer_local_variables_cb (const void *pointer, void *data,
|
||||
const char *completion_item,
|
||||
struct t_gui_buffer *buffer,
|
||||
struct t_gui_completion *completion)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) completion_item;
|
||||
(void) buffer;
|
||||
|
||||
hashtable_map (completion->buffer->local_variables,
|
||||
&completion_list_map_buffer_local_variable_cb,
|
||||
completion);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds buffer local variable value to completion list.
|
||||
*/
|
||||
|
||||
int
|
||||
completion_list_add_buffer_local_variable_value_cb (const void *pointer, void *data,
|
||||
const char *completion_item,
|
||||
struct t_gui_buffer *buffer,
|
||||
struct t_gui_completion *completion)
|
||||
{
|
||||
char **argv;
|
||||
int argc, arg_index;
|
||||
const char *ptr_value;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
(void) data;
|
||||
(void) completion_item;
|
||||
(void) buffer;
|
||||
|
||||
if (!completion->args)
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
argv = string_split (completion->args, " ", NULL,
|
||||
WEECHAT_STRING_SPLIT_STRIP_LEFT
|
||||
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
|
||||
0, &argc);
|
||||
if (!argv)
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
if (argc > 0)
|
||||
{
|
||||
arg_index = completion->base_command_arg_index - 2;
|
||||
if ((arg_index < 1) || (arg_index > argc - 1))
|
||||
arg_index = argc - 1;
|
||||
ptr_value = hashtable_get (completion->buffer->local_variables,
|
||||
argv[arg_index]);
|
||||
if (ptr_value)
|
||||
{
|
||||
gui_completion_list_add (completion,
|
||||
ptr_value,
|
||||
0, WEECHAT_LIST_POS_SORT);
|
||||
}
|
||||
}
|
||||
string_free_split (argv);
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds buffer properties (that can be set) to completion list.
|
||||
*/
|
||||
@@ -1712,6 +1802,12 @@ completion_init ()
|
||||
hook_completion (NULL, "buffers_plugins_names", /* formerly "%B" */
|
||||
N_("names of buffers (including plugins names)"),
|
||||
&completion_list_add_buffers_plugins_names_cb, NULL, NULL);
|
||||
hook_completion (NULL, "buffer_local_variables",
|
||||
N_("buffer local variables"),
|
||||
&completion_list_add_buffer_local_variables_cb, NULL, NULL);
|
||||
hook_completion (NULL, "buffer_local_variable_value",
|
||||
N_("value of a buffer local variable"),
|
||||
&completion_list_add_buffer_local_variable_value_cb, NULL, NULL);
|
||||
hook_completion (NULL, "buffer_properties_set",
|
||||
N_("properties that can be set on a buffer"),
|
||||
&completion_list_add_buffer_properties_set_cb, NULL, NULL);
|
||||
|
||||
@@ -255,6 +255,11 @@ extern int gui_buffer_search_notify (const char *notify);
|
||||
extern const char *gui_buffer_get_plugin_name (struct t_gui_buffer *buffer);
|
||||
extern const char *gui_buffer_get_short_name (struct t_gui_buffer *buffer);
|
||||
extern void gui_buffer_build_full_name (struct t_gui_buffer *buffer);
|
||||
extern void gui_buffer_local_var_add (struct t_gui_buffer *buffer,
|
||||
const char *name,
|
||||
const char *value);
|
||||
extern void gui_buffer_local_var_remove (struct t_gui_buffer *buffer,
|
||||
const char *name);
|
||||
extern void gui_buffer_notify_set_all ();
|
||||
extern void gui_buffer_input_buffer_init (struct t_gui_buffer *buffer);
|
||||
extern int gui_buffer_is_reserved_name (const char *name);
|
||||
|
||||
@@ -274,7 +274,7 @@ alias_command_init ()
|
||||
" $*: all arguments\n"
|
||||
" $~: last argument\n"
|
||||
" $var: where \"var\" is a local variable of buffer (see "
|
||||
"/buffer localvar)\n"
|
||||
"/buffer listvar)\n"
|
||||
" examples: $nick, $channel, $server, $plugin, $name\n"
|
||||
"\n"
|
||||
"Examples:\n"
|
||||
|
||||
Reference in New Issue
Block a user