From 27163106c74fdee8af923daf4345f1c90f9d8b1d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 3 Jun 2018 14:46:44 +1000 Subject: [PATCH] Make register expansions expand to the full register content Now that we have a nice standard way to express lists of strings, registers can be fully exposed. An new $kak_main_reg_... env var was added to provide the previous behaviour which is relied on by doc.kak. --- doc/pages/expansions.asciidoc | 9 ++++++--- rc/base/autowrap.kak | 2 +- rc/core/doc.kak | 2 +- src/command_manager.cc | 12 +++++++++++- src/main.cc | 6 +++++- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/doc/pages/expansions.asciidoc b/doc/pages/expansions.asciidoc index 2a02cc58..381fe5e0 100644 --- a/doc/pages/expansions.asciidoc +++ b/doc/pages/expansions.asciidoc @@ -38,8 +38,8 @@ parameter: section) *reg*:: - register expansion, will expand to the content of the register named - by **. See <> + register expansion, will expand to the strings stored in the register + named by **. See <> *opt*:: option expansion, will expand to the value of the option named by @@ -114,7 +114,10 @@ informations about Kakoune's state: value of option *name* *kak_reg_*:: - value of register *r* + quoted list of value of register *r* + +*kak_main_reg_*:: + content of register *r* associated with the main selection. *kak_session*:: name of the current session diff --git a/rc/base/autowrap.kak b/rc/base/autowrap.kak index 6e6e371b..0fb12123 100644 --- a/rc/base/autowrap.kak +++ b/rc/base/autowrap.kak @@ -31,7 +31,7 @@ define-command -hidden autowrap-cursor %{ evaluate-commands -save-regs '/"|^@m' execute-keys 'p|${format_cmd}' try %{ execute-keys s\h+$ d } } - select '${kak_reg_m}' + select '${kak_main_reg_m}' " fi } diff --git a/rc/core/doc.kak b/rc/core/doc.kak index 45d1541d..73f7505c 100644 --- a/rc/core/doc.kak +++ b/rc/core/doc.kak @@ -41,7 +41,7 @@ define-command -hidden doc-parse-anchors %{ # Find sections as add them as imlicit anchors execute-keys \%s ^={2,}\h+([^\n]+)$ evaluate-commands -itersel %{ - set-option -add buffer doc_anchors "%val{selection_desc}|%sh{printf '%s' ""$kak_reg_1"" | tr '[A-Z ]' '[a-z-]'}" + set-option -add buffer doc_anchors "%val{selection_desc}|%sh{printf '%s' ""$kak_main_reg_1"" | tr '[A-Z ]' '[a-z-]'}" } # Parse explicit anchors and remove their text diff --git a/src/command_manager.cc b/src/command_manager.cc index c3dfc7c4..a554daa2 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -263,6 +263,16 @@ auto expand_option(Option& opt, std::false_type) return opt.get_as_strings(); } +auto expand_register(StringView reg, const Context& context, std::true_type) +{ + return join(RegisterManager::instance()[reg].get(context) | transform(quote), ' ', false); +} + +auto expand_register(StringView reg, const Context& context, std::false_type) +{ + return RegisterManager::instance()[reg].get(context) | gather>(); +} + String expand_arobase(ConstArrayView params, std::true_type) { return join(params, ' ', false); @@ -298,7 +308,7 @@ expand_token(const Token& token, const Context& context, const ShellContext& she return {str}; } case Token::Type::RegisterExpand: - return {context.main_sel_register_value(content).str()}; + return expand_register(content, context, IsSingle{}); case Token::Type::OptionExpand: return expand_option(context.options()[content], IsSingle{}); case Token::Type::ValExpand: diff --git a/src/main.cc b/src/main.cc index c5c962a0..cecf0d1d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -132,10 +132,14 @@ static const EnvVarDesc builtin_env_vars[] = { { "opt_", true, [](StringView name, const Context& context) { return context.options()[name.substr(4_byte)].get_as_string(); } + }, { + "main_reg_", true, + [](StringView name, const Context& context) + { return context.main_sel_register_value(name.substr(9_byte)).str(); } }, { "reg_", true, [](StringView name, const Context& context) - { return context.main_sel_register_value(name.substr(4_byte)).str(); } + { return join(RegisterManager::instance()[name.substr(4_byte)].get(context) | transform(quote), ' ', false); } }, { "client_env_", true, [](StringView name, const Context& context)