Skip to content

Commit 2eb6aa9

Browse files
committed
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} }
1 parent c24c802 commit 2eb6aa9

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

doc/pages/expansions.asciidoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ The following expansions are supported (with required context _in italics_):
305305
history), and each _modification_ is presented as in
306306
`%val{uncommitted_modifications}`.
307307

308+
*%val{history_since_id}*::
309+
_in buffer, window scope_ +
310+
a partial history of the buffer in the same format as `%val{history}`
311+
starting after entry _id_
312+
308313
*%val{history_id}*::
309314
_in buffer, window scope_ +
310315
history id of the current buffer, an integer value which refers to a

src/buffer_utils.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ static String modification_as_string(const Buffer::Modification& modification)
392392
modification.content->strview());
393393
}
394394

395-
Vector<String> history_as_strings(const Vector<Buffer::HistoryNode>& history)
395+
Vector<String> history_as_strings(ConstArrayView<Buffer::HistoryNode> history)
396396
{
397397
Vector<String> res;
398398
for (auto& node : history)

src/buffer_utils.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void write_buffer_to_backup_file(Buffer& buffer);
9797

9898
void write_to_debug_buffer(StringView str);
9999

100-
Vector<String> history_as_strings(const Vector<Buffer::HistoryNode>& history);
100+
Vector<String> history_as_strings(ConstArrayView<Buffer::HistoryNode> history);
101101
Vector<String> undo_group_as_strings(const Buffer::UndoGroup& undo_group);
102102

103103
String generate_buffer_name(StringView pattern);

src/main.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,13 @@ static const EnvVarDesc builtin_env_vars[] = { {
412412
"history", false,
413413
[](StringView name, const Context& context) -> Vector<String>
414414
{ return history_as_strings(context.buffer().history()); }
415+
}, {
416+
"history_since_", true,
417+
[](StringView name, const Context& context) -> Vector<String>
418+
{ return history_as_strings(
419+
ArrayView(context.buffer().history())
420+
.subrange(str_to_int(name.substr(14_byte)) + 1)
421+
); }
415422
}, {
416423
"uncommitted_modifications", false,
417424
[](StringView name, const Context& context) -> Vector<String>

0 commit comments

Comments
 (0)