Merge remote-tracking branch 'Screwtapello/support-user-map-options'

This commit is contained in:
Maxime Coste 2018-08-30 20:10:00 +10:00
commit df655422d1
2 changed files with 11 additions and 2 deletions

View File

@ -77,10 +77,13 @@ are exclusively available to built-in options.
*coord*:: *coord*::
a line, column pair (separated by a comma) a line, column pair (separated by a comma)
Cannot be used with `declare-option`
*<type>-list*:: *<type>-list*::
a list, elements are specified as separate arguments to the command. a list, elements are specified as separate arguments to the command.
`set -add` appends the new element to the list `set -add` appends the new element to the list
Only `int-list` and `str-list` options can be created with
`declare-option`.
*range-specs*:: *range-specs*::
a list of a pair of a buffer range (`<begin line>.<begin column>, a list of a pair of a buffer range (`<begin line>.<begin column>,
@ -110,16 +113,19 @@ are exclusively available to built-in options.
*enum(value1|value2|...)*:: *enum(value1|value2|...)*::
an enum, taking one of the given values an enum, taking one of the given values
Cannot be used with `declare-option`
*flags(value1|value2|...)*:: *flags(value1|value2|...)*::
a set of flags, taking a combination of the given values joined by a a set of flags, taking a combination of the given values joined by a
'|' character. '|' character.
`set -add` adds the new flag to the combination `set -add` adds the new flag to the combination
Cannot be used with `declare-option`
*<type>-to-<type>-map*:: *<type>-to-<type>-map*::
a list of `key=value` pairs. a list of `key=value` pairs.
`set -add` adds the new pair to the hashmap or replace an already `set -add` adds the new pair to the hashmap or replace an already
existing key. existing key.
Only `str-to-str-map` options can be created with `declare-option`.
== Builtin options == Builtin options

View File

@ -1448,7 +1448,8 @@ const CommandDesc declare_option_cmd = {
" str-list: list of character strings\n" " str-list: list of character strings\n"
" completions: list of completion candidates\n" " completions: list of completion candidates\n"
" line-specs: list of line specs\n" " line-specs: list of line specs\n"
" range-specs: list of range specs\n", " range-specs: list of range specs\n"
" str-to-str-map: map from strings to strings\n",
ParameterDesc{ ParameterDesc{
{ { "hidden", { false, "do not display option name when completing" } }, { { "hidden", { false, "do not display option name when completing" } },
{ "docstring", { true, "specify option description" } } }, { "docstring", { true, "specify option description" } } },
@ -1459,7 +1460,7 @@ const CommandDesc declare_option_cmd = {
make_completer( make_completer(
[](const Context& context, CompletionFlags flags, [](const Context& context, CompletionFlags flags,
const String& prefix, ByteCount cursor_pos) -> Completions { const String& prefix, ByteCount cursor_pos) -> Completions {
auto c = {"int", "bool", "str", "regex", "int-list", "str-list", "completions", "line-specs", "range-specs"}; auto c = {"int", "bool", "str", "regex", "int-list", "str-list", "completions", "line-specs", "range-specs", "str-to-str-map"};
return { 0_byte, cursor_pos, complete(prefix, cursor_pos, c) }; return { 0_byte, cursor_pos, complete(prefix, cursor_pos, c) };
}), }),
[](const ParametersParser& parser, Context& context, const ShellContext&) [](const ParametersParser& parser, Context& context, const ShellContext&)
@ -1492,6 +1493,8 @@ const CommandDesc declare_option_cmd = {
opt = &reg.declare_option<TimestampedList<LineAndSpec>>(parser[1], docstring, {}, flags); opt = &reg.declare_option<TimestampedList<LineAndSpec>>(parser[1], docstring, {}, flags);
else if (parser[0] == "range-specs") else if (parser[0] == "range-specs")
opt = &reg.declare_option<TimestampedList<RangeAndString>>(parser[1], docstring, {}, flags); opt = &reg.declare_option<TimestampedList<RangeAndString>>(parser[1], docstring, {}, flags);
else if (parser[0] == "str-to-str-map")
opt = &reg.declare_option<HashMap<String, String, MemoryDomain::Options>>(parser[1], docstring, {}, flags);
else else
throw runtime_error(format("no such option type: '{}'", parser[0])); throw runtime_error(format("no such option type: '{}'", parser[0]));