diff options
| author | Maxime Coste <mawww@kakoune.org> | 2017-03-30 11:29:06 +0100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2017-03-30 11:31:07 +0100 |
| commit | 055ed5ff7e49e232aa95f0821ff68671756fec38 (patch) | |
| tree | 47702775d0a22f6d2e41dab6fa494622879efe2e /src | |
| parent | 2cfe3cae36cb9054b37a351de0d7b60a0e5bd4ca (diff) | |
Expose hook params regex captures in hook_param_capture_N
Diffstat (limited to 'src')
| -rw-r--r-- | src/commands.cc | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/commands.cc b/src/commands.cc index 2c21c78d..500d37b5 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -800,15 +800,23 @@ const CommandDesc add_hook_cmd = { if (not contains(hooks, parser[1])) throw runtime_error{format("Unknown hook '{}'", parser[1])}; - Regex regex(parser[2], Regex::optimize | Regex::nosubs | Regex::ECMAScript); + Regex regex{parser[2], Regex::optimize | Regex::ECMAScript}; const String& command = parser[3]; auto hook_func = [=](StringView param, Context& context) { ScopedSetBool disable_history{context.history_disabled()}; - if (regex_match(param.begin(), param.end(), regex)) + MatchResults<const char*> res; + if (regex_match(param.begin(), param.end(), res, regex)) + { + EnvVarMap env_vars{ {"hook_param", param.str()} }; + for (size_t i = 0; i < res.size(); ++i) + env_vars.insert({format("hook_param_capture_{}", i), + {res[i].first, res[i].second}}); + CommandManager::instance().execute(command, context, - { {}, { { "hook_param", param.str() } } }); + { {}, std::move(env_vars) }); + } }; auto group = parser.get_switch("group").value_or(StringView{}); get_scope(parser[0], context).hooks().add_hook(parser[1], group.str(), hook_func); |
