From cf0458e7348116d9166fd07cc8e008814bf80e05 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 23 Mar 2019 11:32:32 +1100 Subject: [PATCH] Add cursor_display_column expansion Fixes #2788 --- doc/pages/expansions.asciidoc | 5 +++++ src/main.cc | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/doc/pages/expansions.asciidoc b/doc/pages/expansions.asciidoc index 754cf573..49bd1d77 100644 --- a/doc/pages/expansions.asciidoc +++ b/doc/pages/expansions.asciidoc @@ -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 diff --git a/src/main.cc b/src/main.cc index 3cd9bc50..8c33629f 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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(), + coord) + 1); } }, { "cursor_byte_offset", false, [](StringView name, const Context& context, Quoting quoting) -> String