summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2012-12-20 19:23:52 +0100
committerSebastien Helleu <flashcode@flashtux.org>2012-12-20 19:23:52 +0100
commitfa1665ef811e355665f983f9d2f8f1557bf790ea (patch)
treebb5f6e67bea693551658b302e1fe002d752ed280 /src/gui
parenta67d97f16ec43ecd820342b75449b9a4cdee7e0d (diff)
downloadweechat-fa1665ef811e355665f983f9d2f8f1557bf790ea.zip
core: search for a fallback template when a no template is matching command arguments
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui-completion.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/gui/gui-completion.c b/src/gui/gui-completion.c
index 00decef3a..57ba3f865 100644
--- a/src/gui/gui-completion.c
+++ b/src/gui/gui-completion.c
@@ -472,12 +472,14 @@ int
gui_completion_get_matching_template (struct t_gui_completion *completion,
struct t_hook *hook_command)
{
- int i, length;
+ int i, length, fallback;
/* without at least one argument, we can't find matching template! */
if (completion->base_command_arg_index <= 1)
return -1;
+ fallback = -1;
+
for (i = 0; i < HOOK_COMMAND(hook_command, cplt_num_templates); i++)
{
length = strlen (HOOK_COMMAND(hook_command, cplt_templates_static)[i]);
@@ -487,9 +489,23 @@ gui_completion_get_matching_template (struct t_gui_completion *completion,
{
return i;
}
+ /*
+ * try to find a fallback template if we don't find any matching
+ * template, for example with these templates (command /set):
+ * %(config_options) %(config_option_values)
+ * diff %(config_options)|%*
+ * if first argument is "diff", the match is ok (second template)
+ * if first argument is not "diff", we will fallback on the first
+ * template containing "%" (here first template)
+ */
+ if ((fallback < 0)
+ && (strstr (HOOK_COMMAND(hook_command, cplt_templates_static)[i], "%")))
+ {
+ fallback = i;
+ }
}
- return -1;
+ return fallback;
}
/*