mirror of
https://github.com/weechat/weechat.git
synced 2026-07-08 10:43:13 +02:00
Improve completion: allow a command to use completion of another command (used by alias plugin)
This commit is contained in:
@@ -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">
|
||||
@@ -5060,6 +5061,10 @@ struct t_hook *weechat_hook_command (
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>%%command</entry>
|
||||
<entry>Reuse completion template from /command</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>%-</entry>
|
||||
<entry>Stop completion</entry>
|
||||
@@ -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>
|
||||
|
||||
@@ -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">
|
||||
@@ -5059,6 +5060,10 @@ struct t_hook *weechat_hook_command (
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>%%command</entry>
|
||||
<entry>Reuse completion template from /command</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>%-</entry>
|
||||
<entry>Stop completion</entry>
|
||||
@@ -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>
|
||||
|
||||
@@ -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">
|
||||
@@ -5060,6 +5061,10 @@ struct t_hook *weechat_hook_command (
|
||||
</row>
|
||||
</thead>
|
||||
<tbody>
|
||||
<row>
|
||||
<entry>%%command</entry>
|
||||
<entry>Reuse completion template from /command</entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry>%-</entry>
|
||||
<entry>Stop completion</entry>
|
||||
@@ -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>
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user