From 79f7c1cf83e166b42bb803df3b237ddde0fcec8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Thu, 2 Mar 2023 21:08:51 +0100 Subject: fset: hook command /key When command /key is called without arguments, and if fset plugin is loaded, fset displays all key options (filter: `weechat.key*`). --- src/plugins/fset/fset-command.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'src/plugins/fset') diff --git a/src/plugins/fset/fset-command.c b/src/plugins/fset/fset-command.c index 5cfb1b514..7ab4f3a5d 100644 --- a/src/plugins/fset/fset-command.c +++ b/src/plugins/fset/fset-command.c @@ -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)) @@ -575,6 +574,44 @@ end: 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. */ @@ -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); } -- cgit v1.2.3