kakoune/src/alias_registry.cc
Maxime Coste 185b980718 Add scoped aliases
aliases are now stored in window, buffer, or globally.
2014-10-30 14:02:13 +00:00

49 lines
1.0 KiB
C++

#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));
m_aliases[alias] = std::move(command);
}
void AliasRegistry::remove_alias(const String& alias)
{
auto it = m_aliases.find(alias);
if (it != m_aliases.end())
m_aliases.erase(it);
}
StringView AliasRegistry::operator[](const String& alias) const
{
auto it = m_aliases.find(alias);
if (it != m_aliases.end())
return it->second;
else if (m_parent)
return (*m_parent)[alias];
else
return StringView{};
}
std::vector<StringView> AliasRegistry::aliases_for(StringView command) const
{
std::vector<StringView> res;
if (m_parent)
res = m_parent->aliases_for(command);
for (auto& alias : m_aliases)
{
if (alias.second == command)
res.push_back(alias.first);
}
return res;
}
}