Add -with-hooks to execute-keys and make -no-hooks evaluate-commands specific

This commit is contained in:
Maxime Coste 2018-05-15 21:23:17 +10:00
parent 9082564ab7
commit 24d8a58b0d
2 changed files with 22 additions and 13 deletions

View File

@ -44,16 +44,22 @@ when the commands have been executed: */*, *"*, *|*, *^*, *@*.
execute in the context of each buffers in the comma separated list execute in the context of each buffers in the comma separated list
*names*. `*` as a name can be used to iterate on all buffers *names*. `*` as a name can be used to iterate on all buffers
*-no-hooks*::
disable hook execution while executing the keys/commands
(See <<hooks#,`:doc hooks`>>)
*-save-regs* <regs>:: *-save-regs* <regs>::
regs is a string of registers to be restored after execution (overwrites regs is a string of registers to be restored after execution (overwrites
the list of registers saved by default, c.f. description) the list of registers saved by default, c.f. description)
== evaluate-commands specific switches
*-no-hooks*::
disable hook execution while executing the keys/commands
(See <<hooks#,`:doc hooks`>>)
== execute-keys specific switches == execute-keys specific switches
*-with-maps*:: *-with-maps*::
use user key mapping in instead of built in keys use user key mapping in instead of built in keys
(See <<mapping#,`:doc mapping`>>) (See <<mapping#,`:doc mapping`>>)
*-with-hooks*::
the execution of keys will trigger existing hooks
(See <<hooks#,`:doc hooks`>>)

View File

@ -1565,7 +1565,7 @@ const CommandDesc unmap_key_cmd = {
}; };
template<size_t... P> 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...>) std::index_sequence<P...>)
{ {
return { { { "client", { true, "run in given client context" } }, 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" } }, { "buffer", { true, "run in a disposable context for each given buffer in the comma separated list argument" } },
{ "draft", { false, "run in a disposable context" } }, { "draft", { false, "run in a disposable context" } },
{ "itersel", { false, "run once for each selection with that selection as the only one" } }, { "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" } }, { "save-regs", { true, "restore all given registers after execution" } },
std::move(additional_params[P])...}, std::move(additional_params[P])...},
ParameterDesc::Flags::SwitchesOnlyAtStart, 1 ParameterDesc::Flags::SwitchesOnlyAtStart, 1
@ -1581,7 +1580,7 @@ ParameterDesc make_context_wrap_params_impl(std::array<HashItem<String, SwitchDe
} }
template<size_t N> 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>()); 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) (int)(bool)parser.get_switch("try-client") > 1)
throw runtime_error{"only one of -buffer, -client or -try-client can be specified"}; 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& register_manager = RegisterManager::instance();
auto make_register_restorer = [&](char c) { auto make_register_restorer = [&](char c) {
return on_scope_end([&, c, save=register_manager[c].get(context) | gather<Vector<String>>()] { 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::Flags::Draft};
Context& c = input_handler.context(); Context& c = input_handler.context();
ScopedSetBool disable_hooks(c.hooks_disabled(), no_hooks);
ScopedSetBool disable_history(c.history_disabled()); ScopedSetBool disable_history(c.history_disabled());
func(parser, c); func(parser, c);
@ -1672,7 +1668,6 @@ void context_wrap(const ParametersParser& parser, Context& context, StringView d
Context& c = *effective_context; Context& c = *effective_context;
ScopedSetBool disable_hooks(c.hooks_disabled(), no_hooks);
ScopedSetBool disable_history(c.history_disabled()); ScopedSetBool disable_history(c.history_disabled());
ScopedEdition edition{c}; ScopedEdition edition{c};
@ -1729,7 +1724,10 @@ const CommandDesc exec_string_cmd = {
"execute-keys", "execute-keys",
"exec", "exec",
"execute-keys [<switches>] <keys>: execute given keys as if entered by user", "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, CommandFlags::None,
CommandHelper{}, CommandHelper{},
CommandCompleter{}, CommandCompleter{},
@ -1737,6 +1735,8 @@ const CommandDesc exec_string_cmd = {
{ {
context_wrap(parser, context, "/\"|^@", [](const ParametersParser& parser, Context& context) { context_wrap(parser, context, "/\"|^@", [](const ParametersParser& parser, Context& context) {
ScopedSetBool disable_keymaps(context.keymaps_disabled(), not parser.get_switch("with-maps")); 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; KeyList keys;
for (auto& param : parser) for (auto& param : parser)
{ {
@ -1754,13 +1754,16 @@ const CommandDesc eval_string_cmd = {
"evaluate-commands", "evaluate-commands",
"eval", "eval",
"evaluate-commands [<switches>] <commands>...: execute commands as if entered by user", "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, CommandFlags::None,
CommandHelper{}, CommandHelper{},
CommandCompleter{}, CommandCompleter{},
[](const ParametersParser& parser, Context& context, const ShellContext& shell_context) [](const ParametersParser& parser, Context& context, const ShellContext& shell_context)
{ {
context_wrap(parser, context, {}, [&](const ParametersParser& parser, Context& 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); CommandManager::instance().execute(join(parser, ' ', false), context, shell_context);
}); });
} }