1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-25 04:24:48 +03:00

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
`%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

View File

@ -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