add unordered_set option support, use it for completers

This commit is contained in:
Maxime Coste 2013-05-06 13:52:20 +02:00
parent 2342e7686f
commit c1615b5c15
3 changed files with 38 additions and 3 deletions

View File

@ -664,7 +664,7 @@ private:
{ {
if (not m_completions.is_valid()) if (not m_completions.is_valid())
{ {
auto& completers = options()["completers"].get<std::vector<String>>(); auto& completers = options()["completers"].get<std::unordered_set<String>>();
BufferIterator cursor = m_context.editor().main_selection().last(); BufferIterator cursor = m_context.editor().main_selection().last();
if (contains(completers, "option")) if (contains(completers, "option"))
m_completions = complete_opt(cursor, m_context.options()); m_completions = complete_opt(cursor, m_context.options());

View File

@ -119,7 +119,7 @@ GlobalOptions::GlobalOptions()
declare_option<String>("filetype", ""); declare_option<String>("filetype", "");
declare_option<std::vector<String>>("completions", {}); declare_option<std::vector<String>>("completions", {});
declare_option<std::vector<String>>("path", { "./", "/usr/include" }); declare_option<std::vector<String>>("path", { "./", "/usr/include" });
declare_option<std::vector<String>>("completers", {"option", "word"}); declare_option<std::unordered_set<String>>("completers", {"option", "word"});
declare_option<bool>("insert_hide_sel", false); declare_option<bool>("insert_hide_sel", false);
} }

View File

@ -7,6 +7,7 @@
#include <tuple> #include <tuple>
#include <vector> #include <vector>
#include <unordered_set>
namespace Kakoune namespace Kakoune
{ {
@ -64,6 +65,39 @@ bool option_add(std::vector<T>& opt, const std::vector<T>& vec)
return not vec.empty(); return not vec.empty();
} }
template<typename T>
String option_to_string(const std::unordered_set<T>& 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<typename T>
void option_from_string(const String& str, std::unordered_set<T>& opt)
{
opt.clear();
std::vector<String> elems = split(str, list_separator);
for (auto& elem: elems)
{
T opt_elem;
option_from_string(elem, opt_elem);
opt.insert(opt_elem);
}
}
template<typename T>
bool option_add(std::unordered_set<T>& opt, const std::unordered_set<T>& set)
{
std::copy(set.begin(), set.end(), std::inserter(opt, opt.begin()));
return not set.empty();
}
constexpr Codepoint tuple_separator = '|'; constexpr Codepoint tuple_separator = '|';
template<size_t I, typename... Types> template<size_t I, typename... Types>
@ -124,7 +158,8 @@ template<typename RealType, typename ValueType = int>
inline bool option_add(StronglyTypedNumber<RealType, ValueType>& opt, inline bool option_add(StronglyTypedNumber<RealType, ValueType>& opt,
StronglyTypedNumber<RealType, ValueType> val) StronglyTypedNumber<RealType, ValueType> val)
{ {
opt += val; return val != 0; opt += val;
return val != 0;
} }
template<typename T> template<typename T>