From 8b2e5ea862c748e13fbfd49ee3a00c8918d3ee10 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 31 May 2018 20:59:21 +1000 Subject: [PATCH] Make selection lists use the option list syntax --- src/commands.cc | 8 ++++---- src/option_types.hh | 6 ------ src/selection.cc | 11 +++++------ src/selection.hh | 2 +- src/string_utils.hh | 5 +++++ 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index 7c840fb7..233c8f89 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -2113,16 +2113,16 @@ const CommandDesc set_register_cmd = { const CommandDesc select_cmd = { "select", nullptr, - "select : select given selections\n" + "select ...: select given selections\n" "\n" - "selections_desc format is .,.:...", - single_param, + "selection_desc format is .,.", + ParameterDesc{{}, ParameterDesc::Flags::SwitchesAsPositional, 1}, CommandFlags::None, CommandHelper{}, CommandCompleter{}, [](const ParametersParser& parser, Context& context, const ShellContext&) { - context.selections_write_only() = selection_list_from_string(context.buffer(), parser[0]); + context.selections_write_only() = selection_list_from_string(context.buffer(), parser.positionals_from(0)); } }; diff --git a/src/option_types.hh b/src/option_types.hh index 886008b7..8a782e15 100644 --- a/src/option_types.hh +++ b/src/option_types.hh @@ -18,12 +18,6 @@ namespace Kakoune { - -inline String quote(StringView s) -{ - return format("'{}'", replace(s, "'", "''")); -} - template constexpr decltype(T::option_type_name) option_type_name(Meta::Type) { diff --git a/src/selection.cc b/src/selection.cc index 2a4a4629..1cd8641c 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -477,7 +477,7 @@ String selection_list_to_string(const SelectionList& selections) auto main = beg + selections.main_index(); using View = ConstArrayView; return join(concatenated(View{main, end}, View{beg, main}) | - transform(selection_to_string), ':', false); + transform(selection_to_string), ' ', false); } Selection selection_from_string(StringView desc) @@ -502,14 +502,13 @@ Selection selection_from_string(StringView desc) return Selection{anchor, cursor}; } -SelectionList selection_list_from_string(Buffer& buffer, StringView desc) +SelectionList selection_list_from_string(Buffer& buffer, ConstArrayView descs) { - if (desc.empty()) + if (descs.empty()) throw runtime_error{"empty selection description"}; - auto sels = desc | split(':') - | transform([&](auto&& d) { auto s = selection_from_string(d); clamp(s, buffer); return s; }) - | gather>(); + auto sels = descs | transform([&](auto&& d) { auto s = selection_from_string(d); clamp(s, buffer); return s; }) + | gather>(); return {SelectionList::UnsortedTag{}, buffer, std::move(sels)}; } diff --git a/src/selection.hh b/src/selection.hh index bf24ad95..33df78ce 100644 --- a/src/selection.hh +++ b/src/selection.hh @@ -155,7 +155,7 @@ Vector compute_modified_ranges(Buffer& buffer, size_t timestamp); String selection_to_string(const Selection& selection); String selection_list_to_string(const SelectionList& selection); Selection selection_from_string(StringView desc); -SelectionList selection_list_from_string(Buffer& buffer, StringView desc); +SelectionList selection_list_from_string(Buffer& buffer, ConstArrayView descs); } diff --git a/src/string_utils.hh b/src/string_utils.hh index bd803536..61a28cad 100644 --- a/src/string_utils.hh +++ b/src/string_utils.hh @@ -128,6 +128,11 @@ StringView format_to(ArrayView buffer, StringView fmt, Types&&... params) return format_to(buffer, fmt, ArrayView{detail::format_param(std::forward(params))...}); } +inline String quote(StringView s) +{ + return format("'{}'", replace(s, "'", "''")); +} + } #endif // string_utils_hh_INCLUDED