1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-27 12:16:22 +03:00

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
This commit is contained in:
Maxime Coste 2018-12-09 10:07:40 +11:00
parent a4f830f143
commit 1875ff51a0
5 changed files with 23 additions and 15 deletions

View File

@ -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)
{

View File

@ -0,0 +1 @@
<ret><ret>

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@
foo

View File

@ -0,0 +1,5 @@
hook global NormalKey <ret> %{
hook window NormalKey <ret> %{
exec -draft ifoo<esc>
}
}