From 49ef9968c09f80c8bd213e522afd2cf8c7af2ff1 Mon Sep 17 00:00:00 2001 From: Tim Allen Date: Tue, 21 Aug 2018 18:24:14 +1000 Subject: [PATCH 1/2] Support user-defined "str-to-str-map" options. --- doc/pages/options.asciidoc | 1 + src/commands.cc | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/pages/options.asciidoc b/doc/pages/options.asciidoc index 7e8bb52e..860e4914 100644 --- a/doc/pages/options.asciidoc +++ b/doc/pages/options.asciidoc @@ -120,6 +120,7 @@ are exclusively available to built-in options. a list of `key=value` pairs. `set -add` adds the new pair to the hashmap or replace an already existing key. + Only `str-to-str-map` options can be created with `declare-option`. == Builtin options diff --git a/src/commands.cc b/src/commands.cc index 98cbdbad..d00991a5 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1446,7 +1446,8 @@ const CommandDesc declare_option_cmd = { " str-list: list of character strings\n" " completions: list of completion candidates\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{ { { "hidden", { false, "do not display option name when completing" } }, { "docstring", { true, "specify option description" } } }, @@ -1457,7 +1458,7 @@ const CommandDesc declare_option_cmd = { make_completer( [](const Context& context, CompletionFlags flags, 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) }; }), [](const ParametersParser& parser, Context& context, const ShellContext&) @@ -1490,6 +1491,8 @@ const CommandDesc declare_option_cmd = { opt = ®.declare_option>(parser[1], docstring, {}, flags); else if (parser[0] == "range-specs") opt = ®.declare_option>(parser[1], docstring, {}, flags); + else if (parser[0] == "str-to-str-map") + opt = ®.declare_option>(parser[1], docstring, {}, flags); else throw runtime_error(format("no such option type: '{}'", parser[0])); From ede9155fc778de8153806815c5bc413c7e1bf142 Mon Sep 17 00:00:00 2001 From: Tim Allen Date: Tue, 21 Aug 2018 18:24:33 +1000 Subject: [PATCH 2/2] Document which option-types can be used with declare-options. --- doc/pages/options.asciidoc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/pages/options.asciidoc b/doc/pages/options.asciidoc index 860e4914..4c854afe 100644 --- a/doc/pages/options.asciidoc +++ b/doc/pages/options.asciidoc @@ -77,10 +77,13 @@ are exclusively available to built-in options. *coord*:: a line, column pair (separated by a comma) + Cannot be used with `declare-option` *-list*:: a list, elements are specified as separate arguments to the command. `set -add` appends the new element to the list + Only `int-list` and `str-list` options can be created with + `declare-option`. *range-specs*:: a list of a pair of a buffer range (`., @@ -110,11 +113,13 @@ are exclusively available to built-in options. *enum(value1|value2|...)*:: an enum, taking one of the given values + Cannot be used with `declare-option` *flags(value1|value2|...)*:: a set of flags, taking a combination of the given values joined by a '|' character. `set -add` adds the new flag to the combination + Cannot be used with `declare-option` *-to--map*:: a list of `key=value` pairs.