From 772f85b88344e7f6d6b405c74a2239a474c1c9ac Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 12 Sep 2017 12:43:38 +0800 Subject: [PATCH] Expose the character under the cursor as $kak_cursor_char_value Fixes #142 --- README.asciidoc | 1 + doc/manpages/expansions.asciidoc | 2 ++ src/main.cc | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/README.asciidoc b/README.asciidoc index a49d5d84..1a54dd49 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -805,6 +805,7 @@ Some of Kakoune state is available through environment variables: * `kak_source`: path of the file currently getting executed (through the source command) * `kak_cursor_line`: line of the end of the main selection * `kak_cursor_column`: column of the end of the main selection (in byte) + * `kak_cursor_char_value`: unicode value of the codepoint under the cursor * `kak_cursor_char_column`: column of the end of the main selection (in character) * `kak_cursor_byte_offset`: offset of the main selection from the beginning of the buffer (in byte). * `kak_window_width`: width of the current kakoune window diff --git a/doc/manpages/expansions.asciidoc b/doc/manpages/expansions.asciidoc index 72f6daa3..9b48f64c 100644 --- a/doc/manpages/expansions.asciidoc +++ b/doc/manpages/expansions.asciidoc @@ -100,6 +100,8 @@ informations about Kakoune's state: line of the end of the main selection *kak_cursor_column*:: column of the end of the main selection (in byte) +*kak_cursor_char_value*:: + unicode value of the codepoint under the cursor *kak_cursor_char_column*:: column of the end of the main selection (in character) *kak_cursor_byte_offset*:: diff --git a/src/main.cc b/src/main.cc index 0108df17..3e970fe7 100644 --- a/src/main.cc +++ b/src/main.cc @@ -146,6 +146,12 @@ void register_env_vars() "cursor_column", false, [](StringView name, const Context& context) -> String { return to_string(context.selections().main().cursor().column + 1); } + }, { + "cursor_char_value", false, + [](StringView name, const Context& context) -> String + { auto coord = context.selections().main().cursor(); + auto& buffer = context.buffer(); + return to_string((size_t)utf8::codepoint(buffer.iterator_at(coord), buffer.end())); } }, { "cursor_char_column", false, [](StringView name, const Context& context) -> String