diff --git a/ChangeLog b/ChangeLog index fa81a0e5b..38d736895 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ ChangeLog - 2007-03-01 Version 0.2.4 (under dev!): + * fixed completion of redefined commands removed by plugins (bug #19176) * fixed memory leaks in perl and python plugins (bug #19163) * added "call" option to /key command, added new key function "insert" to insert text on command line (task #6468) diff --git a/src/common/command.c b/src/common/command.c index 07bf7efea..5c8961522 100644 --- a/src/common/command.c +++ b/src/common/command.c @@ -275,6 +275,45 @@ command_index_free () } } +/* + * command_used_by_weechat: return 1 if command is used by weechat + * (weechat command, IRC command or alias) + */ + +int +command_used_by_weechat (char *command) +{ + t_weechat_alias *ptr_alias; + int i; + + /* look for alias */ + for (ptr_alias = weechat_alias; ptr_alias; + ptr_alias = ptr_alias->next_alias) + { + if (ascii_strcasecmp (ptr_alias->alias_name, command) == 0) + return 1; + } + + /* look for WeeChat command */ + for (i = 0; weechat_commands[i].command_name; i++) + { + if (ascii_strcasecmp (weechat_commands[i].command_name, command) == 0) + return 1; + } + + /* look for IRC command */ + for (i = 0; irc_commands[i].command_name; i++) + { + if ((ascii_strcasecmp (irc_commands[i].command_name, command) == 0) && + ((irc_commands[i].cmd_function_args) || + (irc_commands[i].cmd_function_1arg))) + return 1; + } + + /* no command/alias found */ + return 0; +} + /* * exec_weechat_command: executes a command (WeeChat internal or IRC) * if only_builtin == 1, then try only WeeChat/IRC commands diff --git a/src/common/command.h b/src/common/command.h index 48ef14d2b..1cdfa06d6 100644 --- a/src/common/command.h +++ b/src/common/command.h @@ -53,6 +53,7 @@ extern t_weelist *last_index_command; extern void command_index_build (); extern void command_index_free (); +extern int command_used_by_weechat (char *); extern char **split_multi_command (char *, char); extern void free_multi_command (char **); extern int exec_weechat_command (t_irc_server *, t_irc_channel *, char *, int); diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index 812ba9d35..3f2dbb26d 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -752,7 +752,8 @@ plugin_handler_remove (t_weechat_plugin *plugin, (handler->next_handler)->prev_handler = handler->prev_handler; /* remove command from WeeChat command list, if command handler */ - if (handler->type == PLUGIN_HANDLER_COMMAND) + if ((handler->type == PLUGIN_HANDLER_COMMAND) + && (!command_used_by_weechat (handler->command))) weelist_remove (&index_commands, &last_index_command, weelist_search (index_commands, handler->command)); diff --git a/weechat/ChangeLog b/weechat/ChangeLog index fa81a0e5b..38d736895 100644 --- a/weechat/ChangeLog +++ b/weechat/ChangeLog @@ -5,6 +5,7 @@ ChangeLog - 2007-03-01 Version 0.2.4 (under dev!): + * fixed completion of redefined commands removed by plugins (bug #19176) * fixed memory leaks in perl and python plugins (bug #19163) * added "call" option to /key command, added new key function "insert" to insert text on command line (task #6468) diff --git a/weechat/src/common/command.c b/weechat/src/common/command.c index 07bf7efea..5c8961522 100644 --- a/weechat/src/common/command.c +++ b/weechat/src/common/command.c @@ -275,6 +275,45 @@ command_index_free () } } +/* + * command_used_by_weechat: return 1 if command is used by weechat + * (weechat command, IRC command or alias) + */ + +int +command_used_by_weechat (char *command) +{ + t_weechat_alias *ptr_alias; + int i; + + /* look for alias */ + for (ptr_alias = weechat_alias; ptr_alias; + ptr_alias = ptr_alias->next_alias) + { + if (ascii_strcasecmp (ptr_alias->alias_name, command) == 0) + return 1; + } + + /* look for WeeChat command */ + for (i = 0; weechat_commands[i].command_name; i++) + { + if (ascii_strcasecmp (weechat_commands[i].command_name, command) == 0) + return 1; + } + + /* look for IRC command */ + for (i = 0; irc_commands[i].command_name; i++) + { + if ((ascii_strcasecmp (irc_commands[i].command_name, command) == 0) && + ((irc_commands[i].cmd_function_args) || + (irc_commands[i].cmd_function_1arg))) + return 1; + } + + /* no command/alias found */ + return 0; +} + /* * exec_weechat_command: executes a command (WeeChat internal or IRC) * if only_builtin == 1, then try only WeeChat/IRC commands diff --git a/weechat/src/common/command.h b/weechat/src/common/command.h index 48ef14d2b..1cdfa06d6 100644 --- a/weechat/src/common/command.h +++ b/weechat/src/common/command.h @@ -53,6 +53,7 @@ extern t_weelist *last_index_command; extern void command_index_build (); extern void command_index_free (); +extern int command_used_by_weechat (char *); extern char **split_multi_command (char *, char); extern void free_multi_command (char **); extern int exec_weechat_command (t_irc_server *, t_irc_channel *, char *, int); diff --git a/weechat/src/plugins/plugins.c b/weechat/src/plugins/plugins.c index 812ba9d35..3f2dbb26d 100644 --- a/weechat/src/plugins/plugins.c +++ b/weechat/src/plugins/plugins.c @@ -752,7 +752,8 @@ plugin_handler_remove (t_weechat_plugin *plugin, (handler->next_handler)->prev_handler = handler->prev_handler; /* remove command from WeeChat command list, if command handler */ - if (handler->type == PLUGIN_HANDLER_COMMAND) + if ((handler->type == PLUGIN_HANDLER_COMMAND) + && (!command_used_by_weechat (handler->command))) weelist_remove (&index_commands, &last_index_command, weelist_search (index_commands, handler->command));