From 24d8a58b0d8b1d5b72faa55910cc2caa27883149 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 15 May 2018 21:23:17 +1000 Subject: Add -with-hooks to execute-keys and make -no-hooks evaluate-commands specific --- src/commands.cc | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'src') 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 -ParameterDesc make_context_wrap_params_impl(std::array, sizeof...(P)>&& additional_params, +ParameterDesc make_context_wrap_params_impl(Array, sizeof...(P)>&& additional_params, std::index_sequence) { return { { { "client", { true, "run in given client context" } }, @@ -1573,7 +1573,6 @@ ParameterDesc make_context_wrap_params_impl(std::array -ParameterDesc make_context_wrap_params(std::array, N>&& additional_params) +ParameterDesc make_context_wrap_params(Array, N>&& additional_params) { return make_context_wrap_params_impl(std::move(additional_params), std::make_index_sequence()); } @@ -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>()] { @@ -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 [] : 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 [] ...: 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); }); } -- cgit v1.2.3