Only user hooks can be disabled
This commit is contained in:
parent
7235180614
commit
edd883ad18
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -36,10 +36,10 @@ class GlobalHooks : public HookManager,
|
|||
public Singleton<GlobalHooks>
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user