Only user hooks can be disabled

This commit is contained in:
Maxime Coste 2014-06-21 12:08:19 +01:00
parent 7235180614
commit edd883ad18
3 changed files with 9 additions and 9 deletions

View File

@ -519,6 +519,9 @@ const CommandDesc add_hook_cmd = {
Regex regex(parser[2].begin(), parser[2].end()); Regex regex(parser[2].begin(), parser[2].end());
String command = parser[3]; String command = parser[3];
auto hook_func = [=](const String& param, Context& context) { 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)) if (boost::regex_match(param.begin(), param.end(), regex))
CommandManager::instance().execute(command, context, {}, CommandManager::instance().execute(command, context, {},
{ { "hook_param", param } }); { { "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"); const bool disable_hooks = parser.has_option("no-hooks");
if (disable_hooks) if (disable_hooks)
GlobalHooks::instance().disable_hooks(); GlobalHooks::instance().disable_user_hooks();
auto restore_hooks = on_scope_end([&](){ auto restore_hooks = on_scope_end([&](){
if (disable_hooks) if (disable_hooks)
GlobalHooks::instance().enable_hooks(); GlobalHooks::instance().enable_user_hooks();
}); });
struct DisableOption { struct DisableOption {

View File

@ -23,9 +23,6 @@ void HookManager::run_hook(const String& hook_name,
const String& param, const String& param,
Context& context) const Context& context) const
{ {
if (GlobalHooks::instance().are_hooks_disabled())
return;
if (m_parent) if (m_parent)
m_parent->run_hook(hook_name, param, context); 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); kak_assert(m_disabled >= 0);
return m_disabled > 0; return m_disabled > 0;

View File

@ -36,10 +36,10 @@ class GlobalHooks : public HookManager,
public Singleton<GlobalHooks> public Singleton<GlobalHooks>
{ {
public: public:
bool are_hooks_disabled() const; bool are_user_hooks_disabled() const;
void disable_hooks() { ++m_disabled; } void disable_user_hooks() { ++m_disabled; }
void enable_hooks() { --m_disabled; } void enable_user_hooks() { --m_disabled; }
private: private:
int m_disabled = 0; int m_disabled = 0;
}; };