summaryrefslogtreecommitdiff
path: root/src/commands.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-05-30 23:23:38 +1000
committerMaxime Coste <mawww@kakoune.org>2018-07-05 07:54:28 +1000
commitb548dd3a6f369e5a244fdcdca55061513026f82a (patch)
tree1ca672c1d6f976a74f34d37f75fd68a83933fbe1 /src/commands.cc
parent5eeec8bd4d24882ea443c4441f696257b8cb68c4 (diff)
Change option lists to be specified as separate arguments on commands line
Option lists and maps are specified using separate arguments, avoiding the need for additional escaping of their separator and reusing the existing command line spliting logic instead. As discussed on #2087, this should make it much easier to work with list options, and make the general option system feel cleaner.
Diffstat (limited to 'src/commands.cc')
-rw-r--r--src/commands.cc18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/commands.cc b/src/commands.cc
index 8323aa56..7c840fb7 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -1318,7 +1318,7 @@ const CommandDesc set_option_cmd = {
"scope the option is set in",
ParameterDesc{
{ { "add", { false, "add to option rather than replacing it" } } },
- ParameterDesc::Flags::SwitchesOnlyAtStart, 3, 3
+ ParameterDesc::Flags::SwitchesOnlyAtStart, 2, (size_t)-1
},
CommandFlags::None,
option_doc_helper,
@@ -1337,13 +1337,11 @@ const CommandDesc set_option_cmd = {
else if (token_to_complete == start + 1)
return { 0_byte, params[start + 1].length(),
GlobalScope::instance().option_registry().complete_option_name(params[start + 1], pos_in_token) };
- else if (not add and token_to_complete == start + 2 and
+ else if (not add and token_to_complete == start + 2 and params[start + 2].empty() and
GlobalScope::instance().option_registry().option_exists(params[start + 1]))
{
OptionManager& options = get_scope(params[start], context).options();
- String val = options[params[start + 1]].get_as_string();
- if (prefix_match(val, params[start + 2]))
- return { 0_byte, params[start + 2].length(), { std::move(val) } };
+ return { 0_byte, params[start + 2].length(), { options[params[start + 1]].get_as_string() }, true };
}
return Completions{};
},
@@ -1351,9 +1349,9 @@ const CommandDesc set_option_cmd = {
{
Option& opt = get_options(parser[0], context, parser[1]).get_local_option(parser[1]);
if (parser.get_switch("add"))
- opt.add_from_string(parser[2]);
+ opt.add_from_strings(parser.positionals_from(2));
else
- opt.set_from_string(parser[2]);
+ opt.set_from_strings(parser.positionals_from(2));
}
};
@@ -1427,7 +1425,7 @@ const CommandDesc declare_option_cmd = {
ParameterDesc{
{ { "hidden", { false, "do not display option name when completing" } },
{ "docstring", { true, "specify option description" } } },
- ParameterDesc::Flags::SwitchesOnlyAtStart, 2, 3
+ ParameterDesc::Flags::SwitchesOnlyAtStart, 2, (size_t)-1
},
CommandFlags::None,
CommandHelper{},
@@ -1470,8 +1468,8 @@ const CommandDesc declare_option_cmd = {
else
throw runtime_error(format("no such option type: '{}'", parser[0]));
- if (parser.positional_count() == 3)
- opt->set_from_string(parser[2]);
+ if (parser.positional_count() > 2)
+ opt->set_from_strings(parser.positionals_from(2));
}
};