From edd883ad18d8b56f0a57d4a20e1de6e5c0141797 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 21 Jun 2014 12:08:19 +0100 Subject: [PATCH] Only user hooks can be disabled --- src/commands.cc | 7 +++++-- src/hook_manager.cc | 5 +---- src/hook_manager.hh | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index 327c9986..9b19e053 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -519,6 +519,9 @@ const CommandDesc add_hook_cmd = { Regex regex(parser[2].begin(), parser[2].end()); String command = parser[3]; auto hook_func = [=](const String& param, Context& context) { + if (GlobalHooks::instance().are_user_hooks_disabled()) + return; + if (boost::regex_match(param.begin(), param.end(), regex)) CommandManager::instance().execute(command, context, {}, { { "hook_param", param } }); @@ -947,10 +950,10 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func) { const bool disable_hooks = parser.has_option("no-hooks"); if (disable_hooks) - GlobalHooks::instance().disable_hooks(); + GlobalHooks::instance().disable_user_hooks(); auto restore_hooks = on_scope_end([&](){ if (disable_hooks) - GlobalHooks::instance().enable_hooks(); + GlobalHooks::instance().enable_user_hooks(); }); struct DisableOption { diff --git a/src/hook_manager.cc b/src/hook_manager.cc index 9287e9ab..e909a5b6 100644 --- a/src/hook_manager.cc +++ b/src/hook_manager.cc @@ -23,9 +23,6 @@ void HookManager::run_hook(const String& hook_name, const String& param, Context& context) const { - if (GlobalHooks::instance().are_hooks_disabled()) - return; - if (m_parent) m_parent->run_hook(hook_name, param, context); @@ -47,7 +44,7 @@ void HookManager::run_hook(const String& hook_name, } } -bool GlobalHooks::are_hooks_disabled() const +bool GlobalHooks::are_user_hooks_disabled() const { kak_assert(m_disabled >= 0); return m_disabled > 0; diff --git a/src/hook_manager.hh b/src/hook_manager.hh index d0def2de..e7a902b7 100644 --- a/src/hook_manager.hh +++ b/src/hook_manager.hh @@ -36,10 +36,10 @@ class GlobalHooks : public HookManager, public Singleton { public: - bool are_hooks_disabled() const; + bool are_user_hooks_disabled() const; - void disable_hooks() { ++m_disabled; } - void enable_hooks() { --m_disabled; } + void disable_user_hooks() { ++m_disabled; } + void enable_user_hooks() { --m_disabled; } private: int m_disabled = 0; };