diff --git a/src/client.cc b/src/client.cc index 1d65227b..e62aaa5d 100644 --- a/src/client.cc +++ b/src/client.cc @@ -127,7 +127,7 @@ DisplayLine Client::generate_mode_line() const modeline.push_back({ format("[recording ({})]", m_input_handler.recording_reg()), info_face }); if (context().buffer().flags() & Buffer::Flags::New) modeline.push_back({ "[new file]", info_face }); - if (context().user_hooks_disabled()) + if (context().hooks_disabled()) modeline.push_back({ "[no-hooks]", info_face }); if (context().buffer().flags() & Buffer::Flags::Fifo) modeline.push_back({ "[fifo]", info_face }); diff --git a/src/commands.cc b/src/commands.cc index dda01867..45f3cacd 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -762,9 +762,6 @@ const CommandDesc add_hook_cmd = { const String& command = parser[3]; auto hook_func = [=](StringView param, Context& context) { - if (context.user_hooks_disabled()) - return; - ScopedSetBool disable_history{context.history_disabled()}; if (regex_match(param.begin(), param.end(), regex)) @@ -1478,7 +1475,7 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func) DisableOption disable_autoshowcompl(context, "autoshowcompl"); DisableOption 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"); Vector saved_registers; @@ -1493,7 +1490,7 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func) Context::Flags::Transient}; 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_history(c.history_disabled()); @@ -1548,7 +1545,7 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func) 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_history(c.history_disabled()); diff --git a/src/context.hh b/src/context.hh index 0bbbaa98..4ef1934b 100644 --- a/src/context.hh +++ b/src/context.hh @@ -136,8 +136,8 @@ public: bool is_editing() const { return m_edition_level!= 0; } void disable_undo_handling() { m_edition_level = -1; } - NestedBool& user_hooks_disabled() { return m_user_hooks_disabled; } - const NestedBool& user_hooks_disabled() const { return m_user_hooks_disabled; } + NestedBool& hooks_disabled() { return m_hooks_disabled; } + const NestedBool& hooks_disabled() const { return m_hooks_disabled; } NestedBool& keymaps_disabled() { return m_keymaps_disabled; } const NestedBool& keymaps_disabled() const { return m_keymaps_disabled; } @@ -169,7 +169,7 @@ private: JumpList m_jump_list; - NestedBool m_user_hooks_disabled; + NestedBool m_hooks_disabled; NestedBool m_keymaps_disabled; NestedBool m_history_disabled; }; diff --git a/src/hook_manager.cc b/src/hook_manager.cc index be940482..9278e577 100644 --- a/src/hook_manager.cc +++ b/src/hook_manager.cc @@ -43,6 +43,9 @@ CandidateList HookManager::complete_hook_group(StringView prefix, ByteCount pos_ void HookManager::run_hook(StringView hook_name, StringView param, Context& context) const { + if (context.hooks_disabled()) + return; + if (m_parent) m_parent->run_hook(hook_name, param, context); diff --git a/src/input_handler.cc b/src/input_handler.cc index a8970164..c7675a1a 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -177,7 +177,7 @@ public: auto restore_hooks = on_scope_end([&, this]{ if (m_hooks_disabled and do_restore_hooks) { - context().user_hooks_disabled().unset(); + context().hooks_disabled().unset(); m_hooks_disabled = false; } }); @@ -201,7 +201,7 @@ public: if (not m_hooks_disabled) { m_hooks_disabled = true; - context().user_hooks_disabled().set(); + context().hooks_disabled().set(); } } else if (key == '"') @@ -939,11 +939,11 @@ public: m_completer.update(); 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 if (m_disable_hooks) - context().user_hooks_disabled().set(); + context().hooks_disabled().set(); last_insert().mode = mode; last_insert().keys.clear(); @@ -963,7 +963,7 @@ public: selections.avoid_eol(); if (m_disable_hooks) - context().user_hooks_disabled().unset(); + context().hooks_disabled().unset(); } void on_enabled() override @@ -1292,7 +1292,7 @@ void InputHandler::repeat_last_insert() Vector 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); // context.last_insert will be refilled by the new Insert // this is very inefficient.