diff --git a/src/commands.cc b/src/commands.cc index 8207d7df..693706e8 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -885,6 +885,7 @@ const ParameterDesc context_wrap_params = { { "try-client", { true, "run in given client context if it exists, or else in the current one" } }, { "buffer", { true, "run in a disposable context for each given buffer in the comma separated list argument" } }, { "draft", { false, "run in a disposable context" } }, + { "no-hooks", { false, "disable hooks" } }, { "itersel", { false, "run once for each selection with that selection as the only one" } } }, ParameterDesc::Flags::SwitchesOnlyAtStart, 1 }; @@ -892,6 +893,14 @@ const ParameterDesc context_wrap_params = { template 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(); + auto restore_hooks = on_scope_end([&](){ + if (disable_hooks) + GlobalHooks::instance().enable_hooks(); + }); + ClientManager& cm = ClientManager::instance(); if (parser.has_option("buffer")) { diff --git a/src/hook_manager.cc b/src/hook_manager.cc index 344b6ce0..47b52e00 100644 --- a/src/hook_manager.cc +++ b/src/hook_manager.cc @@ -23,6 +23,9 @@ 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); @@ -44,4 +47,11 @@ void HookManager::run_hook(const String& hook_name, } } +bool GlobalHooks::are_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 1c86bfb1..794f8077 100644 --- a/src/hook_manager.hh +++ b/src/hook_manager.hh @@ -35,6 +35,13 @@ private: class GlobalHooks : public HookManager, public Singleton { +public: + bool are_hooks_disabled() const; + + void disable_hooks() { ++m_disabled; } + void enable_hooks() { --m_disabled; } +private: + int m_disabled = 0; }; }