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 complete_word(const BufferIterat return { std::move(result), begin }; } +static std::pair complete_opt(const BufferIterator& pos, OptionManager& options) +{ + using StringList = std::vector; + const StringList& opt = options["completions"].get(); + if (opt.empty()) + return { {}, pos }; + + auto& desc = opt[0]; + Regex re(R"((\d+):(\d+)@(\d+))"); + boost::match_results 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; diff --git a/src/option_manager.cc b/src/option_manager.cc index 9471f03c..76475ab9 100644 --- a/src/option_manager.cc +++ b/src/option_manager.cc @@ -121,6 +121,9 @@ template void Option::set(const bool&); template const std::vector& Option::get>() const; template void Option::set>(const std::vector&); +template const std::vector& Option::get>() const; +template void Option::set>(const std::vector&); + OptionManager::OptionManager(OptionManager& parent) : m_parent(&parent) { @@ -235,6 +238,7 @@ GlobalOptions::GlobalOptions() declare_option("incsearch", true); declare_option("ignored_files", R"(^(\..*|.*\.(o|so|a))$)"); declare_option("filetype", ""); + declare_option>("completions", {}); } template