kakoune/src/alias_registry.cc

49 lines
1.0 KiB
C++
Raw Normal View History

#include "alias_registry.hh"
#include "command_manager.hh"
namespace Kakoune
{
void AliasRegistry::add_alias(String alias, String command)
{
kak_assert(not alias.empty());
kak_assert(CommandManager::instance().command_defined(command));
2015-09-16 23:32:02 +02:00
m_aliases.append({std::move(alias), std::move(command) }, true);
}
2015-09-16 23:32:02 +02:00
void AliasRegistry::remove_alias(StringView alias)
{
auto it = m_aliases.find(alias);
if (it != m_aliases.end())
m_aliases.erase(it);
}
2015-09-16 23:32:02 +02:00
StringView AliasRegistry::operator[](StringView alias) const
{
auto it = m_aliases.find(alias);
if (it != m_aliases.end())
2015-09-16 23:32:02 +02:00
return it->value;
else if (m_parent)
return (*m_parent)[alias];
else
return StringView{};
}
2015-01-12 14:58:41 +01:00
Vector<StringView> AliasRegistry::aliases_for(StringView command) const
{
2015-01-12 14:58:41 +01:00
Vector<StringView> res;
if (m_parent)
res = m_parent->aliases_for(command);
for (auto& alias : m_aliases)
{
2015-09-16 23:32:02 +02:00
if (alias.value == command)
res.push_back(alias.key);
}
return res;
}
}