diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2009-05-08 10:31:15 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2009-05-08 10:31:15 +0200 |
commit | 2783b512015e0a42b528042a218d0e3a8843b7e5 (patch) | |
tree | 9d5e89652388f3615e7383ea0c913946cf85d1c6 | |
parent | d3976c2afe608d70724e2d3d59093b6fbb3d230a (diff) | |
download | weechat-2783b512015e0a42b528042a218d0e3a8843b7e5.zip |
Improve completion: allow a command to use completion of another command (used by alias plugin)
-rw-r--r-- | doc/de/dev/plugin_c_api.de.xml | 33 | ||||
-rw-r--r-- | doc/en/dev/plugin_c_api.en.xml | 33 | ||||
-rw-r--r-- | doc/fr/dev/plugin_c_api.fr.xml | 33 | ||||
-rw-r--r-- | src/gui/gui-completion.c | 23 | ||||
-rw-r--r-- | src/plugins/alias/alias.c | 14 |
5 files changed, 113 insertions, 23 deletions
diff --git a/doc/de/dev/plugin_c_api.de.xml b/doc/de/dev/plugin_c_api.de.xml index f35947871..99bf68902 100644 --- a/doc/de/dev/plugin_c_api.de.xml +++ b/doc/de/dev/plugin_c_api.de.xml @@ -5035,6 +5035,7 @@ struct t_hook *weechat_hook_command ( <option>completion</option>: completion template for command: list of completions for each arguments, separated by space. Many completions are possible for one argument, separated by "|". + Many templates are possible for same command, separeted by "||". Default completion codes are: <informaltable colsep="0" frame="none"> <tgroup cols="3"> @@ -5061,6 +5062,10 @@ struct t_hook *weechat_hook_command ( </thead> <tbody> <row> + <entry>%%command</entry> + <entry>Reuse completion template from /command</entry> + </row> + <row> <entry>%-</entry> <entry>Stop completion</entry> </row> @@ -5152,13 +5157,29 @@ my_command_cb (void *data, struct t_gui_buffer *buffer, int argc, return WEECHAT_RC_OK; } +/* this is an example, inspired by weechat command /filter */ struct t_hook *my_command_hook = - weechat_hook_command ("mycommand", - "description of my command", - "[command [buffer]]", - "command: WeeChat or plugin command\n" - " buffer: buffer name", - "%w|%p %b", &my_command_cb, NULL); + weechat_hook_command (/* command name */ + "myfilter", + /* description */ + "description of myfilter", + /* args */ + "[list] | [enable|disable|toggle [name]] | " + "[add name plugin.buffer tags regex] | " + "[del name|-all]", + /* args description */ + "description of arguments...", + /* completion */ + "list" + " || enable %(filters_names)" + " || disable %(filters_names)" + " || toggle %(filters_names)" + " || add %(filters_names) %(buffers_plugins_names)|*" + " || del %(filters_names)|-all", + /* callback */ + &my_command_cb, + /* callback_data */ + NULL); </screen> </para> </section> diff --git a/doc/en/dev/plugin_c_api.en.xml b/doc/en/dev/plugin_c_api.en.xml index 211163bdf..538828c09 100644 --- a/doc/en/dev/plugin_c_api.en.xml +++ b/doc/en/dev/plugin_c_api.en.xml @@ -5034,6 +5034,7 @@ struct t_hook *weechat_hook_command ( <option>completion</option>: completion template for command: list of completions for each arguments, separated by space. Many completions are possible for one argument, separated by "|". + Many templates are possible for same command, separeted by "||". Default completion codes are: <informaltable colsep="0" frame="none"> <tgroup cols="3"> @@ -5060,6 +5061,10 @@ struct t_hook *weechat_hook_command ( </thead> <tbody> <row> + <entry>%%command</entry> + <entry>Reuse completion template from /command</entry> + </row> + <row> <entry>%-</entry> <entry>Stop completion</entry> </row> @@ -5151,13 +5156,29 @@ my_command_cb (void *data, struct t_gui_buffer *buffer, int argc, return WEECHAT_RC_OK; } +/* this is an example, inspired by weechat command /filter */ struct t_hook *my_command_hook = - weechat_hook_command ("mycommand", - "description of my command", - "[command [buffer]]", - "command: WeeChat or plugin command\n" - " buffer: buffer name", - "%w|%p %b", &my_command_cb, NULL); + weechat_hook_command (/* command name */ + "myfilter", + /* description */ + "description of myfilter", + /* args */ + "[list] | [enable|disable|toggle [name]] | " + "[add name plugin.buffer tags regex] | " + "[del name|-all]", + /* args description */ + "description of arguments...", + /* completion */ + "list" + " || enable %(filters_names)" + " || disable %(filters_names)" + " || toggle %(filters_names)" + " || add %(filters_names) %(buffers_plugins_names)|*" + " || del %(filters_names)|-all", + /* callback */ + &my_command_cb, + /* callback_data */ + NULL); </screen> </para> </section> diff --git a/doc/fr/dev/plugin_c_api.fr.xml b/doc/fr/dev/plugin_c_api.fr.xml index 0c00862ff..dc43378f1 100644 --- a/doc/fr/dev/plugin_c_api.fr.xml +++ b/doc/fr/dev/plugin_c_api.fr.xml @@ -5035,6 +5035,7 @@ struct t_hook *weechat_hook_command ( <option>completion</option>: completion template for command: list of completions for each arguments, separated by space. Many completions are possible for one argument, separated by "|". + Many templates are possible for same command, separeted by "||". Default completion codes are: <informaltable colsep="0" frame="none"> <tgroup cols="3"> @@ -5061,6 +5062,10 @@ struct t_hook *weechat_hook_command ( </thead> <tbody> <row> + <entry>%%command</entry> + <entry>Reuse completion template from /command</entry> + </row> + <row> <entry>%-</entry> <entry>Stop completion</entry> </row> @@ -5152,13 +5157,29 @@ my_command_cb (void *data, struct t_gui_buffer *buffer, int argc, return WEECHAT_RC_OK; } +/* this is an example, inspired by weechat command /filter */ struct t_hook *my_command_hook = - weechat_hook_command ("mycommand", - "description of my command", - "[command [buffer]]", - "command: WeeChat or plugin command\n" - " buffer: buffer name", - "%w|%p %b", &my_command_cb, NULL); + weechat_hook_command (/* command name */ + "myfilter", + /* description */ + "description of myfilter", + /* args */ + "[list] | [enable|disable|toggle [name]] | " + "[add name plugin.buffer tags regex] | " + "[del name|-all]", + /* args description */ + "description of arguments...", + /* completion */ + "list" + " || enable %(filters_names)" + " || disable %(filters_names)" + " || toggle %(filters_names)" + " || add %(filters_names) %(buffers_plugins_names)|*" + " || del %(filters_names)|-all", + /* callback */ + &my_command_cb, + /* callback_data */ + NULL); </screen> </para> </section> diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c index 50e4b5328..f41f93bf4 100644 --- a/src/gui/gui-completion.c +++ b/src/gui/gui-completion.c @@ -209,7 +209,7 @@ gui_completion_stop (struct t_gui_completion *completion, */ struct t_hook * -gui_completion_search_command (struct t_gui_completion *completion) +gui_completion_search_command (const char *command) { struct t_hook *ptr_hook; @@ -220,7 +220,7 @@ gui_completion_search_command (struct t_gui_completion *completion) && HOOK_COMMAND(ptr_hook, command) && HOOK_COMMAND(ptr_hook, command)[0] && (string_strcasecmp (HOOK_COMMAND(ptr_hook, command), - completion->base_command) == 0)) + command) == 0)) return ptr_hook; } @@ -1397,7 +1397,22 @@ gui_completion_get_template_for_args (struct t_gui_completion *completion, struct t_hook *hook_command) { int matching_template; - + + /* if template refers to another command, search this command and use its + template */ + if ((HOOK_COMMAND(hook_command, cplt_templates)[0][0] == '%') + && (HOOK_COMMAND(hook_command, cplt_templates)[0][1] == '%') + && (HOOK_COMMAND(hook_command, cplt_templates)[0][1])) + { + hook_command = gui_completion_search_command (HOOK_COMMAND(hook_command, cplt_templates)[0] + 2); + if (!hook_command + || ((HOOK_COMMAND(hook_command, cplt_templates)[0][0] == '%') + && (HOOK_COMMAND(hook_command, cplt_templates)[0][1] == '%'))) + { + return strdup (""); + } + } + /* if only one template available, then use it */ if (HOOK_COMMAND(hook_command, cplt_num_templates) == 1) return strdup (HOOK_COMMAND(hook_command, cplt_templates)[0]); @@ -1432,7 +1447,7 @@ gui_completion_build_list (struct t_gui_completion *completion) repeat_last = 0; - ptr_hook = gui_completion_search_command (completion); + ptr_hook = gui_completion_search_command (completion->base_command); if (!ptr_hook || !HOOK_COMMAND(ptr_hook, completion) || (strcmp (HOOK_COMMAND(ptr_hook, completion), "-") == 0)) { diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c index ab0dcdc40..0b51c9bdd 100644 --- a/src/plugins/alias/alias.c +++ b/src/plugins/alias/alias.c @@ -378,6 +378,8 @@ alias_new (const char *name, const char *command) { struct t_alias *new_alias, *ptr_alias, *pos_alias; struct t_hook *new_hook; + char *str_completion; + int length; if (!name || !name[0] || !command || !command[0]) return NULL; @@ -399,8 +401,18 @@ alias_new (const char *name, const char *command) new_alias = malloc (sizeof (*new_alias)); if (new_alias) { - new_hook = weechat_hook_command (name, "[alias]", NULL, NULL, NULL, + length = 2 + strlen (command) + 1; + str_completion = malloc (length); + if (str_completion) + { + snprintf (str_completion, length, "%%%%%s", + (command[0] == '/') ? command + 1 : command); + } + new_hook = weechat_hook_command (name, "[alias]", NULL, NULL, + (str_completion) ? str_completion : NULL, alias_cb, new_alias); + if (str_completion) + free (str_completion); if (!new_hook) { free (new_alias); |