summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2012-12-02 13:13:24 +0100
committerSebastien Helleu <flashcode@flashtux.org>2012-12-02 13:13:24 +0100
commit1fa23e6d9c7d36e5ece9daaf47bd8aec1ced8c83 (patch)
treecbcc3a8ee199386d8585d430d73fd9769e5dd192
parentc89124aadcb5d498db1c447c3200a21eadc930e8 (diff)
downloadweechat-1fa23e6d9c7d36e5ece9daaf47bd8aec1ced8c83.zip
alias: give higher priority to aliases (2000) so that they take precedence over an existing command
-rw-r--r--ChangeLog2
-rw-r--r--src/plugins/alias/alias.c28
2 files changed, 22 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index f34527607..fd3802026 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -33,6 +33,8 @@ Version 0.4.0 (under dev!)
shuffle list of hosts for a same address, add argument "retry" for
hook_connect, move "sock" from hook_connect arguments to callback of
hook_connect (task #11205)
+* alias: give higher priority to aliases (2000) so that they take precedence
+ over an existing command
* aspell: add bar items "aspell_dict" (dictionary used on current buffer) and
"aspell_suggest" (suggestions for misspelled word at cursor), add option
aspell.check.suggestions (task #12061)
diff --git a/src/plugins/alias/alias.c b/src/plugins/alias/alias.c
index 911dd048c..108426b1f 100644
--- a/src/plugins/alias/alias.c
+++ b/src/plugins/alias/alias.c
@@ -508,18 +508,27 @@ alias_find_pos (const char *name)
void
alias_hook_command (struct t_alias *alias)
{
- char *str_completion;
+ char *str_priority_name, *str_completion;
int length;
- str_completion = NULL;
+ /*
+ * build string with priority and name: the alias priority is 2000, which
+ * is higher than default one (1000), so the alias is executed before a
+ * command (if a command with same name exists in core or in another plugin)
+ */
+ length = strlen (alias->name) + 16 + 1;
+ str_priority_name = malloc (length);
+ if (str_priority_name)
+ snprintf (str_priority_name, length, "2000|%s", alias->name);
+ /*
+ * if alias has no custom completion, then default is to complete with
+ * completion template of target command, for example if alias is
+ * "/alias test /buffer", then str_completion will be "%%buffer"
+ */
+ str_completion = NULL;
if (!alias->completion)
{
- /*
- * if alias has no custom completion, then default is to complete with
- * completion template of target command, for example if alias is
- * "/alias test /buffer", then str_completion will be "%%buffer"
- */
length = 2 + strlen (alias->command) + 1;
str_completion = malloc (length);
if (str_completion)
@@ -530,11 +539,14 @@ alias_hook_command (struct t_alias *alias)
}
}
- alias->hook = weechat_hook_command (alias->name, alias->command,
+ alias->hook = weechat_hook_command ((str_priority_name) ? str_priority_name : alias->name,
+ alias->command,
NULL, NULL,
(str_completion) ? str_completion : alias->completion,
&alias_cb, alias);
+ if (str_priority_name)
+ free (str_priority_name);
if (str_completion)
free (str_completion);
}