From 9082564ab728568fcf4a1670ce405059d7abf6c6 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 15 May 2018 21:10:18 +1000 Subject: [PATCH] Make -with-maps only available for execute-keys command It does not make a lot of sense to have this switch for evaluate-commands. --- doc/pages/execeval.asciidoc | 10 ++++++---- src/commands.cc | 40 ++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/doc/pages/execeval.asciidoc b/doc/pages/execeval.asciidoc index 1c7ed00a9..5705bdf33 100644 --- a/doc/pages/execeval.asciidoc +++ b/doc/pages/execeval.asciidoc @@ -48,10 +48,12 @@ when the commands have been executed: */*, *"*, *|*, *^*, *@*. disable hook execution while executing the keys/commands (See <>) -*-with-maps*:: - use user key mapping in instead of built in keys (*execute-keys* only) - (See <>) - *-save-regs* :: regs is a string of registers to be restored after execution (overwrites the list of registers saved by default, c.f. description) + +== execute-keys specific switches + +*-with-maps*:: + use user key mapping in instead of built in keys + (See <>) diff --git a/src/commands.cc b/src/commands.cc index a169fee49..df1143147 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1564,17 +1564,27 @@ const CommandDesc unmap_key_cmd = { } }; -const ParameterDesc context_wrap_params = { - { { "client", { true, "run in given client context" } }, - { "try-client", { true, "run in given client context if it exists, or else in the current one" } }, - { "buffer", { true, "run in a disposable context for each given buffer in the comma separated list argument" } }, - { "draft", { false, "run in a disposable context" } }, - { "no-hooks", { false, "disable hooks" } }, - { "with-maps", { false, "use user defined key mapping when executing keys" } }, - { "itersel", { false, "run once for each selection with that selection as the only one" } }, - { "save-regs", { true, "restore all given registers after execution (defaults to '/\"|^@')" } } }, - ParameterDesc::Flags::SwitchesOnlyAtStart, 1 -}; +template +ParameterDesc make_context_wrap_params_impl(std::array, sizeof...(P)>&& additional_params, + std::index_sequence) +{ + return { { { "client", { true, "run in given client context" } }, + { "try-client", { true, "run in given client context if it exists, or else in the current one" } }, + { "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 + }; +} + +template +ParameterDesc make_context_wrap_params(std::array, N>&& additional_params) +{ + return make_context_wrap_params_impl(std::move(additional_params), std::make_index_sequence()); +} template void context_wrap(const ParametersParser& parser, Context& context, StringView default_saved_regs, Func func) @@ -1585,7 +1595,6 @@ void context_wrap(const ParametersParser& parser, Context& context, StringView d 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(); - const bool no_keymaps = not parser.get_switch("with-maps"); auto& register_manager = RegisterManager::instance(); auto make_register_restorer = [&](char c) { @@ -1612,7 +1621,6 @@ void context_wrap(const ParametersParser& parser, Context& context, StringView d Context& c = input_handler.context(); ScopedSetBool disable_hooks(c.hooks_disabled(), no_hooks); - ScopedSetBool disable_keymaps(c.keymaps_disabled(), no_keymaps); ScopedSetBool disable_history(c.history_disabled()); func(parser, c); @@ -1665,7 +1673,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_keymaps(c.keymaps_disabled(), no_keymaps); ScopedSetBool disable_history(c.history_disabled()); ScopedEdition edition{c}; @@ -1722,13 +1729,14 @@ const CommandDesc exec_string_cmd = { "execute-keys", "exec", "execute-keys [] : execute given keys as if entered by user", - context_wrap_params, + make_context_wrap_params<1>({{"with-maps", {false, "use user defined key mapping when executing keys" }}}), CommandFlags::None, CommandHelper{}, CommandCompleter{}, [](const ParametersParser& parser, Context& context, const ShellContext&) { context_wrap(parser, context, "/\"|^@", [](const ParametersParser& parser, Context& context) { + ScopedSetBool disable_keymaps(context.keymaps_disabled(), not parser.get_switch("with-maps")); KeyList keys; for (auto& param : parser) { @@ -1746,7 +1754,7 @@ const CommandDesc eval_string_cmd = { "evaluate-commands", "eval", "evaluate-commands [] ...: execute commands as if entered by user", - context_wrap_params, + make_context_wrap_params<0>({}), CommandFlags::None, CommandHelper{}, CommandCompleter{},