summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2017-03-16 09:57:39 +0000
committerMaxime Coste <mawww@kakoune.org>2017-03-16 09:57:39 +0000
commit5f7464d90d0bfe641dd2c7bbbca6e78d92d9d818 (patch)
tree2f83259b53104545893c7e59f7a96d04e037278e /src
parent7eaa05845043420c8f8c58932667b71b6784714a (diff)
Try to clean up option include a bit
Diffstat (limited to 'src')
-rw-r--r--src/buffer.hh1
-rw-r--r--src/client.cc1
-rw-r--r--src/commands.cc1
-rw-r--r--src/highlighters.cc2
-rw-r--r--src/hook_manager.cc1
-rw-r--r--src/insert_completer.hh1
-rw-r--r--src/main.cc9
-rw-r--r--src/meta.hh2
-rw-r--r--src/option.hh59
-rw-r--r--src/option_manager.hh2
-rw-r--r--src/option_types.hh50
-rw-r--r--src/shell_manager.cc1
-rw-r--r--src/window.cc1
13 files changed, 77 insertions, 54 deletions
diff --git a/src/buffer.hh b/src/buffer.hh
index 7e4b54be..6393dc17 100644
--- a/src/buffer.hh
+++ b/src/buffer.hh
@@ -3,6 +3,7 @@
#include "clock.hh"
#include "coord.hh"
+#include "enum.hh"
#include "safe_ptr.hh"
#include "scope.hh"
#include "shared_string.hh"
diff --git a/src/client.cc b/src/client.cc
index e9da59ff..3ce8436d 100644
--- a/src/client.cc
+++ b/src/client.cc
@@ -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"
diff --git a/src/commands.cc b/src/commands.cc
index a57e8031..ec8cd6ca 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -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 = &reg.declare_option<int>(parser[1], docstring, 0, flags);
else if (parser[0] == "bool")
diff --git a/src/highlighters.cc b/src/highlighters.cc
index 8fef89ca..e68f2088 100644
--- a/src/highlighters.cc
+++ b/src/highlighters.cc
@@ -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"
diff --git a/src/hook_manager.cc b/src/hook_manager.cc
index a5f2f7e0..ad30c350 100644
--- a/src/hook_manager.cc
+++ b/src/hook_manager.cc
@@ -7,6 +7,7 @@
#include "display_buffer.hh"
#include "face_registry.hh"
#include "regex.hh"
+#include "option.hh"
namespace Kakoune
{
diff --git a/src/insert_completer.hh b/src/insert_completer.hh
index d7061c37..b0bd13ef 100644
--- a/src/insert_completer.hh
+++ b/src/insert_completer.hh
@@ -2,6 +2,7 @@
#define insert_completer_hh_INCLUDED
#include "option_manager.hh"
+#include "option.hh"
#include "display_buffer.hh"
#include "vector.hh"
diff --git a/src/main.cc b/src/main.cc
index 426e7809..2c6b996d 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -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"
diff --git a/src/meta.hh b/src/meta.hh
index 32f28dbb..768556eb 100644
--- a/src/meta.hh
+++ b/src/meta.hh
@@ -3,7 +3,7 @@
namespace Kakoune
{
-namespace Meta
+inline namespace Meta
{
template<typename T> struct Type {};
diff --git a/src/option.hh b/src/option.hh
new file mode 100644
index 00000000..c54de083
--- /dev/null
+++ b/src/option.hh
@@ -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
diff --git a/src/option_manager.hh b/src/option_manager.hh
index b20303b0..e19ae44a 100644
--- a/src/option_manager.hh
+++ b/src/option_manager.hh
@@ -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>
diff --git a/src/option_types.hh b/src/option_types.hh
index 0193c821..ec7796f6 100644
--- a/src/option_types.hh
+++ b/src/option_types.hh
@@ -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)
{
@@ -315,25 +293,6 @@ EnableIfWithBitOps<Flags, bool> option_add(Flags& opt, StringView str)
}
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)
{
return format("{}:{}", opt.prefix, option_to_string(opt.list));
@@ -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
diff --git a/src/shell_manager.cc b/src/shell_manager.cc
index 78147d76..ad7f18ed 100644
--- a/src/shell_manager.cc
+++ b/src/shell_manager.cc
@@ -8,6 +8,7 @@
#include "face_registry.hh"
#include "file.hh"
#include "flags.hh"
+#include "option.hh"
#include "regex.hh"
#include <cstring>
diff --git a/src/window.cc b/src/window.cc
index fc099c45..3ba1a8ee 100644
--- a/src/window.cc
+++ b/src/window.cc
@@ -8,6 +8,7 @@
#include "input_handler.hh"
#include "client.hh"
#include "buffer_utils.hh"
+#include "option.hh"
#include <algorithm>
#include <sstream>