From c1615b5c15d64b746ff7d4080da43a8d659576ca Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 6 May 2013 13:52:20 +0200 Subject: [PATCH] add unordered_set option support, use it for completers --- src/input_handler.cc | 2 +- src/option_manager.cc | 2 +- src/option_types.hh | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/input_handler.cc b/src/input_handler.cc index 176fa975..01a8e471 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -664,7 +664,7 @@ private: { if (not m_completions.is_valid()) { - auto& completers = options()["completers"].get>(); + auto& completers = options()["completers"].get>(); BufferIterator cursor = m_context.editor().main_selection().last(); if (contains(completers, "option")) m_completions = complete_opt(cursor, m_context.options()); diff --git a/src/option_manager.cc b/src/option_manager.cc index 63a6a7a5..68e65710 100644 --- a/src/option_manager.cc +++ b/src/option_manager.cc @@ -119,7 +119,7 @@ GlobalOptions::GlobalOptions() declare_option("filetype", ""); declare_option>("completions", {}); declare_option>("path", { "./", "/usr/include" }); - declare_option>("completers", {"option", "word"}); + declare_option>("completers", {"option", "word"}); declare_option("insert_hide_sel", false); } diff --git a/src/option_types.hh b/src/option_types.hh index e44b3f0d..121b8f56 100644 --- a/src/option_types.hh +++ b/src/option_types.hh @@ -7,6 +7,7 @@ #include #include +#include namespace Kakoune { @@ -64,6 +65,39 @@ bool option_add(std::vector& opt, const std::vector& vec) return not vec.empty(); } +template +String option_to_string(const std::unordered_set& opt) +{ + String res; + for (auto it = begin(opt); it != end(opt); ++it) + { + if (it != begin(opt)) + res += list_separator; + res += option_to_string(*it); + } + return res; +} + +template +void option_from_string(const String& str, std::unordered_set& opt) +{ + opt.clear(); + std::vector elems = split(str, list_separator); + for (auto& elem: elems) + { + T opt_elem; + option_from_string(elem, opt_elem); + opt.insert(opt_elem); + } +} + +template +bool option_add(std::unordered_set& opt, const std::unordered_set& set) +{ + std::copy(set.begin(), set.end(), std::inserter(opt, opt.begin())); + return not set.empty(); +} + constexpr Codepoint tuple_separator = '|'; template @@ -124,7 +158,8 @@ template inline bool option_add(StronglyTypedNumber& opt, StronglyTypedNumber val) { - opt += val; return val != 0; + opt += val; + return val != 0; } template