From b96ab674790591715020d7e1f531ab303820244b Mon Sep 17 00:00:00 2001 From: Olivier Perret Date: Sat, 20 Oct 2018 12:36:41 +0200 Subject: [PATCH] Expose selection(s) length with a value --- doc/pages/expansions.asciidoc | 8 ++++++++ src/main.cc | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/doc/pages/expansions.asciidoc b/doc/pages/expansions.asciidoc index 6649a571..5fd57a63 100644 --- a/doc/pages/expansions.asciidoc +++ b/doc/pages/expansions.asciidoc @@ -265,6 +265,14 @@ The following expansions are supported (with required context _in italics_): unquoted list of the ranges of all selections, in the same format as `%val{selection_desc}` +*%val{selection_length}*:: + _in window scope_ + + length (in codepoints) of the main selection + +*%val{selections_length}*:: + _in window scope_ + + unquoted list of the lengths (in codepoints) of the selections + *%val{session}*:: name of the current session diff --git a/src/main.cc b/src/main.cc index 41b78527..2be8fee5 100644 --- a/src/main.cc +++ b/src/main.cc @@ -234,6 +234,16 @@ static const EnvVarDesc builtin_env_vars[] = { { "selections_desc", false, [](StringView name, const Context& context, Quoting quoting) { return selection_list_to_string(context.selections()); } + }, { + "selection_length", false, + [](StringView name, const Context& context, Quoting quoting) -> String + { return to_string(char_length(context.buffer(), context.selections().main())); } + }, { + "selections_length", false, + [](StringView name, const Context& context, Quoting quoting) + { return join(context.selections() | + transform([&](const Selection& s) + { return to_string(char_length(context.buffer(), s)); }), ' ', false); } }, { "window_width", false, [](StringView name, const Context& context, Quoting quoting) -> String