diff --git a/src/normal.cc b/src/normal.cc index f587a513..06f71a13 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -908,9 +908,9 @@ void select_object(Context& context, NormalParams params) return select(context, std::bind(sel.func, _1, _2, flags)); } - static const struct + static constexpr struct { - CodepointPair pair; + MatchingPair pair; Codepoint name; } surrounding_pairs[] = { { { '(', ')' }, 'b' }, @@ -923,7 +923,7 @@ void select_object(Context& context, NormalParams params) }; for (auto& sur : surrounding_pairs) { - if (sur.pair.first == c or sur.pair.second == c or + if (sur.pair.opening == c or sur.pair.closing == c or (sur.name != 0 and sur.name == c)) return select(context, std::bind(select_surrounding, _1, _2, sur.pair, level, flags)); diff --git a/src/selectors.cc b/src/selectors.cc index 781ea0e0..5d5b7d2e 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -81,12 +81,12 @@ Selection select_matching(const Buffer& buffer, const Selection& selection) static Optional find_surrounding(const Buffer& buffer, ByteCoord coord, - CodepointPair matching, + MatchingPair matching, ObjectFlags flags, int init_level) { const bool to_begin = flags & ObjectFlags::ToBegin; const bool to_end = flags & ObjectFlags::ToEnd; - const bool nestable = matching.first != matching.second; + const bool nestable = matching.opening != matching.closing; auto pos = buffer.iterator_at(coord); Utf8Iterator first = pos; if (to_begin) @@ -94,9 +94,9 @@ static Optional find_surrounding(const Buffer& buffer, int level = nestable ? init_level : 0; while (first != buffer.begin()) { - if (nestable and first != pos and *first == matching.second) + if (nestable and first != pos and *first == matching.closing) ++level; - else if (*first == matching.first) + else if (*first == matching.opening) { if (level == 0) break; @@ -105,7 +105,7 @@ static Optional find_surrounding(const Buffer& buffer, } --first; } - if (level != 0 or *first != matching.first) + if (level != 0 or *first != matching.opening) return Optional{}; } @@ -115,9 +115,9 @@ static Optional find_surrounding(const Buffer& buffer, int level = nestable ? init_level : 0; while (last != buffer.end()) { - if (nestable and last != pos and *last == matching.first) + if (nestable and last != pos and *last == matching.opening) ++level; - else if (*last == matching.second) + else if (*last == matching.closing) { if (level == 0) break; @@ -141,10 +141,10 @@ static Optional find_surrounding(const Buffer& buffer, } Selection select_surrounding(const Buffer& buffer, const Selection& selection, - CodepointPair matching, int level, + MatchingPair matching, int level, ObjectFlags flags) { - const bool nestable = matching.first != matching.second; + const bool nestable = matching.opening != matching.closing; auto pos = selection.cursor(); if (not nestable or flags & ObjectFlags::Inner) { @@ -154,8 +154,8 @@ Selection select_surrounding(const Buffer& buffer, const Selection& selection, } auto c = buffer.byte_at(pos); - if ((flags == ObjectFlags::ToBegin and c == matching.first) or - (flags == ObjectFlags::ToEnd and c == matching.second)) + if ((flags == ObjectFlags::ToBegin and c == matching.opening) or + (flags == ObjectFlags::ToEnd and c == matching.closing)) ++level; auto res = find_surrounding(buffer, pos, matching, flags, level); diff --git a/src/selectors.hh b/src/selectors.hh index 09ba45e1..cdd89dcb 100644 --- a/src/selectors.hh +++ b/src/selectors.hh @@ -296,9 +296,9 @@ void select_all_matches(SelectionList& selections, void split_selections(SelectionList& selections, const Regex& separator_regex); -using CodepointPair = std::pair; +struct MatchingPair { Codepoint opening, closing; }; Selection select_surrounding(const Buffer& buffer, const Selection& selection, - CodepointPair matching, int level, ObjectFlags flags); + MatchingPair matching, int level, ObjectFlags flags); }