summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-11-19 21:58:26 +0000
committerMaxime Coste <frrrwww@gmail.com>2015-11-19 21:58:26 +0000
commitc0f1b7b99f6b882e9622f41e1ff05f927210ce90 (patch)
treed72affe9da79800b5e6686d1f558a5823c5b9c8e
parentb67d593551b21547630bbd08372278c36d14f413 (diff)
Introduce a debug flags option to control some tracing
Support shell|hooks and write traces in debug buffer
-rw-r--r--src/hook_manager.cc5
-rw-r--r--src/main.cc1
-rw-r--r--src/option_types.hh88
-rw-r--r--src/shell_manager.cc3
4 files changed, 70 insertions, 27 deletions
diff --git a/src/hook_manager.cc b/src/hook_manager.cc
index 49a09f3b..1dda5043 100644
--- a/src/hook_manager.cc
+++ b/src/hook_manager.cc
@@ -49,6 +49,8 @@ void HookManager::run_hook(StringView hook_name,
if (hook_list_it == m_hook.end())
return;
+ const bool trace = context.options()["debug"].get<DebugFlags>() & DebugFlags::Hooks;
+
auto& disabled_hooks = context.options()["disabled_hooks"].get<Regex>();
bool hook_error = false;
for (auto& hook : hook_list_it->value)
@@ -59,6 +61,9 @@ void HookManager::run_hook(StringView hook_name,
try
{
+ if (trace)
+ write_to_debug_buffer(format("hook {}/{}", hook_name, hook.key));
+
hook.value(param, context);
}
catch (runtime_error& err)
diff --git a/src/main.cc b/src/main.cc
index 182f0c5f..5dc3d854 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -240,6 +240,7 @@ void register_options()
UserInterface::Options{});
reg.declare_option("modelinefmt", "format string used to generate the modeline",
"%val{bufname} %val{cursor_line}:%val{cursor_char_column} "_str);
+ reg.declare_option("debug", "various debug flags", DebugFlags::None);
}
struct convert_to_client_mode
diff --git a/src/option_types.hh b/src/option_types.hh
index bcfb4e1d..2dda3d7e 100644
--- a/src/option_types.hh
+++ b/src/option_types.hh
@@ -223,24 +223,15 @@ inline void option_from_string(StringView str, YesNoAsk& opt)
throw runtime_error(format("invalid value '{}', expected yes, no or ask", str));
}
-enum class AutoInfo
-{
- None = 0,
- Command = 1 << 0,
- OnKey = 1 << 1,
- Normal = 1 << 2
-};
-
-template<>
-struct WithBitOps<AutoInfo> : std::true_type {};
-
-constexpr AutoInfo autoinfo_values[] = { AutoInfo::Command, AutoInfo::OnKey, AutoInfo::Normal };
-constexpr StringView autoinfo_names[] = { "command", "onkey", "normal" };
+template<typename T> struct EnumInfo;
-template<typename Flags, typename = EnableIfWithBitOps<Flags>>
-String to_string(Flags flags, ArrayView<const Flags> values, ArrayView<const StringView> names)
+template<typename Flags,
+ typename = EnableIfWithBitOps<Flags>,
+ typename = decltype(EnumInfo<Flags>::values(), EnumInfo<Flags>::names())>
+String option_to_string(Flags flags)
{
- kak_assert(values.size() == names.size());
+ auto names = EnumInfo<Flags>::names();
+ auto values = EnumInfo<Flags>::values();
String res;
for (int i = 0; i < values.size(); ++i)
{
@@ -253,11 +244,14 @@ String to_string(Flags flags, ArrayView<const Flags> values, ArrayView<const Str
return res;
}
-template<typename Flags, typename = EnableIfWithBitOps<Flags>>
-Flags string_to_flags(StringView str, ArrayView<const Flags> values, ArrayView<const StringView> names)
+template<typename Flags,
+ typename = EnableIfWithBitOps<Flags>,
+ typename = decltype(EnumInfo<Flags>::values(), EnumInfo<Flags>::names())>
+void option_from_string(StringView str, Flags& flags)
{
- kak_assert(values.size() == names.size());
- Flags flags{};
+ auto names = EnumInfo<Flags>::names();
+ auto values = EnumInfo<Flags>::values();
+ flags = Flags{};
for (auto s : split(str, '|'))
{
auto it = std::find(names.begin(), names.end(), s);
@@ -265,18 +259,58 @@ Flags string_to_flags(StringView str, ArrayView<const Flags> values, ArrayView<c
throw runtime_error(format("invalid flag value '{}'", s));
flags |= values[it - names.begin()];
}
- return flags;
}
-inline String option_to_string(AutoInfo opt)
+enum class AutoInfo
{
- return to_string<AutoInfo>(opt, autoinfo_values, autoinfo_names);
-}
+ None = 0,
+ Command = 1 << 0,
+ OnKey = 1 << 1,
+ Normal = 1 << 2
+};
+
+template<>
+struct WithBitOps<AutoInfo> : std::true_type {};
-inline void option_from_string(StringView str, AutoInfo& opt)
+template<> struct EnumInfo<AutoInfo>
{
- opt = string_to_flags<AutoInfo>(str, autoinfo_values, autoinfo_names);
-}
+ static ArrayView<const AutoInfo> values()
+ {
+ static constexpr AutoInfo values[] = { AutoInfo::Command, AutoInfo::OnKey, AutoInfo::Normal };
+ return { values };
+ }
+
+ static ArrayView<const StringView> names()
+ {
+ static constexpr StringView names[] = { "command", "onkey", "normal" };
+ return { names };
+ }
+};
+
+enum class DebugFlags
+{
+ None = 0,
+ Hooks = 1 << 0,
+ Shell = 1 << 1,
+};
+
+template<>
+struct WithBitOps<DebugFlags> : std::true_type {};
+
+template<> struct EnumInfo<DebugFlags>
+{
+ static ArrayView<const DebugFlags> values()
+ {
+ static constexpr DebugFlags values[] = { DebugFlags::Hooks, DebugFlags::Shell };
+ return { values };
+ }
+
+ static ArrayView<const StringView> names()
+ {
+ static constexpr StringView names[] = { "hooks", "shell" };
+ return { names };
+ }
+};
}
diff --git a/src/shell_manager.cc b/src/shell_manager.cc
index 6ac02d65..f23725a1 100644
--- a/src/shell_manager.cc
+++ b/src/shell_manager.cc
@@ -87,6 +87,9 @@ std::pair<String, int> ShellManager::eval(
{
static const Regex re(R"(\bkak_(\w+)\b)");
+ if (context.options()["debug"].get<DebugFlags>() & DebugFlags::Shell)
+ write_to_debug_buffer(format("shell:\n{}\n----\n", cmdline));
+
Vector<String> kak_env;
for (RegexIterator<const char*> it{cmdline.begin(), cmdline.end(), re}, end;
it != end; ++it)