summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2020-10-19 20:06:25 +1100
committerMaxime Coste <mawww@kakoune.org>2020-10-19 20:06:25 +1100
commitdef37a6ff45b310e65fd7dd80b3cb398d5eb614a (patch)
tree697c993ec6ace0df94e8b1b4f4e75bc29b414329 /src
parentf549190a988bb91f5d4a79b3f9bba5eac029da73 (diff)
parent4aabe33a240a349979cac60dca78226451172ccb (diff)
Merge remote-tracking branch 'm-kru/vhdl' into master
Diffstat (limited to 'src')
-rw-r--r--src/highlighters.cc3
-rw-r--r--src/insert_completer.cc120
2 files changed, 61 insertions, 62 deletions
diff --git a/src/highlighters.cc b/src/highlighters.cc
index 78099b08..309ade94 100644
--- a/src/highlighters.cc
+++ b/src/highlighters.cc
@@ -1744,7 +1744,8 @@ void insert_matches(const Buffer& buffer, RegexMatchList& matches, const Regex&
for (auto line = range.begin; line < range.end; ++line)
{
const StringView l = buffer[line];
- for (auto&& m : RegexIterator{l.begin(), l.end(), vm})
+ const auto flags = RegexExecFlags::NotEndOfLine; // buffer line already ends with \n
+ for (auto&& m : RegexIterator{l.begin(), l.end(), vm, flags})
{
const bool with_capture = capture and m[1].matched and
m[0].second - m[0].first < std::numeric_limits<uint16_t>::max();
diff --git a/src/insert_completer.cc b/src/insert_completer.cc
index 94c1a95e..03ce45a5 100644
--- a/src/insert_completer.cc
+++ b/src/insert_completer.cc
@@ -261,76 +261,74 @@ InsertCompletion complete_option(const SelectionList& sels,
auto& desc = opt.prefix;
static const Regex re(R"((\d+)\.(\d+)(?:\+(\d+))?@(\d+))");
MatchResults<String::const_iterator> match;
- if (regex_match(desc.begin(), desc.end(), match, re))
- {
- BufferCoord coord{ str_to_int({match[1].first, match[1].second}) - 1,
- str_to_int({match[2].first, match[2].second}) - 1 };
- if (not buffer.is_valid(coord))
- return {};
- size_t timestamp = (size_t)str_to_int({match[4].first, match[4].second});
- auto changes = buffer.changes_since(timestamp);
- if (any_of(changes, [&](auto&& change) { return change.begin < coord; }))
- return {};
-
- if (cursor_pos.line == coord.line and cursor_pos.column >= coord.column)
- {
- StringView query = buffer.substr(coord, cursor_pos);
+ if (not regex_match(desc.begin(), desc.end(), match, re))
+ return {};
- const ColumnCount tabstop = options["tabstop"].get<int>();
- const ColumnCount column = get_column(buffer, tabstop, cursor_pos);
+ BufferCoord coord{str_to_int({match[1].first, match[1].second}) - 1,
+ str_to_int({match[2].first, match[2].second}) - 1};
+ if (not buffer.is_valid(coord))
+ return {};
+ size_t timestamp = (size_t)str_to_int({match[4].first, match[4].second});
+ auto changes = buffer.changes_since(timestamp);
+ if (any_of(changes, [&](auto&& change) { return change.begin < coord; }))
+ return {};
- struct RankedMatchAndInfo : RankedMatch
- {
- using RankedMatch::RankedMatch;
- using RankedMatch::operator==;
- using RankedMatch::operator<;
+ if (cursor_pos.line != coord.line or cursor_pos.column < coord.column)
+ return {};
- StringView on_select;
- DisplayLine menu_entry;
- };
+ const ColumnCount tabstop = options["tabstop"].get<int>();
+ const ColumnCount column = get_column(buffer, tabstop, cursor_pos);
- Vector<RankedMatchAndInfo> matches;
+ struct RankedMatchAndInfo : RankedMatch
+ {
+ using RankedMatch::RankedMatch;
+ using RankedMatch::operator==;
+ using RankedMatch::operator<;
- for (auto& candidate : opt.list)
- {
- if (RankedMatchAndInfo match{std::get<0>(candidate), query})
- {
- match.on_select = std::get<1>(candidate);
- auto& menu = std::get<2>(candidate);
- match.menu_entry = not menu.empty() ?
- parse_display_line(expand_tabs(menu, tabstop, column), faces)
- : DisplayLine{ expand_tabs(menu, tabstop, column), {} };
-
- matches.push_back(std::move(match));
- }
- }
+ StringView on_select;
+ DisplayLine menu_entry;
+ };
- constexpr size_t max_count = 100;
- // Gather best max_count matches
- auto greater = [](auto& lhs, auto& rhs) { return rhs < lhs; };
- auto first = matches.begin(), last = matches.end();
- std::make_heap(first, last, greater);
- InsertCompletion::CandidateList candidates;
- candidates.reserve(std::min(matches.size(), max_count));
- candidates.reserve(matches.size());
- while (candidates.size() < max_count and first != last)
- {
- if (candidates.empty() or candidates.back().completion != first->candidate())
- candidates.push_back({ first->candidate().str(), first->on_select.str(),
- std::move(first->menu_entry) });
- std::pop_heap(first, last--, greater);
- }
+ StringView query = buffer.substr(coord, cursor_pos);
+ Vector<RankedMatchAndInfo> matches;
- auto end = cursor_pos;
- if (match[3].matched)
- {
- ByteCount len = str_to_int({match[3].first, match[3].second});
- end = buffer.advance(coord, len);
- }
- return { std::move(candidates), coord, end, timestamp };
+ for (auto& candidate : opt.list)
+ {
+ if (RankedMatchAndInfo match{std::get<0>(candidate), query})
+ {
+ match.on_select = std::get<1>(candidate);
+ auto& menu = std::get<2>(candidate);
+ match.menu_entry = not menu.empty() ?
+ parse_display_line(expand_tabs(menu, tabstop, column), faces)
+ : DisplayLine{String{}, {}};
+
+ matches.push_back(std::move(match));
}
}
- return {};
+
+ constexpr size_t max_count = 100;
+ // Gather best max_count matches
+ auto greater = [](auto& lhs, auto& rhs) { return rhs < lhs; };
+ auto first = matches.begin(), last = matches.end();
+ std::make_heap(first, last, greater);
+ InsertCompletion::CandidateList candidates;
+ candidates.reserve(std::min(matches.size(), max_count));
+ candidates.reserve(matches.size());
+ while (candidates.size() < max_count and first != last)
+ {
+ if (candidates.empty() or candidates.back().completion != first->candidate())
+ candidates.push_back({ first->candidate().str(), first->on_select.str(),
+ std::move(first->menu_entry) });
+ std::pop_heap(first, last--, greater);
+ }
+
+ auto end = cursor_pos;
+ if (match[3].matched)
+ {
+ ByteCount len = str_to_int({match[3].first, match[3].second});
+ end = buffer.advance(coord, len);
+ }
+ return { std::move(candidates), coord, end, timestamp };
}
template<bool other_buffers>