Make selection lists use the option list syntax

This commit is contained in:
Maxime Coste 2018-05-31 20:59:21 +10:00
parent 2729042f83
commit 8b2e5ea862
5 changed files with 15 additions and 17 deletions

View File

@ -2113,16 +2113,16 @@ const CommandDesc set_register_cmd = {
const CommandDesc select_cmd = {
"select",
nullptr,
"select <selections_desc>: select given selections\n"
"select <selection_desc>...: select given selections\n"
"\n"
"selections_desc format is <anchor_line>.<anchor_column>,<cursor_line>.<cursor_column>:...",
single_param,
"selection_desc format is <anchor_line>.<anchor_column>,<cursor_line>.<cursor_column>",
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));
}
};

View File

@ -18,12 +18,6 @@
namespace Kakoune
{
inline String quote(StringView s)
{
return format("'{}'", replace(s, "'", "''"));
}
template<typename T>
constexpr decltype(T::option_type_name) option_type_name(Meta::Type<T>)
{

View File

@ -477,7 +477,7 @@ String selection_list_to_string(const SelectionList& selections)
auto main = beg + selections.main_index();
using View = ConstArrayView<Selection>;
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,13 +502,12 @@ 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<String> descs)
{
if (desc.empty())
if (descs.empty())
throw runtime_error{"empty selection description"};
auto sels = desc | split<StringView>(':')
| transform([&](auto&& d) { auto s = selection_from_string(d); clamp(s, buffer); return s; })
auto sels = descs | transform([&](auto&& d) { auto s = selection_from_string(d); clamp(s, buffer); return s; })
| gather<Vector<Selection>>();
return {SelectionList::UnsortedTag{}, buffer, std::move(sels)};
}

View File

@ -155,7 +155,7 @@ Vector<Selection> 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<String> descs);
}

View File

@ -128,6 +128,11 @@ StringView format_to(ArrayView<char> buffer, StringView fmt, Types&&... params)
return format_to(buffer, fmt, ArrayView<const StringView>{detail::format_param(std::forward<Types>(params))...});
}
inline String quote(StringView s)
{
return format("'{}'", replace(s, "'", "''"));
}
}
#endif // string_utils_hh_INCLUDED