exec and eval support the -no-hooks option

Hooks gets disabled during the execution of the commands
This commit is contained in:
Maxime Coste 2014-03-20 08:29:41 +00:00
parent be417d3616
commit c48bdbe4f1
3 changed files with 26 additions and 0 deletions

View File

@ -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" } }, { "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" } }, { "buffer", { true, "run in a disposable context for each given buffer in the comma separated list argument" } },
{ "draft", { false, "run in a disposable context" } }, { "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" } } }, { "itersel", { false, "run once for each selection with that selection as the only one" } } },
ParameterDesc::Flags::SwitchesOnlyAtStart, 1 ParameterDesc::Flags::SwitchesOnlyAtStart, 1
}; };
@ -892,6 +893,14 @@ const ParameterDesc context_wrap_params = {
template<typename Func> template<typename Func>
void context_wrap(const ParametersParser& parser, Context& context, Func func) 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(); ClientManager& cm = ClientManager::instance();
if (parser.has_option("buffer")) if (parser.has_option("buffer"))
{ {

View File

@ -23,6 +23,9 @@ 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);
@ -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;
}
} }

View File

@ -35,6 +35,13 @@ private:
class GlobalHooks : public HookManager, class GlobalHooks : public HookManager,
public Singleton<GlobalHooks> public Singleton<GlobalHooks>
{ {
public:
bool are_hooks_disabled() const;
void disable_hooks() { ++m_disabled; }
void enable_hooks() { --m_disabled; }
private:
int m_disabled = 0;
}; };
} }