From a32d7069c646c895a5a8b11734040aed75ca1f44 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 26 Aug 2018 12:29:11 +1000 Subject: [PATCH] Try to complete command switches when an argument starts with '-' Fixes #1467 --- src/command_manager.cc | 16 +++++++++++++--- 1 file 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 params; for (auto it = tokens.begin() + 1; it != tokens.end(); ++it)