From 2693c8cc21390df8b6d6c26951dd8c8301b6c306 Mon Sep 17 00:00:00 2001 From: xenia Date: Wed, 11 Oct 2023 19:36:16 +0200 Subject: [PATCH] Add zero-indexed register --- src/input_handler.cc | 1 + src/main.cc | 11 +++++++++++ src/register_manager.cc | 1 + 3 files changed, 13 insertions(+) diff --git a/src/input_handler.cc b/src/input_handler.cc index 99fb684e..fa4aeb2d 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -205,6 +205,7 @@ constexpr StringView register_doc = "%: buffer name\n" ".: selection contents\n" "#: selection index\n" + "$: selection index (zero-indexed)\n" "_: null register\n" "\": default yank/paste register\n" "@: default macro register\n" diff --git a/src/main.cc b/src/main.cc index e0044db0..9eb392a6 100644 --- a/src/main.cc +++ b/src/main.cc @@ -445,6 +445,17 @@ void register_registers() return res; })); + register_manager.add_register('$', make_dyn_reg( + "$", + [](const Context& context) { + const size_t count = context.selections().size(); + StringList res; + res.reserve(count); + for (size_t i = 0; i < count; ++i) + res.push_back(to_string((int)i)); + return res; + })); + for (size_t i = 0; i < 10; ++i) { register_manager.add_register('0'+i, make_dyn_reg( diff --git a/src/register_manager.cc b/src/register_manager.cc index 16db41ba..4642b8e9 100644 --- a/src/register_manager.cc +++ b/src/register_manager.cc @@ -67,6 +67,7 @@ static const HashMap reg_names { { "percent", '%' }, { "dot", '.' }, { "hash", '#' }, + { "dollar", '$' }, { "underscore", '_' }, { "colon", ':' } };