Make -with-maps only available for execute-keys command

It does not make a lot of sense to have this switch for
evaluate-commands.
This commit is contained in:
Maxime Coste 2018-05-15 21:10:18 +10:00
parent 5902c7b790
commit 9082564ab7
2 changed files with 30 additions and 20 deletions

View File

@ -48,10 +48,12 @@ when the commands have been executed: */*, *"*, *|*, *^*, *@*.
disable hook execution while executing the keys/commands
(See <<hooks#,`:doc hooks`>>)
*-with-maps*::
use user key mapping in instead of built in keys (*execute-keys* only)
(See <<mapping#,`:doc mapping`>>)
*-save-regs* <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 <<mapping#,`:doc mapping`>>)

View File

@ -1564,17 +1564,27 @@ const CommandDesc unmap_key_cmd = {
}
};
const ParameterDesc context_wrap_params = {
{ { "client", { true, "run in given client context" } },
template<size_t... P>
ParameterDesc make_context_wrap_params_impl(std::array<HashItem<String, SwitchDesc>, sizeof...(P)>&& additional_params,
std::index_sequence<P...>)
{
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" } },
{ "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 '/\"|^@')" } } },
{ "no-hooks", { false, "disable hooks" } },
{ "save-regs", { true, "restore all given registers after execution" } },
std::move(additional_params[P])...},
ParameterDesc::Flags::SwitchesOnlyAtStart, 1
};
};
}
template<size_t N>
ParameterDesc make_context_wrap_params(std::array<HashItem<String, SwitchDesc>, N>&& additional_params)
{
return make_context_wrap_params_impl(std::move(additional_params), std::make_index_sequence<N>());
}
template<typename Func>
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 [<switches>] <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 [<switches>] <commands>...: execute commands as if entered by user",
context_wrap_params,
make_context_wrap_params<0>({}),
CommandFlags::None,
CommandHelper{},
CommandCompleter{},