Try to clean up option include a bit
This commit is contained in:
parent
7eaa058450
commit
5f7464d90d
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "clock.hh"
|
||||
#include "coord.hh"
|
||||
#include "enum.hh"
|
||||
#include "safe_ptr.hh"
|
||||
#include "scope.hh"
|
||||
#include "shared_string.hh"
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "buffer_utils.hh"
|
||||
#include "file.hh"
|
||||
#include "remote.hh"
|
||||
#include "option.hh"
|
||||
#include "client_manager.hh"
|
||||
#include "command_manager.hh"
|
||||
#include "event_manager.hh"
|
||||
|
|
|
@ -1339,6 +1339,7 @@ const CommandDesc declare_option_cmd = {
|
|||
auto docstring = parser.get_switch("docstring").value_or(StringView{}).str();
|
||||
OptionsRegistry& reg = GlobalScope::instance().option_registry();
|
||||
|
||||
|
||||
if (parser[0] == "int")
|
||||
opt = ®.declare_option<int>(parser[1], docstring, 0, flags);
|
||||
else if (parser[0] == "bool")
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "face_registry.hh"
|
||||
#include "highlighter_group.hh"
|
||||
#include "line_modification.hh"
|
||||
#include "option_types.hh"
|
||||
#include "option.hh"
|
||||
#include "parameters_parser.hh"
|
||||
#include "register_manager.hh"
|
||||
#include "regex.hh"
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "display_buffer.hh"
|
||||
#include "face_registry.hh"
|
||||
#include "regex.hh"
|
||||
#include "option.hh"
|
||||
|
||||
namespace Kakoune
|
||||
{
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define insert_completer_hh_INCLUDED
|
||||
|
||||
#include "option_manager.hh"
|
||||
#include "option.hh"
|
||||
#include "display_buffer.hh"
|
||||
#include "vector.hh"
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "assert.hh"
|
||||
#include "buffer.hh"
|
||||
#include "backtrace.hh"
|
||||
#include "buffer.hh"
|
||||
#include "buffer_manager.hh"
|
||||
#include "buffer_utils.hh"
|
||||
#include "client_manager.hh"
|
||||
|
@ -13,14 +13,15 @@
|
|||
#include "file.hh"
|
||||
#include "highlighters.hh"
|
||||
#include "insert_completer.hh"
|
||||
#include "shared_string.hh"
|
||||
#include "ncurses_ui.hh"
|
||||
#include "json_ui.hh"
|
||||
#include "ncurses_ui.hh"
|
||||
#include "option_types.hh"
|
||||
#include "parameters_parser.hh"
|
||||
#include "regex.hh"
|
||||
#include "register_manager.hh"
|
||||
#include "remote.hh"
|
||||
#include "regex.hh"
|
||||
#include "scope.hh"
|
||||
#include "shared_string.hh"
|
||||
#include "shell_manager.hh"
|
||||
#include "string.hh"
|
||||
#include "unit_tests.hh"
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
namespace Kakoune
|
||||
{
|
||||
namespace Meta
|
||||
inline namespace Meta
|
||||
{
|
||||
|
||||
template<typename T> struct Type {};
|
||||
|
|
59
src/option.hh
Normal file
59
src/option.hh
Normal file
|
@ -0,0 +1,59 @@
|
|||
#ifndef option_hh_INCLUDED
|
||||
#define option_hh_INCLUDED
|
||||
|
||||
#include "enum.hh"
|
||||
|
||||
namespace Kakoune
|
||||
{
|
||||
|
||||
class String;
|
||||
|
||||
// Forward declare functions that wont get found by ADL
|
||||
inline String option_to_string(int opt);
|
||||
inline String option_to_string(size_t opt);
|
||||
inline String option_to_string(bool opt);
|
||||
|
||||
template<typename P, typename T>
|
||||
struct PrefixedList
|
||||
{
|
||||
P prefix;
|
||||
Vector<T, MemoryDomain::Options> list;
|
||||
|
||||
friend bool operator==(const PrefixedList& lhs, const PrefixedList& rhs)
|
||||
{
|
||||
return lhs.prefix == rhs.prefix and lhs.list == rhs.list;
|
||||
}
|
||||
|
||||
friend bool operator!=(const PrefixedList& lhs, const PrefixedList& rhs)
|
||||
{
|
||||
return not (lhs == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
using TimestampedList = PrefixedList<size_t, T>;
|
||||
|
||||
enum class DebugFlags
|
||||
{
|
||||
None = 0,
|
||||
Hooks = 1 << 0,
|
||||
Shell = 1 << 1,
|
||||
Profile = 1 << 2,
|
||||
Keys = 1 << 3,
|
||||
};
|
||||
|
||||
constexpr bool with_bit_ops(Meta::Type<DebugFlags>) { return true; }
|
||||
|
||||
constexpr Array<EnumDesc<DebugFlags>, 4> enum_desc(Meta::Type<DebugFlags>)
|
||||
{
|
||||
return { {
|
||||
{ DebugFlags::Hooks, "hooks" },
|
||||
{ DebugFlags::Shell, "shell" },
|
||||
{ DebugFlags::Profile, "profile" },
|
||||
{ DebugFlags::Keys, "keys" }
|
||||
} };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // option_hh_INCLUDED
|
|
@ -4,8 +4,8 @@
|
|||
#include "completion.hh"
|
||||
#include "containers.hh"
|
||||
#include "exception.hh"
|
||||
#include "option_types.hh"
|
||||
#include "vector.hh"
|
||||
#include "option.hh"
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
#ifndef option_types_hh_INCLUDED
|
||||
#define option_types_hh_INCLUDED
|
||||
|
||||
#include "option.hh"
|
||||
#include "exception.hh"
|
||||
#include "string.hh"
|
||||
#include "units.hh"
|
||||
#include "coord.hh"
|
||||
#include "array_view.hh"
|
||||
#include "hash_map.hh"
|
||||
#include "flags.hh"
|
||||
#include "enum.hh"
|
||||
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
@ -39,7 +38,7 @@ inline bool option_add(int& opt, StringView str)
|
|||
opt += val;
|
||||
return val != 0;
|
||||
}
|
||||
inline StringView option_type_name(Meta::Type<int>) { return "int"; }
|
||||
constexpr StringView option_type_name(Meta::Type<int>) { 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); }
|
||||
|
@ -54,7 +53,7 @@ inline void option_from_string(StringView str, bool& opt)
|
|||
else
|
||||
throw runtime_error("boolean values are either true, yes, false or no");
|
||||
}
|
||||
inline StringView option_type_name(Meta::Type<bool>) { return "bool"; }
|
||||
constexpr StringView option_type_name(Meta::Type<bool>) { return "bool"; }
|
||||
|
||||
constexpr char list_separator = ':';
|
||||
|
||||
|
@ -233,27 +232,6 @@ inline String option_to_string(const LineAndColumn<EffectiveType, LineType, Colu
|
|||
return format("{},{}", opt.line, opt.column);
|
||||
}
|
||||
|
||||
enum class DebugFlags
|
||||
{
|
||||
None = 0,
|
||||
Hooks = 1 << 0,
|
||||
Shell = 1 << 1,
|
||||
Profile = 1 << 2,
|
||||
Keys = 1 << 3,
|
||||
};
|
||||
|
||||
constexpr bool with_bit_ops(Meta::Type<DebugFlags>) { return true; }
|
||||
|
||||
constexpr Array<EnumDesc<DebugFlags>, 4> enum_desc(Meta::Type<DebugFlags>)
|
||||
{
|
||||
return { {
|
||||
{ DebugFlags::Hooks, "hooks" },
|
||||
{ DebugFlags::Shell, "shell" },
|
||||
{ DebugFlags::Profile, "profile" },
|
||||
{ DebugFlags::Keys, "keys" }
|
||||
} };
|
||||
}
|
||||
|
||||
template<typename Flags, typename = decltype(enum_desc(Meta::Type<Flags>{}))>
|
||||
EnableIfWithBitOps<Flags, String> option_to_string(Flags flags)
|
||||
{
|
||||
|
@ -314,25 +292,6 @@ EnableIfWithBitOps<Flags, bool> option_add(Flags& opt, StringView str)
|
|||
return res != (Flags)0;
|
||||
}
|
||||
|
||||
template<typename P, typename T>
|
||||
struct PrefixedList
|
||||
{
|
||||
P prefix;
|
||||
Vector<T, MemoryDomain::Options> list;
|
||||
};
|
||||
|
||||
template<typename P, typename T>
|
||||
inline bool operator==(const PrefixedList<P, T>& lhs, const PrefixedList<P, T>& rhs)
|
||||
{
|
||||
return lhs.prefix == rhs.prefix and lhs.list == rhs.list;
|
||||
}
|
||||
|
||||
template<typename P, typename T>
|
||||
inline bool operator!=(const PrefixedList<P, T>& lhs, const PrefixedList<P, T>& rhs)
|
||||
{
|
||||
return not (lhs == rhs);
|
||||
}
|
||||
|
||||
template<typename P, typename T>
|
||||
inline String option_to_string(const PrefixedList<P, T>& opt)
|
||||
{
|
||||
|
@ -354,9 +313,6 @@ inline bool option_add(PrefixedList<P, T>& opt, StringView str)
|
|||
return option_add(opt.list, str);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
using TimestampedList = PrefixedList<size_t, T>;
|
||||
|
||||
}
|
||||
|
||||
#endif // option_types_hh_INCLUDED
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "face_registry.hh"
|
||||
#include "file.hh"
|
||||
#include "flags.hh"
|
||||
#include "option.hh"
|
||||
#include "regex.hh"
|
||||
|
||||
#include <cstring>
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "input_handler.hh"
|
||||
#include "client.hh"
|
||||
#include "buffer_utils.hh"
|
||||
#include "option.hh"
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
|
|
Loading…
Reference in New Issue
Block a user