From 817d1eaf8e0be700bf9b61dcbaf9db7ab507d3af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Thu, 24 Aug 2023 19:01:20 +0200 Subject: 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_*". --- src/plugins/script/script-buffer.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/plugins/script/script-buffer.c') 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; -- cgit v1.2.3