summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Jungkamp <p.jungkamp@gmx.net>2025-07-05 00:24:54 +0200
committerPhilipp Jungkamp <p.jungkamp@gmx.net>2025-07-05 00:24:54 +0200
commit2eb6aa9e20901c53ec7c288d47592043649b1bbd (patch)
tree743d84905db6fc0bf578654528fdb7be93375ad9 /src
parentc24c802373fc223fb80f1b80419ce6dcc59f2836 (diff)
Introduce `history_since_<id>` value expansion
The `history_since_<id>` value expansion allows incremental parsing of a buffer's history. declare-option int my_last_history_id define-command my-process-history ... # process the initial buffer history my-process-history %val{bufname} 0 %val{history} set-option buffer my_last_history_id 0 # only process new history changes on idle hook buffer NormalIdle %{ evaluate-commands %exp{ my-process-history \ %%val{bufname} \ %%opt{my_last_history_id} \ %%val{history_since_%opt{my_last_history_id}} } set-option buffer my_last_history_id %val{history_id} }
Diffstat (limited to 'src')
-rw-r--r--src/buffer_utils.cc2
-rw-r--r--src/buffer_utils.hh2
-rw-r--r--src/main.cc7
3 files changed, 9 insertions, 2 deletions
diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc
index a2d2e709..994dbd23 100644
--- a/src/buffer_utils.cc
+++ b/src/buffer_utils.cc
@@ -392,7 +392,7 @@ static String modification_as_string(const Buffer::Modification& modification)
modification.content->strview());
}
-Vector<String> history_as_strings(const Vector<Buffer::HistoryNode>& history)
+Vector<String> history_as_strings(ConstArrayView<Buffer::HistoryNode> history)
{
Vector<String> res;
for (auto& node : history)
diff --git a/src/buffer_utils.hh b/src/buffer_utils.hh
index 96e89743..f677c34e 100644
--- a/src/buffer_utils.hh
+++ b/src/buffer_utils.hh
@@ -97,7 +97,7 @@ void write_buffer_to_backup_file(Buffer& buffer);
void write_to_debug_buffer(StringView str);
-Vector<String> history_as_strings(const Vector<Buffer::HistoryNode>& history);
+Vector<String> history_as_strings(ConstArrayView<Buffer::HistoryNode> history);
Vector<String> undo_group_as_strings(const Buffer::UndoGroup& undo_group);
String generate_buffer_name(StringView pattern);
diff --git a/src/main.cc b/src/main.cc
index bf382dd2..fb78669d 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -413,6 +413,13 @@ static const EnvVarDesc builtin_env_vars[] = { {
[](StringView name, const Context& context) -> Vector<String>
{ return history_as_strings(context.buffer().history()); }
}, {
+ "history_since_", true,
+ [](StringView name, const Context& context) -> Vector<String>
+ { return history_as_strings(
+ ArrayView(context.buffer().history())
+ .subrange(str_to_int(name.substr(14_byte)) + 1)
+ ); }
+ }, {
"uncommitted_modifications", false,
[](StringView name, const Context& context) -> Vector<String>
{ return undo_group_as_strings(context.buffer().current_undo_group()); }