Re-introduce aliases in command name completion

Aliases are considered again in command name completion, but only
if they are more than 3 charactes long. This should prevent cluttering
with aliases while still letting long ones being completed.
This commit is contained in:
Maxime Coste 2018-02-20 22:09:03 +11:00
parent 6239357e99
commit 6d111d4bd7
2 changed files with 20 additions and 2 deletions

View File

@ -18,12 +18,26 @@ public:
Vector<StringView> aliases_for(StringView command) const; Vector<StringView> aliases_for(StringView command) const;
auto flatten_aliases() const
{
auto merge = [](auto&& first, const AliasMap& second) {
return concatenated(std::forward<decltype(first)>(first)
| filter([&second](auto& i) { return not second.contains(i.key); }),
second);
};
static const AliasMap empty;
auto& parent = m_parent ? m_parent->m_aliases : empty;
auto& grand_parent = (m_parent and m_parent->m_parent) ? m_parent->m_parent->m_aliases : empty;
return merge(merge(grand_parent, parent), m_aliases);
}
private: private:
friend class Scope; friend class Scope;
AliasRegistry() {} AliasRegistry() {}
SafePtr<AliasRegistry> m_parent; SafePtr<AliasRegistry> m_parent;
HashMap<String, String, MemoryDomain::Aliases> m_aliases; using AliasMap = HashMap<String, String, MemoryDomain::Aliases>;
AliasMap m_aliases;
}; };
} }

View File

@ -540,7 +540,11 @@ Completions CommandManager::complete_command_name(const Context& context, String
| filter([](const CommandMap::Item& cmd) { return not (cmd.value.flags & CommandFlags::Hidden); }) | filter([](const CommandMap::Item& cmd) { return not (cmd.value.flags & CommandFlags::Hidden); })
| transform(std::mem_fn(&CommandMap::Item::key)); | transform(std::mem_fn(&CommandMap::Item::key));
return {0, query.length(), Kakoune::complete(query, query.length(), commands)}; auto aliases = context.aliases().flatten_aliases()
| transform(std::mem_fn(&HashItem<String, String>::key))
| filter([](auto& alias) { return alias.length() > 3; });
return {0, query.length(), Kakoune::complete(query, query.length(), concatenated(commands, aliases))};
} }
Completions CommandManager::complete(const Context& context, Completions CommandManager::complete(const Context& context,