summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-08-26 12:29:11 +1000
committerMaxime Coste <mawww@kakoune.org>2018-08-26 12:29:11 +1000
commita32d7069c646c895a5a8b11734040aed75ca1f44 (patch)
treee6ccd19d577f3b116eb5414a64eda26304e947f9
parent8a904b02b95f3fac7f547f104746380a1cca5a01 (diff)
Try to complete command switches when an argument starts with '-'
Fixes #1467
-rw-r--r--src/command_manager.cc16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/command_manager.cc b/src/command_manager.cc
index 91b5fb82..7537f450 100644
--- a/src/command_manager.cc
+++ b/src/command_manager.cc
@@ -663,9 +663,19 @@ Completions CommandManager::complete(const Context& context,
}
auto command_it = find_command(context, command_name);
- if (command_it == m_commands.end() or
- not command_it->value.completer)
- return Completions();
+ if (command_it == m_commands.end())
+ return Completions{};
+
+ if (token.content.substr(0_byte, 1_byte) == "-")
+ {
+ auto switches = Kakoune::complete(token.content.substr(1_byte), cursor_pos_in_token,
+ command_it->value.param_desc.switches |
+ transform(&SwitchMap::Item::key));
+ if (not switches.empty())
+ return Completions{start+1, cursor_pos, std::move(switches)};
+ }
+ if (not command_it->value.completer)
+ return Completions{};
Vector<String> params;
for (auto it = tokens.begin() + 1; it != tokens.end(); ++it)