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

Support named captures in hooks

Fixes #2857
This commit is contained in:
Maxime Coste 2019-04-15 23:53:47 +10:00
parent ac73f7c27f
commit 6b79c1e000
6 changed files with 10 additions and 1 deletions

View File

@ -189,7 +189,9 @@ vars are available:
* `kak_hook_param`: filtering text passed to the currently executing hook
* `kak_hook_param_capture_N`: text captured by the hook filter regex capture N
* `kak_hook_param_capture_N`: text captured by the hook filter regex capturing
group N, N can either be the capturing group number, or its name
(See <<regex#groups,`:doc regex groups`>>).
== Disabling Hooks

View File

@ -117,6 +117,9 @@ void HookManager::run_hook(Hook hook, StringView param, Context& context)
for (size_t i = 0; i < to_run.captures.size(); ++i)
env_vars.insert({format("hook_param_capture_{}", i),
{to_run.captures[i].first, to_run.captures[i].second}});
for (auto& c : to_run.hook->filter.impl()->named_captures)
env_vars.insert({format("hook_param_capture_{}", c.name),
{to_run.captures[c.index].first, to_run.captures[c.index].second}});
CommandManager::instance().execute(to_run.hook->commands, context,
{ {}, std::move(env_vars) });

View File

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

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@
ret

View File

@ -0,0 +1 @@
hook global InsertKey '<(?<name>\w+)>' %{ exec "<backspace>%val(hook_param_capture_name)" }