Expose the character under the cursor as $kak_cursor_char_value

Fixes #142
This commit is contained in:
Maxime Coste 2017-09-12 12:43:38 +08:00
parent 6fefe66415
commit 772f85b883
3 changed files with 9 additions and 0 deletions

View File

@ -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_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_line`: line of the end of the main selection
* `kak_cursor_column`: column of the end of the main selection (in byte) * `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_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_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 * `kak_window_width`: width of the current kakoune window

View File

@ -100,6 +100,8 @@ informations about Kakoune's state:
line of the end of the main selection line of the end of the main selection
*kak_cursor_column*:: *kak_cursor_column*::
column of the end of the main selection (in byte) 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*:: *kak_cursor_char_column*::
column of the end of the main selection (in character) column of the end of the main selection (in character)
*kak_cursor_byte_offset*:: *kak_cursor_byte_offset*::

View File

@ -146,6 +146,12 @@ void register_env_vars()
"cursor_column", false, "cursor_column", false,
[](StringView name, const Context& context) -> String [](StringView name, const Context& context) -> String
{ return to_string(context.selections().main().cursor().column + 1); } { 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, "cursor_char_column", false,
[](StringView name, const Context& context) -> String [](StringView name, const Context& context) -> String