summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-09-18 16:27:34 +0100
committerMaxime Coste <frrrwww@gmail.com>2016-09-18 16:27:34 +0100
commit44e9da3beed9e4b5e5bbf2a10a465c77d61c0a48 (patch)
tree142951ea2ab4ad3e08b0dff61df7ca6c30a737d5
parentd14c39ebddecb2e154bfe0e87fcb34419380c5e5 (diff)
More command completer code cleanup
-rw-r--r--src/commands.cc49
1 files changed, 20 insertions, 29 deletions
diff --git a/src/commands.cc b/src/commands.cc
index a84c8427..c96a302b 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -166,6 +166,21 @@ const ParameterDesc single_optional_name_param{ {}, ParameterDesc::Flags::None,
static constexpr auto scopes = { "global", "buffer", "window" };
+static Completions complete_scope(const Context&, CompletionFlags,
+ const String& prefix, ByteCount cursor_pos)
+{
+ return { 0_byte, cursor_pos, complete(prefix, cursor_pos, scopes) };
+}
+
+
+static Completions complete_command_name(const Context& context, CompletionFlags,
+ const String& prefix, ByteCount cursor_pos)
+{
+ return CommandManager::instance().complete_command_name(
+ context, prefix.substr(0, cursor_pos), false);
+}
+
+
Scope* get_scope_ifp(StringView scope, const Context& context)
{
if (prefix_match("global", scope))
@@ -740,20 +755,11 @@ const CommandDesc add_hook_cmd = {
},
CommandFlags::None,
CommandHelper{},
- [](const Context& context, CompletionFlags flags,
- CommandParameters params, size_t token_to_complete,
- ByteCount pos_in_token) -> Completions
- {
- if (token_to_complete == 0)
- return { 0_byte, params[0].length(),
- complete(params[0], pos_in_token, scopes) };
- else if (token_to_complete == 3)
- {
- auto& cm = CommandManager::instance();
- return cm.complete(context, flags, params[3], pos_in_token);
- }
- return {};
- },
+ make_completer(&complete_scope, &complete_nothing, &complete_nothing,
+ [](const Context& context, CompletionFlags flags,
+ const String& prefix, ByteCount cursor_pos)
+ { return CommandManager::instance().complete(
+ context, flags, prefix, cursor_pos); }),
[](const ParametersParser& parser, Context& context, const ShellContext&)
{
Regex regex(parser[2], Regex::optimize | Regex::nosubs | Regex::ECMAScript);
@@ -1004,21 +1010,6 @@ const CommandDesc define_command_cmd = {
define_command
};
-static Completions complete_scope(const Context&, CompletionFlags,
- const String& prefix, ByteCount cursor_pos)
-{
- auto scopes = {"global", "buffer", "window"};
- return { 0_byte, cursor_pos, complete(prefix, cursor_pos, scopes) };
-}
-
-
-static Completions complete_command_name(const Context& context, CompletionFlags,
- const String& prefix, ByteCount cursor_pos)
-{
- return CommandManager::instance().complete_command_name(
- context, prefix.substr(0, cursor_pos), false);
-}
-
const CommandDesc alias_cmd = {
"alias",
nullptr,