summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-09-26 23:32:07 +0100
committerMaxime Coste <frrrwww@gmail.com>2016-09-26 23:32:07 +0100
commitfcb37cc7541cfa2152f8c0aed6eda177bc9770a6 (patch)
treefcc05344434344010401c62928e889289a5a43bd /src
parent1e0ec182c166da505ad1404fcbf80240a3797ae4 (diff)
Pass count to all object selectors
Diffstat (limited to 'src')
-rw-r--r--src/normal.cc20
-rw-r--r--src/selectors.cc10
-rw-r--r--src/selectors.hh33
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<Word> },
{ 'W', select_word<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<mode>(context, std::bind(sel.func, _1, _2, flags));
+ return select<mode>(context, std::bind(sel.func, _1, _2, count, flags));
}
- if (cp == 'u')
- return select<mode>(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 <open>,<close>"};
return select<mode>(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<mode>(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<mode>(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<ObjectFlags> : std::true_type {};
template<WordType word_type>
-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);