Make hook disabling work for all hooks, not only user hooks

Fixes #823
This commit is contained in:
Maxime Coste 2016-09-26 23:43:05 +01:00
parent 696db111e2
commit e3c4bddd3b
5 changed files with 16 additions and 16 deletions

View File

@ -127,7 +127,7 @@ DisplayLine Client::generate_mode_line() const
modeline.push_back({ format("[recording ({})]", m_input_handler.recording_reg()), info_face }); modeline.push_back({ format("[recording ({})]", m_input_handler.recording_reg()), info_face });
if (context().buffer().flags() & Buffer::Flags::New) if (context().buffer().flags() & Buffer::Flags::New)
modeline.push_back({ "[new file]", info_face }); modeline.push_back({ "[new file]", info_face });
if (context().user_hooks_disabled()) if (context().hooks_disabled())
modeline.push_back({ "[no-hooks]", info_face }); modeline.push_back({ "[no-hooks]", info_face });
if (context().buffer().flags() & Buffer::Flags::Fifo) if (context().buffer().flags() & Buffer::Flags::Fifo)
modeline.push_back({ "[fifo]", info_face }); modeline.push_back({ "[fifo]", info_face });

View File

@ -762,9 +762,6 @@ const CommandDesc add_hook_cmd = {
const String& command = parser[3]; const String& command = parser[3];
auto hook_func = [=](StringView param, Context& context) { auto hook_func = [=](StringView param, Context& context) {
if (context.user_hooks_disabled())
return;
ScopedSetBool disable_history{context.history_disabled()}; ScopedSetBool disable_history{context.history_disabled()};
if (regex_match(param.begin(), param.end(), regex)) if (regex_match(param.begin(), param.end(), regex))
@ -1478,7 +1475,7 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func)
DisableOption<bool> disable_autoshowcompl(context, "autoshowcompl"); DisableOption<bool> disable_autoshowcompl(context, "autoshowcompl");
DisableOption<bool> disable_incsearch(context, "incsearch"); DisableOption<bool> disable_incsearch(context, "incsearch");
const bool no_hooks = parser.get_switch("no-hooks") or context.user_hooks_disabled(); const bool no_hooks = parser.get_switch("no-hooks") or context.hooks_disabled();
const bool no_keymaps = not parser.get_switch("with-maps"); const bool no_keymaps = not parser.get_switch("with-maps");
Vector<RegisterRestorer> saved_registers; Vector<RegisterRestorer> saved_registers;
@ -1493,7 +1490,7 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func)
Context::Flags::Transient}; Context::Flags::Transient};
Context& c = input_handler.context(); Context& c = input_handler.context();
ScopedSetBool disable_hooks(c.user_hooks_disabled(), no_hooks); ScopedSetBool disable_hooks(c.hooks_disabled(), no_hooks);
ScopedSetBool disable_keymaps(c.keymaps_disabled(), no_keymaps); ScopedSetBool disable_keymaps(c.keymaps_disabled(), no_keymaps);
ScopedSetBool disable_history(c.history_disabled()); ScopedSetBool disable_history(c.history_disabled());
@ -1548,7 +1545,7 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func)
Context& c = *effective_context; Context& c = *effective_context;
ScopedSetBool disable_hooks(c.user_hooks_disabled(), no_hooks); ScopedSetBool disable_hooks(c.hooks_disabled(), no_hooks);
ScopedSetBool disable_keymaps(c.keymaps_disabled(), no_keymaps); ScopedSetBool disable_keymaps(c.keymaps_disabled(), no_keymaps);
ScopedSetBool disable_history(c.history_disabled()); ScopedSetBool disable_history(c.history_disabled());

View File

@ -136,8 +136,8 @@ public:
bool is_editing() const { return m_edition_level!= 0; } bool is_editing() const { return m_edition_level!= 0; }
void disable_undo_handling() { m_edition_level = -1; } void disable_undo_handling() { m_edition_level = -1; }
NestedBool& user_hooks_disabled() { return m_user_hooks_disabled; } NestedBool& hooks_disabled() { return m_hooks_disabled; }
const NestedBool& user_hooks_disabled() const { return m_user_hooks_disabled; } const NestedBool& hooks_disabled() const { return m_hooks_disabled; }
NestedBool& keymaps_disabled() { return m_keymaps_disabled; } NestedBool& keymaps_disabled() { return m_keymaps_disabled; }
const NestedBool& keymaps_disabled() const { return m_keymaps_disabled; } const NestedBool& keymaps_disabled() const { return m_keymaps_disabled; }
@ -169,7 +169,7 @@ private:
JumpList m_jump_list; JumpList m_jump_list;
NestedBool m_user_hooks_disabled; NestedBool m_hooks_disabled;
NestedBool m_keymaps_disabled; NestedBool m_keymaps_disabled;
NestedBool m_history_disabled; NestedBool m_history_disabled;
}; };

View File

@ -43,6 +43,9 @@ CandidateList HookManager::complete_hook_group(StringView prefix, ByteCount pos_
void HookManager::run_hook(StringView hook_name, void HookManager::run_hook(StringView hook_name,
StringView param, Context& context) const StringView param, Context& context) const
{ {
if (context.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);

View File

@ -177,7 +177,7 @@ public:
auto restore_hooks = on_scope_end([&, this]{ auto restore_hooks = on_scope_end([&, this]{
if (m_hooks_disabled and do_restore_hooks) if (m_hooks_disabled and do_restore_hooks)
{ {
context().user_hooks_disabled().unset(); context().hooks_disabled().unset();
m_hooks_disabled = false; m_hooks_disabled = false;
} }
}); });
@ -201,7 +201,7 @@ public:
if (not m_hooks_disabled) if (not m_hooks_disabled)
{ {
m_hooks_disabled = true; m_hooks_disabled = true;
context().user_hooks_disabled().set(); context().hooks_disabled().set();
} }
} }
else if (key == '"') else if (key == '"')
@ -939,11 +939,11 @@ public:
m_completer.update(); m_completer.update();
context().hooks().run_hook("InsertIdle", "", context()); context().hooks().run_hook("InsertIdle", "", context());
}}, }},
m_disable_hooks{context().user_hooks_disabled()} m_disable_hooks{context().hooks_disabled()}
{ {
// Prolongate hook disabling for the whole insert session // Prolongate hook disabling for the whole insert session
if (m_disable_hooks) if (m_disable_hooks)
context().user_hooks_disabled().set(); context().hooks_disabled().set();
last_insert().mode = mode; last_insert().mode = mode;
last_insert().keys.clear(); last_insert().keys.clear();
@ -963,7 +963,7 @@ public:
selections.avoid_eol(); selections.avoid_eol();
if (m_disable_hooks) if (m_disable_hooks)
context().user_hooks_disabled().unset(); context().hooks_disabled().unset();
} }
void on_enabled() override void on_enabled() override
@ -1292,7 +1292,7 @@ void InputHandler::repeat_last_insert()
Vector<Key> keys; Vector<Key> keys;
swap(keys, m_last_insert.keys); swap(keys, m_last_insert.keys);
ScopedSetBool disable_hooks(context().user_hooks_disabled(), ScopedSetBool disable_hooks(context().hooks_disabled(),
m_last_insert.disable_hooks); m_last_insert.disable_hooks);
// context.last_insert will be refilled by the new Insert // context.last_insert will be refilled by the new Insert
// this is very inefficient. // this is very inefficient.