diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-hook.c | 49 | ||||
-rw-r--r-- | src/core/wee-hook.h | 2 | ||||
-rw-r--r-- | src/plugins/plugin-api.c | 3 |
3 files changed, 46 insertions, 8 deletions
diff --git a/src/core/wee-hook.c b/src/core/wee-hook.c index 67478bd6d..87942064d 100644 --- a/src/core/wee-hook.c +++ b/src/core/wee-hook.c @@ -2847,16 +2847,33 @@ unhook_all () */ int -hook_add_to_infolist_type (struct t_infolist *infolist, - int type) +hook_add_to_infolist_type (struct t_infolist *infolist, int type, + const char *arguments) { struct t_hook *ptr_hook; struct t_infolist_item *ptr_item; char value[64]; + int match; for (ptr_hook = weechat_hooks[type]; ptr_hook; ptr_hook = ptr_hook->next_hook) { + match = 1; + if (arguments && !ptr_hook->deleted) + { + switch (ptr_hook->type) + { + case HOOK_TYPE_COMMAND: + match = (strcmp (HOOK_COMMAND(ptr_hook, command), arguments) == 0); + break; + default: + break; + } + } + + if (!match) + continue; + ptr_item = infolist_new_item (infolist); if (!ptr_item) return 0; @@ -3190,27 +3207,47 @@ hook_add_to_infolist_type (struct t_infolist *infolist, /* * hook_add_to_infolist: add hooks in an infolist - * if type == NULL or is not found, all types are returned + * arguments can be a hook type with optional comma + + * name after * return 1 if ok, 0 if error */ int -hook_add_to_infolist (struct t_infolist *infolist, - const char *type) +hook_add_to_infolist (struct t_infolist *infolist, const char *arguments) { + const char *pos_arguments; + char *type; int i, type_int; if (!infolist) return 0; + type = NULL; + pos_arguments = NULL; + + if (arguments) + { + pos_arguments = strchr (arguments, ','); + if (pos_arguments) + { + type = string_strndup (arguments, pos_arguments - arguments); + pos_arguments++; + } + else + type = strdup (arguments); + } + type_int = (type) ? hook_search_type (type) : -1; for (i = 0; i < HOOK_NUM_TYPES; i++) { if ((type_int < 0) || (type_int == i)) - hook_add_to_infolist_type (infolist, i); + hook_add_to_infolist_type (infolist, i, pos_arguments); } + if (type) + free (type); + return 1; } diff --git a/src/core/wee-hook.h b/src/core/wee-hook.h index 1c2e357d9..a3ae429e2 100644 --- a/src/core/wee-hook.h +++ b/src/core/wee-hook.h @@ -498,7 +498,7 @@ extern void unhook (struct t_hook *hook); extern void unhook_all_plugin (struct t_weechat_plugin *plugin); extern void unhook_all (); extern int hook_add_to_infolist (struct t_infolist *infolist, - const char *type); + const char *arguments); extern void hook_print_log (); #endif /* __WEECHAT_HOOK_H */ diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c index 7c0b87057..853dafa2a 100644 --- a/src/plugins/plugin-api.c +++ b/src/plugins/plugin-api.c @@ -1004,7 +1004,8 @@ plugin_api_init () &plugin_api_infolist_get_internal, NULL); hook_infolist (NULL, "hook", N_("list of hooks"), NULL, - N_("hook type: command, timer, .. (optional)"), + N_("type,arguments (type is command/timer/.., arguments to " + "get only some hooks, both are optional)"), &plugin_api_infolist_get_internal, NULL); hook_infolist (NULL, "hotlist", N_("list of buffers in hotlist"), NULL, |