diff --git a/src/main.cc b/src/main.cc index 91d26f25..cd078d6c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -58,7 +58,7 @@ String runtime_directory() void register_env_vars() { struct EnvVarDesc { const char* name; String (*func)(const String&, const Context&); }; - EnvVarDesc env_vars[] = { { + static const EnvVarDesc env_vars[] = { { "bufname", [](const String& name, const Context& context) { return context.buffer().display_name(); } @@ -135,10 +135,18 @@ void register_env_vars() void register_registers() { - RegisterManager& register_manager = RegisterManager::instance(); + using StringList = std::vector; + struct DynRegDesc { char name; StringList (*func)(const Context&); }; + static const DynRegDesc dyn_regs[] = { + { '%', [](const Context& context) { return StringList{{context.buffer().display_name()}}; } }, + { '.', [](const Context& context) { return context.editor().selections_content(); } }, + { '#', [](const Context& context) { return StringList{{to_string((int)context.editor().selections().size())}}; } }, + }; + + RegisterManager& register_manager = RegisterManager::instance(); + for (auto& dyn_reg : dyn_regs) + register_manager.register_dynamic_register(dyn_reg.name, dyn_reg.func); - register_manager.register_dynamic_register('%', [](const Context& context) { return std::vector(1, context.buffer().display_name()); }); - register_manager.register_dynamic_register('.', [](const Context& context) { return context.editor().selections_content(); }); for (size_t i = 0; i < 10; ++i) { register_manager.register_dynamic_register('0'+i,