summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-05-15 21:23:17 +1000
committerMaxime Coste <mawww@kakoune.org>2018-07-05 07:54:28 +1000
commit24d8a58b0d8b1d5b72faa55910cc2caa27883149 (patch)
tree8df5c30eb51eca2652a8aff9b20c4902edb4fa41 /src
parent9082564ab728568fcf4a1670ce405059d7abf6c6 (diff)
Add -with-hooks to execute-keys and make -no-hooks evaluate-commands specific
Diffstat (limited to 'src')
-rw-r--r--src/commands.cc21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/commands.cc b/src/commands.cc
index df114314..8323aa56 100644
--- a/src/commands.cc
+++ b/src/commands.cc
@@ -1565,7 +1565,7 @@ const CommandDesc unmap_key_cmd = {
};
template<size_t... P>
-ParameterDesc make_context_wrap_params_impl(std::array<HashItem<String, SwitchDesc>, sizeof...(P)>&& additional_params,
+ParameterDesc make_context_wrap_params_impl(Array<HashItem<String, SwitchDesc>, sizeof...(P)>&& additional_params,
std::index_sequence<P...>)
{
return { { { "client", { true, "run in given client context" } },
@@ -1573,7 +1573,6 @@ ParameterDesc make_context_wrap_params_impl(std::array<HashItem<String, SwitchDe
{ "buffer", { true, "run in a disposable context for each given buffer in the comma separated list argument" } },
{ "draft", { false, "run in a disposable context" } },
{ "itersel", { false, "run once for each selection with that selection as the only one" } },
- { "no-hooks", { false, "disable hooks" } },
{ "save-regs", { true, "restore all given registers after execution" } },
std::move(additional_params[P])...},
ParameterDesc::Flags::SwitchesOnlyAtStart, 1
@@ -1581,7 +1580,7 @@ ParameterDesc make_context_wrap_params_impl(std::array<HashItem<String, SwitchDe
}
template<size_t N>
-ParameterDesc make_context_wrap_params(std::array<HashItem<String, SwitchDesc>, N>&& additional_params)
+ParameterDesc make_context_wrap_params(Array<HashItem<String, SwitchDesc>, N>&& additional_params)
{
return make_context_wrap_params_impl(std::move(additional_params), std::make_index_sequence<N>());
}
@@ -1594,8 +1593,6 @@ void context_wrap(const ParametersParser& parser, Context& context, StringView d
(int)(bool)parser.get_switch("try-client") > 1)
throw runtime_error{"only one of -buffer, -client or -try-client can be specified"};
- const bool no_hooks = parser.get_switch("no-hooks") or context.hooks_disabled();
-
auto& register_manager = RegisterManager::instance();
auto make_register_restorer = [&](char c) {
return on_scope_end([&, c, save=register_manager[c].get(context) | gather<Vector<String>>()] {
@@ -1620,7 +1617,6 @@ void context_wrap(const ParametersParser& parser, Context& context, StringView d
Context::Flags::Draft};
Context& c = input_handler.context();
- ScopedSetBool disable_hooks(c.hooks_disabled(), no_hooks);
ScopedSetBool disable_history(c.history_disabled());
func(parser, c);
@@ -1672,7 +1668,6 @@ void context_wrap(const ParametersParser& parser, Context& context, StringView d
Context& c = *effective_context;
- ScopedSetBool disable_hooks(c.hooks_disabled(), no_hooks);
ScopedSetBool disable_history(c.history_disabled());
ScopedEdition edition{c};
@@ -1729,7 +1724,10 @@ const CommandDesc exec_string_cmd = {
"execute-keys",
"exec",
"execute-keys [<switches>] <keys>: execute given keys as if entered by user",
- make_context_wrap_params<1>({{"with-maps", {false, "use user defined key mapping when executing keys" }}}),
+ make_context_wrap_params<2>({{
+ {"with-maps", {false, "use user defined key mapping when executing keys"}},
+ {"with-hooks", {false, "trigger hooks while executing keys"}}
+ }}),
CommandFlags::None,
CommandHelper{},
CommandCompleter{},
@@ -1737,6 +1735,8 @@ const CommandDesc exec_string_cmd = {
{
context_wrap(parser, context, "/\"|^@", [](const ParametersParser& parser, Context& context) {
ScopedSetBool disable_keymaps(context.keymaps_disabled(), not parser.get_switch("with-maps"));
+ ScopedSetBool disable_hoooks(context.hooks_disabled(), not parser.get_switch("with-hooks"));
+
KeyList keys;
for (auto& param : parser)
{
@@ -1754,13 +1754,16 @@ const CommandDesc eval_string_cmd = {
"evaluate-commands",
"eval",
"evaluate-commands [<switches>] <commands>...: execute commands as if entered by user",
- make_context_wrap_params<0>({}),
+ make_context_wrap_params<1>({{{"no-hooks", { false, "disable hooks while executing commands" }}}}),
CommandFlags::None,
CommandHelper{},
CommandCompleter{},
[](const ParametersParser& parser, Context& context, const ShellContext& shell_context)
{
context_wrap(parser, context, {}, [&](const ParametersParser& parser, Context& context) {
+ const bool no_hooks = context.hooks_disabled() or parser.get_switch("no-hooks");
+ ScopedSetBool disable_hoooks(context.hooks_disabled(), no_hooks);
+
CommandManager::instance().execute(join(parser, ' ', false), context, shell_context);
});
}