Add information of types of options
This commit is contained in:
parent
f1a93a0e61
commit
f73e89a716
|
@ -37,6 +37,18 @@
|
|||
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
|
||||
{
|
||||
|
||||
|
|
|
@ -103,6 +103,8 @@ struct CharCoord : LineAndColumn<CharCoord, LineCount, CharCount>
|
|||
[[gnu::always_inline]]
|
||||
constexpr CharCoord(LineCount line = 0, CharCount column = 0)
|
||||
: LineAndColumn(line, column) {}
|
||||
|
||||
static constexpr const char* option_type_name = "coord";
|
||||
};
|
||||
|
||||
struct ByteCoordAndTarget : ByteCoord
|
||||
|
|
|
@ -37,9 +37,19 @@ using InsertCompleterDescList = Vector<InsertCompleterDesc, MemoryDomain::Option
|
|||
String option_to_string(const 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 CompletionList = PrefixedList<String, CompletionCandidate>;
|
||||
|
||||
template<> struct option_type_name<CompletionList>
|
||||
{
|
||||
static constexpr StringView name() { return "completions"; }
|
||||
};
|
||||
|
||||
struct InsertCompletion
|
||||
{
|
||||
struct Candidate
|
||||
|
|
|
@ -213,8 +213,8 @@ void register_options()
|
|||
reg.declare_option<CharCoord, check_scrolloff>(
|
||||
"scrolloff", "number of lines and columns to keep visible main cursor when scrolling",
|
||||
{0,0});
|
||||
reg.declare_option("eolformat", "end of line format: crlf or lf", EolFormat::Lf);
|
||||
reg.declare_option("BOM", "insert a byte order mark when writing buffer (none or utf8)",
|
||||
reg.declare_option("eolformat", "end of line format", EolFormat::Lf);
|
||||
reg.declare_option("BOM", "byte order mark to use when writing buffer",
|
||||
ByteOrderMark::None);
|
||||
reg.declare_option("incsearch",
|
||||
"incrementaly apply search/select/split regex",
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "vector.hh"
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Kakoune
|
||||
{
|
||||
|
@ -223,7 +224,7 @@ public:
|
|||
return **it;
|
||||
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});
|
||||
return *opts.back();
|
||||
}
|
||||
|
|
|
@ -16,9 +16,25 @@
|
|||
namespace Kakoune
|
||||
{
|
||||
|
||||
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<typename T, typename = void> struct option_type_name;
|
||||
template<typename T> using void_t = void;
|
||||
|
||||
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 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;
|
||||
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 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
|
||||
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 = ':';
|
||||
|
||||
|
@ -82,6 +100,12 @@ bool option_add(Vector<T, domain>& opt, StringView str)
|
|||
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>
|
||||
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 = '|';
|
||||
|
||||
template<size_t I, typename... Types>
|
||||
|
|
|
@ -31,6 +31,8 @@ struct Regex : RegexBase
|
|||
|
||||
const String& str() const { return m_str; }
|
||||
|
||||
static constexpr StringView option_type_name = "regex";
|
||||
|
||||
private:
|
||||
String m_str;
|
||||
};
|
||||
|
|
|
@ -128,6 +128,7 @@ public:
|
|||
void resize(ByteCount size, char c);
|
||||
|
||||
static const String ms_empty;
|
||||
static constexpr const char* option_type_name = "str";
|
||||
|
||||
union Data
|
||||
{
|
||||
|
@ -305,6 +306,10 @@ inline String operator"" _str(const char* str, size_t)
|
|||
int str_to_int(StringView str); // throws on error
|
||||
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>
|
||||
struct InplaceString
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user