From b3ac4d86b63cc21ee7a872ca099f06188e6e54a0 Mon Sep 17 00:00:00 2001
From: Francesco Magliocca <franciman12@gmail.com>
Date: Sat, 2 Sep 2017 12:14:19 +0200
Subject: [PATCH 1/3] Add current history id to env variables

---
 src/main.cc | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/main.cc b/src/main.cc
index 81ad37bc..79a55965 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -93,6 +93,10 @@ void register_env_vars()
             "timestamp", false,
             [](StringView name, const Context& context) -> String
             { return to_string(context.buffer().timestamp()); }
+        }, {
+            "curr_history_id", false,
+            [](StringView name, const Context& context) -> String
+            { return to_string(context.buffer().current_history_id()); }
         }, {
             "selection", false,
             [](StringView name, const Context& context)

From a903824ca6071c2edbdac02a532af96063ee6d74 Mon Sep 17 00:00:00 2001
From: Francesco Magliocca <franciman12@gmail.com>
Date: Sun, 3 Sep 2017 20:48:28 +0200
Subject: [PATCH 2/3] Add documentation for curr_history_id

---
 README.asciidoc                  | 2 ++
 doc/manpages/expansions.asciidoc | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/README.asciidoc b/README.asciidoc
index 39aef0f1..00f618ad 100644
--- a/README.asciidoc
+++ b/README.asciidoc
@@ -792,6 +792,8 @@ Some of Kakoune state is available through environment variables:
  * `kak_buf_line_count`: the current buffer line count
  * `kak_timestamp`: timestamp of the current buffer, the timestamp is an
        integer value which is incremented each time the buffer is modified.
+ * `kak_curr_history_id`: history id of the current buffer, the history id is an integer value
+       which is used to reference a specific buffer version in the undo tree
  * `kak_runtime`: directory containing the kak binary
  * `kak_count`: count parameter passed to the command
  * `kak_opt_<name>`: value of option <name>
diff --git a/doc/manpages/expansions.asciidoc b/doc/manpages/expansions.asciidoc
index 5e4bdc79..3f01bb84 100644
--- a/doc/manpages/expansions.asciidoc
+++ b/doc/manpages/expansions.asciidoc
@@ -74,6 +74,9 @@ informations about Kakoune's state:
 *kak_timestamp*::
 	timestamp of the current buffer, the timestamp is an integer value
 	which is incremented each time the buffer is modified
+*kak_curr_history_id*::
+	history id of the current buffer, the history id is an integer value
+	which is used to reference a specific buffer version in the undo tree
 *kak_runtime*::
 	directory containing the kak binary
 *kak_count*::

From d4fa94c3564738f642027e352bdabb67f0bc2471 Mon Sep 17 00:00:00 2001
From: Francesco Magliocca <franciman12@gmail.com>
Date: Mon, 4 Sep 2017 16:41:27 +0200
Subject: [PATCH 3/3] Rename env variable kak_curr_history_id to kak_history_id

---
 README.asciidoc                  | 2 +-
 doc/manpages/expansions.asciidoc | 2 +-
 src/main.cc                      | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/README.asciidoc b/README.asciidoc
index 00f618ad..2c96216a 100644
--- a/README.asciidoc
+++ b/README.asciidoc
@@ -792,7 +792,7 @@ Some of Kakoune state is available through environment variables:
  * `kak_buf_line_count`: the current buffer line count
  * `kak_timestamp`: timestamp of the current buffer, the timestamp is an
        integer value which is incremented each time the buffer is modified.
- * `kak_curr_history_id`: history id of the current buffer, the history id is an integer value
+ * `kak_history_id`: history id of the current buffer, the history id is an integer value
        which is used to reference a specific buffer version in the undo tree
  * `kak_runtime`: directory containing the kak binary
  * `kak_count`: count parameter passed to the command
diff --git a/doc/manpages/expansions.asciidoc b/doc/manpages/expansions.asciidoc
index 3f01bb84..72f6daa3 100644
--- a/doc/manpages/expansions.asciidoc
+++ b/doc/manpages/expansions.asciidoc
@@ -74,7 +74,7 @@ informations about Kakoune's state:
 *kak_timestamp*::
 	timestamp of the current buffer, the timestamp is an integer value
 	which is incremented each time the buffer is modified
-*kak_curr_history_id*::
+*kak_history_id*::
 	history id of the current buffer, the history id is an integer value
 	which is used to reference a specific buffer version in the undo tree
 *kak_runtime*::
diff --git a/src/main.cc b/src/main.cc
index 79a55965..bcedab05 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -94,7 +94,7 @@ void register_env_vars()
             [](StringView name, const Context& context) -> String
             { return to_string(context.buffer().timestamp()); }
         }, {
-            "curr_history_id", false,
+            "history_id", false,
             [](StringView name, const Context& context) -> String
             { return to_string(context.buffer().current_history_id()); }
         }, {