2014-10-30 00:22:54 +01:00
|
|
|
#include "alias_registry.hh"
|
|
|
|
|
|
|
|
#include "command_manager.hh"
|
2015-11-17 14:55:27 +01:00
|
|
|
#include "containers.hh"
|
2014-10-30 00:22:54 +01:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
void AliasRegistry::add_alias(String alias, String command)
|
|
|
|
{
|
|
|
|
kak_assert(not alias.empty());
|
|
|
|
kak_assert(CommandManager::instance().command_defined(command));
|
2015-11-17 14:55:27 +01:00
|
|
|
auto it = m_aliases.find(alias);
|
|
|
|
if (it == m_aliases.end())
|
2017-03-07 02:12:37 +01:00
|
|
|
m_aliases.insert({std::move(alias), std::move(command) });
|
2015-11-17 14:55:27 +01:00
|
|
|
else
|
|
|
|
it->value = std::move(command);
|
2014-10-30 00:22:54 +01:00
|
|
|
}
|
|
|
|
|
2015-09-16 23:32:02 +02:00
|
|
|
void AliasRegistry::remove_alias(StringView alias)
|
2014-10-30 00:22:54 +01:00
|
|
|
{
|
2017-03-06 20:44:36 +01:00
|
|
|
m_aliases.remove(alias);
|
2014-10-30 00:22:54 +01:00
|
|
|
}
|
|
|
|
|
2015-09-16 23:32:02 +02:00
|
|
|
StringView AliasRegistry::operator[](StringView alias) const
|
2014-10-30 00:22:54 +01:00
|
|
|
{
|
|
|
|
auto it = m_aliases.find(alias);
|
|
|
|
if (it != m_aliases.end())
|
2015-09-16 23:32:02 +02:00
|
|
|
return it->value;
|
2014-10-30 00:22:54 +01:00
|
|
|
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
|
2014-10-30 00:22:54 +01:00
|
|
|
{
|
2015-01-12 14:58:41 +01:00
|
|
|
Vector<StringView> res;
|
2014-10-30 00:22:54 +01:00
|
|
|
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)
|
2017-01-08 23:30:15 +01:00
|
|
|
res.emplace_back(alias.key);
|
2014-10-30 00:22:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|