summaryrefslogtreecommitdiffstats
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
parentcore: add option "diff" for command /set (list options with changed value) (diff)
downloadweechat-fa1665ef811e355665f983f9d2f8f1557bf790ea.tar.xz
weechat-fa1665ef811e355665f983f9d2f8f1557bf790ea.zip
core: search for a fallback template when a no template is matching command arguments
-rw-r--r--ChangeLog2
-rw-r--r--src/gui/gui-completion.c20
2 files changed, 20 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 63d533f3d..fbdc137b5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,8 @@ v0.4.0-dev, 2012-12-20
Version 0.4.0 (under dev!)
--------------------------
+* core: search for a fallback template when a no template is matching command
+ arguments
* core: add option "diff" for command /set (list options with changed value)
* core: fix refresh of windows after split (fix bug with horizontal separator
between windows) (bug #37874)
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;
}
/*