diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2013-03-09 14:23:19 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2013-03-11 14:20:28 +0100 |
| commit | ddc894ccfe9794c941aa243703d00090453cefdd (patch) | |
| tree | e623ea833db739ff93e665c439f30ef8a8c6f9e9 /src/input_handler.cc | |
| parent | 4db6e3e9170bb3c5b14af145b7dbf6a751aff663 (diff) | |
Add an experimental configurable input completion fonction
The completions option (a std::vector<String>) is used for
completions candidates, if it's first element matches the current
cursor position and buffer timestamp.
Diffstat (limited to 'src/input_handler.cc')
| -rw-r--r-- | src/input_handler.cc | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc index 6dc3f17a..2513991e 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -482,6 +482,28 @@ static std::pair<CandidateList, BufferIterator> complete_word(const BufferIterat return { std::move(result), begin }; } +static std::pair<CandidateList, BufferIterator> complete_opt(const BufferIterator& pos, OptionManager& options) +{ + using StringList = std::vector<String>; + const StringList& opt = options["completions"].get<StringList>(); + if (opt.empty()) + return { {}, pos }; + + auto& desc = opt[0]; + Regex re(R"((\d+):(\d+)@(\d+))"); + boost::match_results<String::iterator> match; + if (boost::regex_match(desc.begin(), desc.end(), match, re)) + { + LineCount line = str_to_int(String(match[1].first, match[1].second)) - 1; + ByteCount column = str_to_int(String(match[2].first, match[2].second)) - 1; + int timestamp = str_to_int(String(match[3].first, match[3].second)); + + if (timestamp == pos.buffer().timestamp() and line == pos.line() and column == pos.column()) + return { { opt.begin() + 1, opt.end() }, pos }; + } + return { {}, pos }; +} + class BufferCompleter { public: @@ -507,7 +529,9 @@ private: if (not m_position.is_valid()) { BufferIterator cursor = context.editor().selections().back().last(); - auto completions = complete_word(cursor); + auto completions = complete_opt(cursor, context.options()); + if (completions.first.empty()) + completions = complete_word(cursor); m_completions = std::move(completions.first); if (m_completions.empty()) return false; |
