diff --git a/README.asciidoc b/README.asciidoc index 15a58b5f..1d797c0e 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -712,6 +712,7 @@ Some of Kakoune state is available through environment variables: * `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_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 * `kak_window_height`: height of the current kakoune window * `kak_hook_param`: filtering text passed to the currently executing hook diff --git a/src/main.cc b/src/main.cc index 15c2a867..9a50ec46 100644 --- a/src/main.cc +++ b/src/main.cc @@ -114,6 +114,11 @@ void register_env_vars() [](StringView name, const Context& context) -> String { auto coord = context.selections().main().cursor(); return to_string(context.buffer()[coord.line].char_count_to(coord.column) + 1); } + }, { + "cursor_byte_offset", false, + [](StringView name, const Context& context) -> String + { auto cursor = context.selections().main().cursor(); + return to_string(context.buffer().distance(context.buffer().begin().coord(), cursor)); } }, { "selection_desc", false, [](StringView name, const Context& context)