Add cursor_display_column expansion

Fixes #2788
This commit is contained in:
Maxime Coste 2019-03-23 11:32:32 +11:00
parent 18a9724a83
commit cf0458e734
2 changed files with 12 additions and 0 deletions

View File

@ -230,6 +230,11 @@ The following expansions are supported (with required context _in italics_):
contains full-width codepoints (which occupy two columns) or zero-width
codepoints
*%val{cursor_display_column}*::
_in window scope_ +
1-based offset from the start of the line to the cursor position in
display column, taking into account tabs and character width.
*%val{cursor_char_value}*::
_in window scope_ +
unicode value of the codepoint under the main cursor

View File

@ -226,6 +226,13 @@ static const EnvVarDesc builtin_env_vars[] = { {
[](StringView name, const Context& context, Quoting quoting) -> String
{ auto coord = context.selections().main().cursor();
return to_string(context.buffer()[coord.line].char_count_to(coord.column) + 1); }
}, {
"cursor_display_column", false,
[](StringView name, const Context& context, Quoting quoting) -> String
{ auto coord = context.selections().main().cursor();
return to_string(get_column(context.buffer(),
context.options()["tabstop"].get<int>(),
coord) + 1); }
}, {
"cursor_byte_offset", false,
[](StringView name, const Context& context, Quoting quoting) -> String