kakoune

Fork of kakoune, an acceptable text editor
git clone git://git.laack.co/kakoune.git
Log | Files | Refs

alias_registry.cc (1088B)


      1 #include "alias_registry.hh"
      2 
      3 #include "command_manager.hh"
      4 
      5 namespace Kakoune
      6 {
      7 
      8 void AliasRegistry::add_alias(String alias, String command)
      9 {
     10     kak_assert(not alias.empty());
     11     kak_assert(CommandManager::instance().command_defined(command));
     12     auto it = m_aliases.find(alias);
     13     if (it == m_aliases.end())
     14         m_aliases.insert({std::move(alias), std::move(command) });
     15     else
     16         it->value = std::move(command);
     17 }
     18 
     19 void AliasRegistry::remove_alias(StringView alias)
     20 {
     21     m_aliases.remove(alias);
     22 }
     23 
     24 StringView AliasRegistry::operator[](StringView alias) const
     25 {
     26     auto it = m_aliases.find(alias);
     27     if (it != m_aliases.end())
     28         return it->value;
     29     else if (m_parent)
     30         return (*m_parent)[alias];
     31     else
     32         return StringView{};
     33 }
     34 
     35 Vector<StringView> AliasRegistry::aliases_for(StringView command) const
     36 {
     37     Vector<StringView> res;
     38     if (m_parent)
     39         res = m_parent->aliases_for(command);
     40 
     41     for (auto& alias : m_aliases)
     42     {
     43         if (alias.value == command)
     44             res.emplace_back(alias.key);
     45     }
     46 
     47     return res;
     48 }
     49 
     50 }