summaryrefslogtreecommitdiff
path: root/src/plugins/script/script-buffer.c
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2023-08-24 19:01:20 +0200
committerSébastien Helleu <flashcode@flashtux.org>2023-08-24 19:01:20 +0200
commit817d1eaf8e0be700bf9b61dcbaf9db7ab507d3af (patch)
tree17460d9351bae87dcd188da9f4ded9ed8633adcd /src/plugins/script/script-buffer.c
parent6737859330cc582649edfd07b3d6664220ce7a96 (diff)
downloadweechat-817d1eaf8e0be700bf9b61dcbaf9db7ab507d3af.zip
script: add local key bindings during the buffer creation
This allows the user to bind or unbind keys by setting options "weechat.buffer.script.scripts.key_bind_*" and "weechat.buffer.script.scripts.key_unbind_*".
Diffstat (limited to 'src/plugins/script/script-buffer.c')
-rw-r--r--src/plugins/script/script-buffer.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/plugins/script/script-buffer.c b/src/plugins/script/script-buffer.c
index f05ee1e3a..08f45a02f 100644
--- a/src/plugins/script/script-buffer.c
+++ b/src/plugins/script/script-buffer.c
@@ -1085,10 +1085,13 @@ script_buffer_set_callbacks ()
/*
* Sets keys on script buffer.
+ *
+ * If hashtable is not NULL, it is used to set keys, otherwise keys are directly
+ * set in the script buffer.
*/
void
-script_buffer_set_keys ()
+script_buffer_set_keys (struct t_hashtable *hashtable)
{
char *keys[][2] = {
{ "meta-A", "toggleautoload" },
@@ -1113,12 +1116,18 @@ script_buffer_set_keys ()
{
snprintf (str_key, sizeof (str_key), "key_bind_%s", keys[i][0]);
snprintf (str_command, sizeof (str_command), "/script %s", keys[i][1]);
- weechat_buffer_set (script_buffer, str_key, str_command);
+ if (hashtable)
+ weechat_hashtable_set (hashtable, str_key, str_command);
+ else
+ weechat_buffer_set (script_buffer, str_key, str_command);
}
else
{
snprintf (str_key, sizeof (str_key), "key_unbind_%s", keys[i][0]);
- weechat_buffer_set (script_buffer, str_key, "");
+ if (hashtable)
+ weechat_hashtable_set (hashtable, str_key, "");
+ else
+ weechat_buffer_set (script_buffer, str_key, "");
}
}
}
@@ -1159,6 +1168,7 @@ script_buffer_open ()
weechat_hashtable_set (buffer_props, "type", "free");
weechat_hashtable_set (buffer_props, "title", _("Scripts"));
weechat_hashtable_set (buffer_props, "localvar_set_type", "script");
+ script_buffer_set_keys (buffer_props);
}
script_buffer = weechat_buffer_new_props (
@@ -1173,7 +1183,6 @@ script_buffer_open ()
if (!script_buffer)
return;
- script_buffer_set_keys ();
script_buffer_set_localvar_filter ();
script_buffer_selected_line = 0;