From 84379f446662d20ef23244cabf0df02e6d3251bb Mon Sep 17 00:00:00 2001 From: Olivier Perret Date: Fri, 4 Nov 2022 19:16:38 +0100 Subject: [PATCH] Add a %val{selection_count} expansion --- doc/pages/expansions.asciidoc | 4 ++++ src/main.cc | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/doc/pages/expansions.asciidoc b/doc/pages/expansions.asciidoc index 674f5707..81ccd7b7 100644 --- a/doc/pages/expansions.asciidoc +++ b/doc/pages/expansions.asciidoc @@ -373,6 +373,10 @@ The following expansions are supported (with required context _in italics_): _in window scope_ + unquoted list of the lengths (in codepoints) of the selections +*%val{selection_count}*:: + _in window scope_ + + the number of selections + *%val{session}*:: name of the current session diff --git a/src/main.cc b/src/main.cc index 08baed94..2b09ccd6 100644 --- a/src/main.cc +++ b/src/main.cc @@ -349,6 +349,10 @@ static const EnvVarDesc builtin_env_vars[] = { { transform([&](const Selection& s) -> String { return to_string(char_length(context.buffer(), s)); }) | gather>(); } + }, { + "selection_count", false, + [](StringView name, const Context& context) -> Vector + { return {to_string(context.selections().size())}; } }, { "window_width", false, [](StringView name, const Context& context) -> Vector