mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-15 01:11:09 +03:00
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:
parent
6239357e99
commit
6d111d4bd7
@ -18,12 +18,26 @@ public:
|
||||
|
||||
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:
|
||||
friend class Scope;
|
||||
AliasRegistry() {}
|
||||
|
||||
SafePtr<AliasRegistry> m_parent;
|
||||
HashMap<String, String, MemoryDomain::Aliases> m_aliases;
|
||||
using AliasMap = HashMap<String, String, MemoryDomain::Aliases>;
|
||||
AliasMap m_aliases;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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); })
|
||||
| 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,
|
||||
|
Loading…
Reference in New Issue
Block a user