Skip to content

Commit

Permalink
script: add local key bindings during the buffer creation
Browse files Browse the repository at this point in the history
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_*".
  • Loading branch information
flashcode committed Aug 24, 2023
1 parent 6737859 commit 817d1ea
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions ChangeLog.adoc
Expand Up @@ -49,6 +49,7 @@ Bug fixes::
* irc: add missing "account-tag" in list of supported capabilities
* irc: add channel in "autojoin" server option only when the channel is actually joined (issue #1990)
* relay: synchronize nick modes with IRC client upon connection (issue #1984)
* script: add local key bindings during the buffer creation
* script: add parameters up/down/go in `/help script` and command completion
* script: fix cursor position after `/script list -i` or `/script list -il`
* script: fix buffer used by command `/script list -i|-il|-o|-ol`
Expand Down
17 changes: 13 additions & 4 deletions src/plugins/script/script-buffer.c
Expand Up @@ -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" },
Expand All @@ -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, "");
}
}
}
Expand Down Expand Up @@ -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 (
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/script/script-buffer.h
Expand Up @@ -46,7 +46,7 @@ extern int script_buffer_input_cb (const void *pointer, void *data,
extern int script_buffer_close_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer);
extern void script_buffer_set_callbacks ();
extern void script_buffer_set_keys ();
extern void script_buffer_set_keys (struct t_hashtable *hashtable);
extern void script_buffer_set_localvar_filter ();
extern void script_buffer_open ();

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/script/script-config.c
Expand Up @@ -279,7 +279,7 @@ script_config_change_use_keys_cb (const void *pointer, void *data,
(void) option;

if (script_buffer)
script_buffer_set_keys ();
script_buffer_set_keys (NULL);
}

/*
Expand Down

0 comments on commit 817d1ea

Please sign in to comment.