Skip to content

Commit

Permalink
fset: hook command /key
Browse files Browse the repository at this point in the history
When command /key is called without arguments, and if fset plugin is loaded,
fset displays all key options (filter: `weechat.key*`).
  • Loading branch information
flashcode committed Mar 16, 2023
1 parent ccc649d commit 79f7c1c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/wee-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -8356,7 +8356,7 @@ command_init ()
hook_command (
NULL, "key",
N_("bind/unbind keys"),
N_("list|listdefault|listdiff [<context>]"
N_("[list|listdefault|listdiff] [<context>]"
" || bind <key> [<command> [<args>]]"
" || bindctxt <context> <key> [<command> [<args>]]"
" || unbind <key>"
Expand Down
40 changes: 39 additions & 1 deletion src/plugins/fset/fset-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ fset_command_run_set_cb (const void *pointer, void *data,
/* make C compiler happy */
(void) pointer;
(void) data;
(void) buffer;

/* ignore /set command if issued on fset buffer */
if (fset_buffer && (buffer == fset_buffer))
Expand Down Expand Up @@ -575,6 +574,44 @@ fset_command_run_set_cb (const void *pointer, void *data,
return rc;
}

/*
* Hooks execution of command "/key".
*/

int
fset_command_run_key_cb (const void *pointer, void *data,
struct t_gui_buffer *buffer, const char *command)
{
const char *ptr_args;

/* make C compiler happy */
(void) pointer;
(void) data;
(void) buffer;

if (strncmp (command, "/key", 4) != 0)
return WEECHAT_RC_OK;

ptr_args = strchr (command, ' ');
while (ptr_args && (ptr_args[0] == ' '))
{
ptr_args++;
}

if (!ptr_args || !ptr_args[0])
{
fset_option_filter_options ("weechat.key*");
if (!fset_buffer)
fset_buffer_open ();
fset_buffer_set_localvar_filter ();
fset_buffer_refresh (1);
weechat_buffer_set (fset_buffer, "display", "1");
return WEECHAT_RC_OK_EAT;
}

return WEECHAT_RC_OK;
}

/*
* Hooks fset commands.
*/
Expand Down Expand Up @@ -807,4 +844,5 @@ fset_command_init ()
" || *|c:|f:|s:|d|d:|d=|d==|=|==|%(fset_options)",
&fset_command_fset, NULL, NULL);
weechat_hook_command_run ("/set", &fset_command_run_set_cb, NULL, NULL);
weechat_hook_command_run ("/key", &fset_command_run_key_cb, NULL, NULL);
}

0 comments on commit 79f7c1c

Please sign in to comment.