diff options
| author | Maxime Coste <mawww@kakoune.org> | 2018-12-09 10:07:40 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2018-12-09 10:07:40 +1100 |
| commit | 1875ff51a001a73f89f1273782db03490247238d (patch) | |
| tree | 496eb1a389f470257703206419ec6d8485c86e8c /src | |
| parent | a4f830f143e625710f6cc5f9dd63965b66ad0989 (diff) | |
Gather the list of hooks to run before running the parent
This will prevent hooks added by the parent hook manager to be
gathered, as was decided during the discussion for #2603
Diffstat (limited to 'src')
| -rw-r--r-- | src/hook_manager.cc | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/hook_manager.cc b/src/hook_manager.cc index e55eb89e..c5698c18 100644 --- a/src/hook_manager.cc +++ b/src/hook_manager.cc @@ -63,12 +63,26 @@ CandidateList HookManager::complete_hook_group(StringView prefix, ByteCount pos_ void HookManager::run_hook(Hook hook, StringView param, Context& context) { + auto& hook_list = m_hooks[to_underlying(hook)]; + const bool only_always = context.hooks_disabled(); + auto& disabled_hooks = context.options()["disabled_hooks"].get<Regex>(); + + struct ToRun { HookData* hook; MatchResults<const char*> captures; }; + Vector<ToRun> hooks_to_run; // The m_hooks_trash vector ensure hooks wont die during this method + for (auto& hook : hook_list) + { + MatchResults<const char*> captures; + if ((not only_always or (hook->flags & HookFlags::Always)) and + (hook->group.empty() or disabled_hooks.empty() or + not regex_match(hook->group.begin(), hook->group.end(), disabled_hooks)) + and regex_match(param.begin(), param.end(), captures, hook->filter)) + hooks_to_run.push_back({ hook.get(), std::move(captures) }); + } if (m_parent) m_parent->run_hook(hook, param, context); - auto& hook_list = m_hooks[to_underlying(hook)]; auto hook_name = enum_desc(Meta::Type<Hook>{})[to_underlying(hook)].name; if (contains(m_running_hooks, std::make_pair(hook, param))) { @@ -88,20 +102,6 @@ void HookManager::run_hook(Hook hook, StringView param, Context& context) const bool profile = debug_flags & DebugFlags::Profile; auto start_time = profile ? Clock::now() : TimePoint{}; - auto& disabled_hooks = context.options()["disabled_hooks"].get<Regex>(); - - struct ToRun { HookData* hook; MatchResults<const char*> captures; }; - Vector<ToRun> hooks_to_run; // The m_hooks_trash vector ensure hooks wont die during this method - for (auto& hook : hook_list) - { - MatchResults<const char*> captures; - if ((not only_always or (hook->flags & HookFlags::Always)) and - (hook->group.empty() or disabled_hooks.empty() or - not regex_match(hook->group.begin(), hook->group.end(), disabled_hooks)) - and regex_match(param.begin(), param.end(), captures, hook->filter)) - hooks_to_run.push_back({ hook.get(), std::move(captures) }); - } - bool hook_error = false; for (auto& to_run : hooks_to_run) { |
