Merge remote-tracking branch 'lenormf/complete-expansion-reg'
This commit is contained in:
commit
a933cae7b9
|
@ -676,6 +676,11 @@ Completions CommandManager::complete(const Context& context,
|
||||||
|
|
||||||
switch (token.type)
|
switch (token.type)
|
||||||
{
|
{
|
||||||
|
case Token::Type::RegisterExpand:
|
||||||
|
return {start , cursor_pos,
|
||||||
|
RegisterManager::instance().complete_register_name(
|
||||||
|
token.content, cursor_pos_in_token) };
|
||||||
|
|
||||||
case Token::Type::OptionExpand:
|
case Token::Type::OptionExpand:
|
||||||
return {start , cursor_pos,
|
return {start , cursor_pos,
|
||||||
GlobalScope::instance().option_registry().complete_option_name(
|
GlobalScope::instance().option_registry().complete_option_name(
|
||||||
|
|
|
@ -7,23 +7,24 @@
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
|
static const HashMap<String, Codepoint> reg_names = {
|
||||||
|
{ "slash", '/' },
|
||||||
|
{ "dquote", '"' },
|
||||||
|
{ "pipe", '|' },
|
||||||
|
{ "caret", '^' },
|
||||||
|
{ "arobase", '@' },
|
||||||
|
{ "percent", '%' },
|
||||||
|
{ "dot", '.' },
|
||||||
|
{ "hash", '#' },
|
||||||
|
{ "underscore", '_' },
|
||||||
|
{ "colon", ':' }
|
||||||
|
};
|
||||||
|
|
||||||
Register& RegisterManager::operator[](StringView reg) const
|
Register& RegisterManager::operator[](StringView reg) const
|
||||||
{
|
{
|
||||||
if (reg.length() == 1)
|
if (reg.length() == 1)
|
||||||
return (*this)[reg[0_byte]];
|
return (*this)[reg[0_byte]];
|
||||||
|
|
||||||
static const HashMap<String, Codepoint> reg_names = {
|
|
||||||
{ "slash", '/' },
|
|
||||||
{ "dquote", '"' },
|
|
||||||
{ "pipe", '|' },
|
|
||||||
{ "caret", '^' },
|
|
||||||
{ "arobase", '@' },
|
|
||||||
{ "percent", '%' },
|
|
||||||
{ "dot", '.' },
|
|
||||||
{ "hash", '#' },
|
|
||||||
{ "underscore", '_' },
|
|
||||||
{ "colon", ':' }
|
|
||||||
};
|
|
||||||
auto it = reg_names.find(reg);
|
auto it = reg_names.find(reg);
|
||||||
if (it == reg_names.end())
|
if (it == reg_names.end())
|
||||||
throw runtime_error(format("no such register: '{}'", reg));
|
throw runtime_error(format("no such register: '{}'", reg));
|
||||||
|
@ -47,4 +48,9 @@ void RegisterManager::add_register(Codepoint c, std::unique_ptr<Register> reg)
|
||||||
reg_ptr = std::move(reg);
|
reg_ptr = std::move(reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CandidateList RegisterManager::complete_register_name(StringView prefix, ByteCount cursor_pos) const
|
||||||
|
{
|
||||||
|
return complete(prefix, cursor_pos, reg_names | transform([](auto& i) { return i.key; }) | gather<Vector<String>>());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define register_manager_hh_INCLUDED
|
#define register_manager_hh_INCLUDED
|
||||||
|
|
||||||
#include "array_view.hh"
|
#include "array_view.hh"
|
||||||
|
#include "completion.hh"
|
||||||
#include "exception.hh"
|
#include "exception.hh"
|
||||||
#include "utils.hh"
|
#include "utils.hh"
|
||||||
#include "hash_map.hh"
|
#include "hash_map.hh"
|
||||||
|
@ -146,6 +147,7 @@ public:
|
||||||
Register& operator[](StringView reg) const;
|
Register& operator[](StringView reg) const;
|
||||||
Register& operator[](Codepoint c) const;
|
Register& operator[](Codepoint c) const;
|
||||||
void add_register(Codepoint c, std::unique_ptr<Register> reg);
|
void add_register(Codepoint c, std::unique_ptr<Register> reg);
|
||||||
|
CandidateList complete_register_name(StringView prefix, ByteCount cursor_pos) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
HashMap<Codepoint, std::unique_ptr<Register>, MemoryDomain::Registers> m_registers;
|
HashMap<Codepoint, std::unique_ptr<Register>, MemoryDomain::Registers> m_registers;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user