commands: add "registers" subcommand to :debug

This prints all non-empty registers and their value(s) to the `*debug*`
buffer.
This commit is contained in:
Cole Helbling 2020-12-23 01:30:55 -08:00
parent 16547a1d46
commit 266e388c6b
No known key found for this signature in database
GPG Key ID: B37E0F2371016A4C
2 changed files with 18 additions and 1 deletions

View File

@ -1392,7 +1392,7 @@ const CommandDesc debug_cmd = {
[](const Context& context, CompletionFlags flags,
const String& prefix, ByteCount cursor_pos) -> Completions {
auto c = {"info", "buffers", "options", "memory", "shared-strings",
"profile-hash-maps", "faces", "mappings", "regex"};
"profile-hash-maps", "faces", "mappings", "regex", "registers"};
return { 0_byte, cursor_pos, complete(prefix, cursor_pos, c) };
}),
[](const ParametersParser& parser, Context& context, const ShellContext&)
@ -1485,6 +1485,20 @@ const CommandDesc debug_cmd = {
write_to_debug_buffer(format(" * {}:\n{}",
parser[1], dump_regex(compile_regex(parser[1], RegexCompileFlags::Optimize))));
}
else if (parser[0] == "registers")
{
write_to_debug_buffer("Register info:");
for (auto&& [name, reg] : RegisterManager::instance())
{
auto content = reg->get(context);
if (content.size() == 1 and content[0] == "")
continue;
write_to_debug_buffer(format(" * {} = {}\n", name,
join(content | transform(quote), "\n = ")));
}
}
else
throw runtime_error(format("no such debug command: '{}'", parser[0]));
}

View File

@ -124,6 +124,9 @@ public:
void add_register(Codepoint c, std::unique_ptr<Register> reg);
CandidateList complete_register_name(StringView prefix, ByteCount cursor_pos) const;
auto begin() const { return m_registers.begin(); }
auto end() const { return m_registers.end(); }
protected:
HashMap<Codepoint, std::unique_ptr<Register>, MemoryDomain::Registers> m_registers;
};