Expose selection(s) length with a value

This commit is contained in:
Olivier Perret 2018-10-20 12:36:41 +02:00 committed by Maxime Coste
parent 8c2c3d27ad
commit b96ab67479
2 changed files with 18 additions and 0 deletions

View File

@ -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 unquoted list of the ranges of all selections, in the same format as
`%val{selection_desc}` `%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}*:: *%val{session}*::
name of the current session name of the current session

View File

@ -234,6 +234,16 @@ static const EnvVarDesc builtin_env_vars[] = { {
"selections_desc", false, "selections_desc", false,
[](StringView name, const Context& context, Quoting quoting) [](StringView name, const Context& context, Quoting quoting)
{ return selection_list_to_string(context.selections()); } { 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, "window_width", false,
[](StringView name, const Context& context, Quoting quoting) -> String [](StringView name, const Context& context, Quoting quoting) -> String