add a reg command to set a register

This commit is contained in:
Maxime Coste 2013-03-18 22:43:48 +01:00
parent 5fe7315df9
commit 2de0d0fccf
2 changed files with 13 additions and 0 deletions

View File

@ -434,6 +434,7 @@ Some helper commands can be used to define composite commands:
* +try <commands> catch <on_error_commands>+: prevent an error in <commands> * +try <commands> catch <on_error_commands>+: prevent an error in <commands>
from aborting the whole commands execution, execute <on_error_commands> from aborting the whole commands execution, execute <on_error_commands>
instead. instead.
* +reg <name> <content>+: set register <name> to <content>
Note that these commands are available in interactive command mode, but are Note that these commands are available in interactive command mode, but are
not that useful in this context. not that useful in this context.

View File

@ -713,6 +713,16 @@ void set_client_name(const CommandParameters& params, Context& context)
ClientManager::instance().set_client_name(context, params[0]); ClientManager::instance().set_client_name(context, params[0]);
} }
void set_register(const CommandParameters& params, Context& context)
{
if (params.size() != 2)
throw wrong_argument_count();
if (params[0].length() != 1)
throw runtime_error("register names are single character");
RegisterManager::instance()[params[0][0]] = memoryview<String>(params[1]);
}
class RegisterRestorer class RegisterRestorer
{ {
public: public:
@ -908,6 +918,8 @@ void register_commands()
cm.register_commands({"ca", "colalias"}, define_color_alias); cm.register_commands({"ca", "colalias"}, define_color_alias);
cm.register_commands({"name"}, set_client_name); cm.register_commands({"name"}, set_client_name);
cm.register_command("reg", set_register);
} }
} }