mirror of
https://github.com/weechat/weechat.git
synced 2026-07-06 17:53:13 +02:00
Improved alias completion (now uses target command for completion)
This commit is contained in:
+34
-1
@@ -352,6 +352,38 @@ alias_new (char *alias_name, char *alias_command)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_get_final_command: get final command pointer by an alias
|
||||
*/
|
||||
|
||||
char *
|
||||
alias_get_final_command (t_weechat_alias *alias)
|
||||
{
|
||||
t_weechat_alias *ptr_alias;
|
||||
char *result;
|
||||
|
||||
if (alias->running)
|
||||
{
|
||||
irc_display_prefix (NULL, NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s circular reference when calling alias \"/%s\"\n"),
|
||||
WEECHAT_ERROR, alias->alias_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ptr_alias = alias_search ((alias->alias_command[0] == '/') ?
|
||||
alias->alias_command + 1 : alias->alias_command);
|
||||
if (ptr_alias)
|
||||
{
|
||||
alias->running = 1;
|
||||
result = alias_get_final_command (ptr_alias);
|
||||
alias->running = 0;
|
||||
return result;
|
||||
}
|
||||
return (alias->alias_command[0] == '/') ?
|
||||
alias->alias_command + 1 : alias->alias_command;
|
||||
}
|
||||
|
||||
/*
|
||||
* alias_free: free an alias and reomve it from list
|
||||
*/
|
||||
@@ -802,7 +834,8 @@ exec_weechat_command (t_irc_server *server, t_irc_channel *channel, char *string
|
||||
if (ascii_strcasecmp (ptr_alias->alias_name, command + 1) == 0)
|
||||
{
|
||||
if (ptr_alias->running == 1)
|
||||
{
|
||||
{
|
||||
irc_display_prefix (NULL, NULL, PREFIX_ERROR);
|
||||
gui_printf (NULL,
|
||||
_("%s circular reference when calling alias \"/%s\"\n"),
|
||||
WEECHAT_ERROR, ptr_alias->alias_name);
|
||||
|
||||
@@ -63,7 +63,9 @@ extern t_weelist *last_index_command;
|
||||
|
||||
extern void command_index_build ();
|
||||
extern void command_index_free ();
|
||||
extern t_weechat_alias *alias_search (char *);
|
||||
extern t_weechat_alias *alias_new (char *, char *);
|
||||
extern char *alias_get_final_command (t_weechat_alias *);
|
||||
extern void alias_free_all ();
|
||||
extern char **explode_string (char *, char *, int, int *);
|
||||
extern void free_exploded_string (char **);
|
||||
|
||||
+15
-3
@@ -107,6 +107,8 @@ void
|
||||
completion_get_command_infos (t_completion *completion,
|
||||
char **template, int *max_arg)
|
||||
{
|
||||
t_weechat_alias *ptr_alias;
|
||||
char *ptr_command;
|
||||
int i;
|
||||
#ifdef PLUGINS
|
||||
t_weechat_plugin *ptr_plugin;
|
||||
@@ -116,6 +118,16 @@ completion_get_command_infos (t_completion *completion,
|
||||
*template = NULL;
|
||||
*max_arg = MAX_ARGS;
|
||||
|
||||
ptr_alias = alias_search (completion->base_command);
|
||||
if (ptr_alias)
|
||||
{
|
||||
ptr_command = alias_get_final_command (ptr_alias);
|
||||
if (!ptr_command)
|
||||
return;
|
||||
}
|
||||
else
|
||||
ptr_command = completion->base_command;
|
||||
|
||||
#ifdef PLUGINS
|
||||
/* look for plugin command handler */
|
||||
for (ptr_plugin = weechat_plugins; ptr_plugin;
|
||||
@@ -126,7 +138,7 @@ completion_get_command_infos (t_completion *completion,
|
||||
{
|
||||
if ((ptr_handler->type == HANDLER_COMMAND)
|
||||
&& (ascii_strcasecmp (ptr_handler->command,
|
||||
completion->base_command) == 0))
|
||||
ptr_command) == 0))
|
||||
{
|
||||
*template = ptr_handler->completion_template;
|
||||
*max_arg = MAX_ARGS;
|
||||
@@ -140,7 +152,7 @@ completion_get_command_infos (t_completion *completion,
|
||||
for (i = 0; weechat_commands[i].command_name; i++)
|
||||
{
|
||||
if (ascii_strcasecmp (weechat_commands[i].command_name,
|
||||
completion->base_command) == 0)
|
||||
ptr_command) == 0)
|
||||
{
|
||||
*template = weechat_commands[i].completion_template;
|
||||
*max_arg = weechat_commands[i].max_arg;
|
||||
@@ -153,7 +165,7 @@ completion_get_command_infos (t_completion *completion,
|
||||
{
|
||||
if ((irc_commands[i].cmd_function_args || irc_commands[i].cmd_function_1arg)
|
||||
&& (ascii_strcasecmp (irc_commands[i].command_name,
|
||||
completion->base_command) == 0))
|
||||
ptr_command) == 0))
|
||||
{
|
||||
*template = irc_commands[i].completion_template;
|
||||
*max_arg = irc_commands[i].max_arg;
|
||||
|
||||
Reference in New Issue
Block a user