2012-06-29 18:37:17 +02:00
|
|
|
#include "register_manager.hh"
|
|
|
|
|
|
|
|
#include "assert.hh"
|
2014-12-23 14:54:09 +01:00
|
|
|
#include "id_map.hh"
|
2012-06-29 18:37:17 +02:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2015-11-25 22:08:33 +01:00
|
|
|
Register& RegisterManager::operator[](StringView reg) const
|
2012-06-29 18:37:17 +02:00
|
|
|
{
|
2014-06-06 01:48:18 +02:00
|
|
|
if (reg.length() == 1)
|
2015-03-10 20:33:46 +01:00
|
|
|
return (*this)[reg[0_byte]];
|
2014-06-06 01:48:18 +02:00
|
|
|
|
2014-12-23 23:51:00 +01:00
|
|
|
static const IdMap<Codepoint> reg_names = {
|
2014-06-06 01:48:18 +02:00
|
|
|
{ "slash", '/' },
|
|
|
|
{ "dquote", '"' },
|
2015-08-19 22:16:53 +02:00
|
|
|
{ "pipe", '|' },
|
|
|
|
{ "caret", '^' },
|
|
|
|
{ "arobase", '@' }
|
2014-06-06 01:48:18 +02:00
|
|
|
};
|
|
|
|
auto it = reg_names.find(reg);
|
|
|
|
if (it == reg_names.end())
|
2015-06-01 22:15:59 +02:00
|
|
|
throw runtime_error(format("no such register: '{}'", reg));
|
2015-09-16 20:57:57 +02:00
|
|
|
return (*this)[it->value];
|
2014-06-06 01:48:18 +02:00
|
|
|
}
|
|
|
|
|
2015-11-25 22:08:33 +01:00
|
|
|
Register& RegisterManager::operator[](Codepoint c) const
|
2014-06-06 01:48:18 +02:00
|
|
|
{
|
2015-11-11 01:21:20 +01:00
|
|
|
c = to_lower(c);
|
2015-11-25 22:08:33 +01:00
|
|
|
auto it = m_registers.find(c);
|
|
|
|
if (it == m_registers.end())
|
|
|
|
throw runtime_error(format("no such register: '{}'", c));
|
2015-07-14 14:48:39 +02:00
|
|
|
|
2015-11-25 22:08:33 +01:00
|
|
|
return *(it->second);
|
2012-06-29 18:37:17 +02:00
|
|
|
}
|
|
|
|
|
2015-11-25 22:08:33 +01:00
|
|
|
void RegisterManager::add_register(char c, std::unique_ptr<Register> reg)
|
2012-06-29 18:37:17 +02:00
|
|
|
{
|
2015-11-25 22:08:33 +01:00
|
|
|
auto& reg_ptr = m_registers[c];
|
2013-04-09 20:04:11 +02:00
|
|
|
kak_assert(not reg_ptr);
|
2015-11-25 22:08:33 +01:00
|
|
|
reg_ptr = std::move(reg);
|
2012-06-29 18:37:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|