diff --git a/README.asciidoc b/README.asciidoc index f0695fa5..cc133fe1 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -1155,6 +1155,8 @@ Some helper commands can be used to define composite commands: * `:prompt `: Prompt the user for a string, when the user validates, store the result in given and run . the -init switch allows setting initial content. + * `:onkey `: Wait for next key from user, writes it into given + and execute commands. * `:menu ...`: display a menu using labels, the selected label's commands are executed. `menu` can take a -auto-single argument, to automatically run commands diff --git a/src/commands.cc b/src/commands.cc index e1cfcb10..682e191b 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1300,6 +1300,26 @@ const CommandDesc menu_cmd = { } }; +const CommandDesc onkey_cmd = { + "onkey", + nullptr, + "onkey : wait for next user key, store it in and execute ", + ParameterDesc{ {}, ParameterDesc::Flags::None, 2, 2 }, + CommandFlags::None, + CommandHelper{}, + CommandCompleter{}, + [](const ParametersParser& parser, Context& context) + { + String reg = parser[0]; + String command = parser[1]; + context.input_handler().on_next_key(KeymapMode::None, + [=](Key key, Context& context) { + RegisterManager::instance()[reg] = key_to_str(key); + CommandManager::instance().execute(command, context); + }); + } +}; + const CommandDesc info_cmd = { "info", nullptr, @@ -1517,6 +1537,7 @@ void register_commands() register_command(eval_string_cmd); register_command(prompt_cmd); register_command(menu_cmd); + register_command(onkey_cmd); register_command(info_cmd); register_command(try_catch_cmd); register_command(face_cmd);