1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-29 22:36:38 +02:00

Added completion hook, to let plugins add custom completions for commands

This commit is contained in:
Sebastien Helleu
2007-12-07 15:01:37 +01:00
parent 495e6bd5df
commit 72a694ed4c
9 changed files with 230 additions and 23 deletions
+28 -1
View File
@@ -43,6 +43,7 @@ struct t_alias *last_alias = NULL;
struct t_hook *alias_command = NULL;
struct t_hook *unalias_command = NULL;
struct t_hook *config_reload = NULL;
struct t_hook *completion = NULL;
/*
@@ -690,6 +691,28 @@ unalias_command_cb (void *data, void *buffer, int argc, char **argv,
return 0;
}
/*
* alias_completion_cb: callback for completion
*/
int
alias_completion_cb (void *data, char *completion, void *list)
{
struct t_alias *ptr_alias;
/* make C compiler happy */
(void) data;
(void) completion;
for (ptr_alias = alias_list; ptr_alias;
ptr_alias = ptr_alias->next_alias)
{
weechat_list_add (list, ptr_alias->name, "sort");
}
return PLUGIN_RC_SUCCESS;
}
/*
* weechat_plugin_init: initialize alias plugin
*/
@@ -734,12 +757,15 @@ weechat_plugin_init (struct t_weechat_plugin *plugin)
N_("alias_name"),
N_("alias_name: name of alias to "
"remove"),
"%h",
"%(alias)",
unalias_command_cb, NULL);
config_reload = weechat_hook_event ("config_reload",
alias_config_reload_event_cb, NULL);
completion = weechat_hook_completion ("alias",
alias_completion_cb, NULL);
return PLUGIN_RC_SUCCESS;
}
@@ -756,6 +782,7 @@ weechat_plugin_end ()
weechat_unhook (alias_command);
weechat_unhook (unalias_command);
weechat_unhook (config_reload);
weechat_unhook (completion);
return PLUGIN_RC_SUCCESS;
}
+15
View File
@@ -1185,6 +1185,21 @@ plugin_api_hook_config (struct t_weechat_plugin *plugin, char *config_type,
return NULL;
}
/*
* plugin_api_hook_completion: hook a completion
*/
struct t_hook *
plugin_api_hook_completion (struct t_weechat_plugin *plugin, char *completion,
int (*callback)(void *, char *, void *),
void *data)
{
if (plugin && callback)
return hook_completion (plugin, completion, callback, data);
return NULL;
}
/*
* plugin_api_unhook: unhook something
*/
+4
View File
@@ -146,6 +146,10 @@ extern struct t_hook *plugin_api_hook_config (struct t_weechat_plugin *,
char *, char *,
int (*)(void *, char *, char *, char *),
void *);
extern struct t_hook *plugin_api_hook_completion (struct t_weechat_plugin *,
char *,
int (*)(void *, char *, void *),
void *);
extern void plugin_api_unhook (struct t_weechat_plugin *, void *);
extern void plugin_api_unhook_all (struct t_weechat_plugin *);
+1
View File
@@ -289,6 +289,7 @@ plugin_load (char *filename)
new_plugin->hook_print = &plugin_api_hook_print;
new_plugin->hook_event = &plugin_api_hook_event;
new_plugin->hook_config = &plugin_api_hook_config;
new_plugin->hook_completion = &plugin_api_hook_completion;
new_plugin->unhook = &plugin_api_unhook;
new_plugin->unhook_all = &plugin_api_unhook_all;
+6
View File
@@ -155,6 +155,9 @@ struct t_weechat_plugin
struct t_hook *(*hook_config) (struct t_weechat_plugin *, char *, char *,
int (*)(void *, char *, char *, char *),
void *);
struct t_hook *(*hook_completion) (struct t_weechat_plugin *, char *,
int (*)(void *, char *, void *),
void *);
void (*unhook) (struct t_weechat_plugin *, void *);
void (*unhook_all) (struct t_weechat_plugin *);
@@ -364,6 +367,9 @@ struct t_weechat_plugin
#define weechat_hook_config(__type, __option, __callback, __data) \
weechat_plugin->hook_config(weechat_plugin, __type, __option, \
__callback, __data)
#define weechat_hook_completion(__completion, __callback, __data) \
weechat_plugin->hook_completion(weechat_plugin, __completion, \
__callback, __data)
#define weechat_unhook(__hook) \
weechat_plugin->unhook(weechat_plugin, __hook)
#define weechat_unhook_all() \