diff --git a/src/command_manager.cc b/src/command_manager.cc index 9ae3cbc5..a99f89b3 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -313,9 +313,7 @@ String eval_token(const Token& token, Context& context, return ShellManager::instance().eval(content, context, shell_params, env_vars); case Token::Type::RegisterExpand: - if (content.length() != 1) - throw runtime_error("wrong register name: " + content); - return RegisterManager::instance()[content[0]].values(context)[0]; + return RegisterManager::instance()[content].values(context)[0]; case Token::Type::OptionExpand: return context.options()[content].get_as_string(); case Token::Type::RawEval: diff --git a/src/commands.cc b/src/commands.cc index 988fbeb1..90d72f56 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1269,9 +1269,7 @@ const CommandDesc set_register_cmd = { CommandCompleter{}, [](const ParametersParser& parser, Context& context) { - if (parser[0].length() != 1) - throw runtime_error("register names are single character"); - RegisterManager::instance()[parser[0][0]] = memoryview(parser[1]); + RegisterManager::instance()[parser[0]] = memoryview(parser[1]); } }; diff --git a/src/main.cc b/src/main.cc index 46163d7e..346c7cd7 100644 --- a/src/main.cc +++ b/src/main.cc @@ -106,7 +106,7 @@ void register_env_vars() }, { "reg_.+", [](StringView name, const Context& context) -> String - { return RegisterManager::instance()[name[4]].values(context)[0]; } + { return RegisterManager::instance()[name.substr(4_byte)].values(context)[0]; } }, { "client_env_.+", [](StringView name, const Context& context) -> String diff --git a/src/register_manager.cc b/src/register_manager.cc index 0fb17141..f3b6b06e 100644 --- a/src/register_manager.cc +++ b/src/register_manager.cc @@ -1,6 +1,7 @@ #include "register_manager.hh" #include "assert.hh" +#include "id_map.hh" #include "utils.hh" namespace Kakoune @@ -55,9 +56,25 @@ private: RegisterRetriever m_function; }; -Register& RegisterManager::operator[](char reg) +Register& RegisterManager::operator[](StringView reg) { - auto& reg_ptr = m_registers[reg]; + if (reg.length() == 1) + return (*this)[reg[0]]; + + static const id_map reg_names = { + { "slash", '/' }, + { "dquote", '"' }, + { "pipe", '|' } + }; + auto it = reg_names.find(reg); + if (it == reg_names.end()) + throw runtime_error("no such register: " + reg); + return (*this)[it->second]; +} + +Register& RegisterManager::operator[](Codepoint c) +{ + auto& reg_ptr = m_registers[c]; if (not reg_ptr) reg_ptr.reset(new StaticRegister()); return *reg_ptr; diff --git a/src/register_manager.hh b/src/register_manager.hh index 7021c53b..97f84fc0 100644 --- a/src/register_manager.hh +++ b/src/register_manager.hh @@ -16,7 +16,8 @@ using RegisterRetriever = std::function (const Context&)>; class RegisterManager : public Singleton { public: - Register& operator[](char reg); + Register& operator[](StringView reg); + Register& operator[](Codepoint c); void register_dynamic_register(char reg, RegisterRetriever function); protected: