Add information of types of options
This commit is contained in:
parent
f1a93a0e61
commit
f73e89a716
|
@ -37,6 +37,18 @@
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct option_type_name<TimestampedList<LineAndFlag>>
|
||||||
|
{
|
||||||
|
static StringView name() { return "line-flags"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct option_type_name<TimestampedList<RangeAndFace>>
|
||||||
|
{
|
||||||
|
static StringView name() { return "range-faces"; }
|
||||||
|
};
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,8 @@ struct CharCoord : LineAndColumn<CharCoord, LineCount, CharCount>
|
||||||
[[gnu::always_inline]]
|
[[gnu::always_inline]]
|
||||||
constexpr CharCoord(LineCount line = 0, CharCount column = 0)
|
constexpr CharCoord(LineCount line = 0, CharCount column = 0)
|
||||||
: LineAndColumn(line, column) {}
|
: LineAndColumn(line, column) {}
|
||||||
|
|
||||||
|
static constexpr const char* option_type_name = "coord";
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ByteCoordAndTarget : ByteCoord
|
struct ByteCoordAndTarget : ByteCoord
|
||||||
|
|
|
@ -37,9 +37,19 @@ using InsertCompleterDescList = Vector<InsertCompleterDesc, MemoryDomain::Option
|
||||||
String option_to_string(const InsertCompleterDesc& opt);
|
String option_to_string(const InsertCompleterDesc& opt);
|
||||||
void option_from_string(StringView str, InsertCompleterDesc& opt);
|
void option_from_string(StringView str, InsertCompleterDesc& opt);
|
||||||
|
|
||||||
|
template<> struct option_type_name<InsertCompleterDesc>
|
||||||
|
{
|
||||||
|
static constexpr StringView name() { return "completer"; }
|
||||||
|
};
|
||||||
|
|
||||||
using CompletionCandidate = std::tuple<String, String, String>;
|
using CompletionCandidate = std::tuple<String, String, String>;
|
||||||
using CompletionList = PrefixedList<String, CompletionCandidate>;
|
using CompletionList = PrefixedList<String, CompletionCandidate>;
|
||||||
|
|
||||||
|
template<> struct option_type_name<CompletionList>
|
||||||
|
{
|
||||||
|
static constexpr StringView name() { return "completions"; }
|
||||||
|
};
|
||||||
|
|
||||||
struct InsertCompletion
|
struct InsertCompletion
|
||||||
{
|
{
|
||||||
struct Candidate
|
struct Candidate
|
||||||
|
|
|
@ -213,8 +213,8 @@ void register_options()
|
||||||
reg.declare_option<CharCoord, check_scrolloff>(
|
reg.declare_option<CharCoord, check_scrolloff>(
|
||||||
"scrolloff", "number of lines and columns to keep visible main cursor when scrolling",
|
"scrolloff", "number of lines and columns to keep visible main cursor when scrolling",
|
||||||
{0,0});
|
{0,0});
|
||||||
reg.declare_option("eolformat", "end of line format: crlf or lf", EolFormat::Lf);
|
reg.declare_option("eolformat", "end of line format", EolFormat::Lf);
|
||||||
reg.declare_option("BOM", "insert a byte order mark when writing buffer (none or utf8)",
|
reg.declare_option("BOM", "byte order mark to use when writing buffer",
|
||||||
ByteOrderMark::None);
|
ByteOrderMark::None);
|
||||||
reg.declare_option("incsearch",
|
reg.declare_option("incsearch",
|
||||||
"incrementaly apply search/select/split regex",
|
"incrementaly apply search/select/split regex",
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "vector.hh"
|
#include "vector.hh"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
@ -223,7 +224,7 @@ public:
|
||||||
return **it;
|
return **it;
|
||||||
throw runtime_error(format("option '{}' already declared with different type or flags", name));
|
throw runtime_error(format("option '{}' already declared with different type or flags", name));
|
||||||
}
|
}
|
||||||
m_descs.emplace_back(new OptionDesc{name.str(), docstring.str(), flags});
|
m_descs.emplace_back(new OptionDesc{name.str(), format("({}): {}", option_type_name<T>::name(), docstring), flags});
|
||||||
opts.emplace_back(new TypedCheckedOption<T, validator>{m_global_manager, *m_descs.back(), value});
|
opts.emplace_back(new TypedCheckedOption<T, validator>{m_global_manager, *m_descs.back(), value});
|
||||||
return *opts.back();
|
return *opts.back();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,25 @@
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
inline String option_to_string(StringView opt) { return opt.str(); }
|
template<typename T, typename = void> struct option_type_name;
|
||||||
inline void option_from_string(StringView str, String& opt) { opt = str.str(); }
|
template<typename T> using void_t = void;
|
||||||
inline bool option_add(String& opt, StringView val) { opt += val; return not val.empty(); }
|
|
||||||
|
template<typename T>
|
||||||
|
struct option_type_name<T, void_t<decltype(T::option_type_name)>>
|
||||||
|
{
|
||||||
|
static decltype(T::option_type_name) name() { return T::option_type_name; }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename Enum>
|
||||||
|
struct option_type_name<Enum, typename std::enable_if<std::is_enum<Enum>::value>::type>
|
||||||
|
{
|
||||||
|
static String name()
|
||||||
|
{
|
||||||
|
constexpr StringView type = WithBitOps<Enum>::value ? "flags" : "enum";
|
||||||
|
auto name = enum_desc(Enum{});
|
||||||
|
return type + "(" + join(name | transform([](const EnumDesc<Enum>& d) { return d.name; }), '|') + ")";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
inline String option_to_string(int opt) { return to_string(opt); }
|
inline String option_to_string(int opt) { return to_string(opt); }
|
||||||
inline void option_from_string(StringView str, int& opt) { opt = str_to_int(str); }
|
inline void option_from_string(StringView str, int& opt) { opt = str_to_int(str); }
|
||||||
|
@ -28,6 +44,7 @@ inline bool option_add(int& opt, StringView str)
|
||||||
opt += val;
|
opt += val;
|
||||||
return val != 0;
|
return val != 0;
|
||||||
}
|
}
|
||||||
|
template<> struct option_type_name<int> { static StringView name() { return "int"; } };
|
||||||
|
|
||||||
inline String option_to_string(size_t opt) { return to_string(opt); }
|
inline String option_to_string(size_t opt) { return to_string(opt); }
|
||||||
inline void option_from_string(StringView str, size_t& opt) { opt = str_to_int(str); }
|
inline void option_from_string(StringView str, size_t& opt) { opt = str_to_int(str); }
|
||||||
|
@ -42,6 +59,7 @@ inline void option_from_string(StringView str, bool& opt)
|
||||||
else
|
else
|
||||||
throw runtime_error("boolean values are either true, yes, false or no");
|
throw runtime_error("boolean values are either true, yes, false or no");
|
||||||
}
|
}
|
||||||
|
template<> struct option_type_name<bool> { static StringView name() { return "bool"; } };
|
||||||
|
|
||||||
constexpr char list_separator = ':';
|
constexpr char list_separator = ':';
|
||||||
|
|
||||||
|
@ -82,6 +100,12 @@ bool option_add(Vector<T, domain>& opt, StringView str)
|
||||||
return not vec.empty();
|
return not vec.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T, MemoryDomain D>
|
||||||
|
struct option_type_name<Vector<T, D>>
|
||||||
|
{
|
||||||
|
static String name() { return option_type_name<T>::name() + StringView{"-list"}; }
|
||||||
|
};
|
||||||
|
|
||||||
template<typename Value, MemoryDomain domain>
|
template<typename Value, MemoryDomain domain>
|
||||||
String option_to_string(const IdMap<Value, domain>& opt)
|
String option_to_string(const IdMap<Value, domain>& opt)
|
||||||
{
|
{
|
||||||
|
@ -114,6 +138,12 @@ void option_from_string(StringView str, IdMap<Value, domain>& opt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T, MemoryDomain D>
|
||||||
|
struct option_type_name<IdMap<T, D>>
|
||||||
|
{
|
||||||
|
static String name() { return format("str-to-{}-map", option_type_name<T>::name()); }
|
||||||
|
};
|
||||||
|
|
||||||
constexpr char tuple_separator = '|';
|
constexpr char tuple_separator = '|';
|
||||||
|
|
||||||
template<size_t I, typename... Types>
|
template<size_t I, typename... Types>
|
||||||
|
|
|
@ -31,6 +31,8 @@ struct Regex : RegexBase
|
||||||
|
|
||||||
const String& str() const { return m_str; }
|
const String& str() const { return m_str; }
|
||||||
|
|
||||||
|
static constexpr StringView option_type_name = "regex";
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String m_str;
|
String m_str;
|
||||||
};
|
};
|
||||||
|
|
|
@ -128,6 +128,7 @@ public:
|
||||||
void resize(ByteCount size, char c);
|
void resize(ByteCount size, char c);
|
||||||
|
|
||||||
static const String ms_empty;
|
static const String ms_empty;
|
||||||
|
static constexpr const char* option_type_name = "str";
|
||||||
|
|
||||||
union Data
|
union Data
|
||||||
{
|
{
|
||||||
|
@ -305,6 +306,10 @@ inline String operator"" _str(const char* str, size_t)
|
||||||
int str_to_int(StringView str); // throws on error
|
int str_to_int(StringView str); // throws on error
|
||||||
Optional<int> str_to_int_ifp(StringView str);
|
Optional<int> str_to_int_ifp(StringView str);
|
||||||
|
|
||||||
|
inline String option_to_string(StringView opt) { return opt.str(); }
|
||||||
|
inline void option_from_string(StringView str, String& opt) { opt = str.str(); }
|
||||||
|
inline bool option_add(String& opt, StringView val) { opt += val; return not val.empty(); }
|
||||||
|
|
||||||
template<size_t N>
|
template<size_t N>
|
||||||
struct InplaceString
|
struct InplaceString
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user