From fcb37cc7541cfa2152f8c0aed6eda177bc9770a6 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 26 Sep 2016 23:32:07 +0100 Subject: [PATCH] Pass count to all object selectors --- src/normal.cc | 20 +++++++++----------- src/selectors.cc | 10 +++++----- src/selectors.hh | 33 +++++++++++++-------------------- 3 files changed, 27 insertions(+), 36 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index 3d1d05ce..e1564bca 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -933,9 +933,9 @@ void select_object(Context& context, NormalParams params) whole ? "" : (flags & ObjectFlags::ToBegin ? " begin" : " end")); }; - const int level = params.count <= 0 ? 0 : params.count - 1; + const int count = params.count <= 0 ? 0 : params.count - 1; on_next_key_with_autoinfo(context, KeymapMode::Object, - [level](Key key, Context& context) { + [count](Key key, Context& context) { auto cp = key.codepoint().value_or((Codepoint)-1); if (cp == -1) return; @@ -943,7 +943,7 @@ void select_object(Context& context, NormalParams params) static constexpr struct { Codepoint key; - Selection (*func)(const Buffer&, const Selection&, ObjectFlags); + Selection (*func)(const Buffer&, const Selection&, int, ObjectFlags); } selectors[] = { { 'w', select_word }, { 'W', select_word }, @@ -952,16 +952,14 @@ void select_object(Context& context, NormalParams params) { ' ', select_whitespaces }, { 'i', select_indent }, { 'n', select_number }, + { 'u', select_argument }, }; for (auto& sel : selectors) { if (cp == sel.key) - return select(context, std::bind(sel.func, _1, _2, flags)); + return select(context, std::bind(sel.func, _1, _2, count, flags)); } - if (cp == 'u') - return select(context, std::bind(select_argument, _1, _2, level, flags)); - if (cp == ':') { const bool info = show_auto_info_ifn( @@ -971,7 +969,7 @@ void select_object(Context& context, NormalParams params) context.input_handler().prompt( "object desc:", "", get_face("Prompt"), PromptFlags::None, complete_nothing, - [level,info](StringView cmdline, PromptEvent event, Context& context) { + [count,info](StringView cmdline, PromptEvent event, Context& context) { if (event != PromptEvent::Change) hide_auto_info_ifn(context, info); if (event != PromptEvent::Validate) @@ -982,7 +980,7 @@ void select_object(Context& context, NormalParams params) throw runtime_error{"desc parsing failed, expected ,"}; return select(context, std::bind(select_surrounding, _1, _2, - params[0], params[1], level, flags)); + params[0], params[1], count, flags)); }); } @@ -1007,7 +1005,7 @@ void select_object(Context& context, NormalParams params) (sur.name != 0 and sur.name == cp)) return select(context, std::bind(select_surrounding, _1, _2, sur.opening, sur.closing, - level, flags)); + count, flags)); } if (is_punctuation(cp)) @@ -1015,7 +1013,7 @@ void select_object(Context& context, NormalParams params) auto utf8cp = to_string(cp); return select(context, std::bind(select_surrounding, _1, _2, utf8cp, utf8cp, - level, flags)); + count, flags)); } }, get_title(), "b,(,): parenthesis block\n" diff --git a/src/selectors.cc b/src/selectors.cc index dc6edc98..0f519297 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -238,7 +238,7 @@ Selection select_to_reverse(const Buffer& buffer, const Selection& selection, return utf8_range(begin, inclusive ? end : end+1); } -Selection select_number(const Buffer& buffer, const Selection& selection, ObjectFlags flags) +Selection select_number(const Buffer& buffer, const Selection& selection, int count, ObjectFlags flags) { auto is_number = [&](char c) { return (c >= '0' and c <= '9') or @@ -272,7 +272,7 @@ Selection select_number(const Buffer& buffer, const Selection& selection, Object : Selection{last.coord(), first.coord()}; } -Selection select_sentence(const Buffer& buffer, const Selection& selection, ObjectFlags flags) +Selection select_sentence(const Buffer& buffer, const Selection& selection, int count, ObjectFlags flags) { auto is_end_of_sentence = [](char c) { return c == '.' or c == ';' or c == '!' or c == '?'; @@ -337,7 +337,7 @@ Selection select_sentence(const Buffer& buffer, const Selection& selection, Obje : Selection{last.coord(), first.coord()}; } -Selection select_paragraph(const Buffer& buffer, const Selection& selection, ObjectFlags flags) +Selection select_paragraph(const Buffer& buffer, const Selection& selection, int count, ObjectFlags flags) { BufferIterator first = buffer.iterator_at(selection.cursor()); @@ -390,7 +390,7 @@ Selection select_paragraph(const Buffer& buffer, const Selection& selection, Obj : Selection{last.coord(), first.coord()}; } -Selection select_whitespaces(const Buffer& buffer, const Selection& selection, ObjectFlags flags) +Selection select_whitespaces(const Buffer& buffer, const Selection& selection, int count, ObjectFlags flags) { auto is_whitespace = [&](char c) { return c == ' ' or c == '\t' or @@ -419,7 +419,7 @@ Selection select_whitespaces(const Buffer& buffer, const Selection& selection, O : Selection{last.coord(), first.coord()}; } -Selection select_indent(const Buffer& buffer, const Selection& selection, ObjectFlags flags) +Selection select_indent(const Buffer& buffer, const Selection& selection, int count, ObjectFlags flags) { auto get_indent = [](StringView str, int tabstop) { CharCount indent = 0; diff --git a/src/selectors.hh b/src/selectors.hh index 8982a00e..bf2a6450 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -144,9 +144,8 @@ enum class ObjectFlags template<> struct WithBitOps : std::true_type {}; template -Selection select_word(const Buffer& buffer, - const Selection& selection, - ObjectFlags flags) +Selection select_word(const Buffer& buffer, const Selection& selection, + int count, ObjectFlags flags) { Utf8Iterator first{buffer.iterator_at(selection.cursor()), buffer}; Utf8Iterator last = first; @@ -187,28 +186,22 @@ Selection select_word(const Buffer& buffer, : utf8_range(last, first); } -Selection select_number(const Buffer& buffer, - const Selection& selection, - ObjectFlags flags); +Selection select_number(const Buffer& buffer, const Selection& selection, + int count, ObjectFlags flags); -Selection select_sentence(const Buffer& buffer, - const Selection& selection, - ObjectFlags flags); +Selection select_sentence(const Buffer& buffer, const Selection& selection, + int count, ObjectFlags flags); -Selection select_paragraph(const Buffer& buffer, - const Selection& selection, - ObjectFlags flags); +Selection select_paragraph(const Buffer& buffer, const Selection& selection, + int count, ObjectFlags flags); -Selection select_whitespaces(const Buffer& buffer, - const Selection& selection, - ObjectFlags flags); +Selection select_whitespaces(const Buffer& buffer, const Selection& selection, + int count, ObjectFlags flags); -Selection select_indent(const Buffer& buffer, - const Selection& selection, - ObjectFlags flags); +Selection select_indent(const Buffer& buffer, const Selection& selection, + int count, ObjectFlags flags); -Selection select_argument(const Buffer& buffer, - const Selection& selection, +Selection select_argument(const Buffer& buffer, const Selection& selection, int level, ObjectFlags flags); Selection select_lines(const Buffer& buffer, const Selection& selection);