1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-25 12:36:11 +03:00

Few style changes on history exposition code

This commit is contained in:
Maxime Coste 2020-01-02 21:27:16 +11:00
parent 43dc494e5c
commit 8b6ed26e8c
4 changed files with 17 additions and 24 deletions

View File

@ -3,6 +3,11 @@
This changelog contains major and/or breaking changes to Kakoune between
released versions.
== Development version
* Expose history tree through `$kak_history` and
`$kak_uncommitted_modifications`
== Kakoune 2019.12.10
* Arrow keys and `<home>`, `<end>` are not normal mode commands

View File

@ -221,23 +221,9 @@ void write_to_debug_buffer(StringView str)
InplaceString<23> to_string(Buffer::HistoryId id)
{
if (id == Buffer::HistoryId::Invalid) {
InplaceString<23> res;
res.m_data[0] = '-';
res.m_length = 1;
return res;
} else {
return to_string(static_cast<size_t>(id));
}
}
String format_modification(const Buffer::Modification& modification, Quoting quoting)
{
auto quote = quoter(quoting);
return quote(format("{}{}.{}|{}",
modification.type == Buffer::Modification::Type::Insert ? '+' : '-',
modification.coord.line, modification.coord.column,
modification.content->strview()));
if (id == Buffer::HistoryId::Invalid)
return InplaceString<23>{1, "-"};
return to_string(static_cast<size_t>(id));
}
String history_as_string(const Vector<Buffer::HistoryNode>& history, Quoting quoting)
@ -251,15 +237,19 @@ String history_as_string(const Vector<Buffer::HistoryNode>& history, Quoting quo
node.undo_group.empty() ? "" : " ",
undo_group_as_string(node.undo_group, quoting));
};
return join(history |transform(format_history_node), ' ', false);
return join(history | transform(format_history_node), ' ', false);
}
String undo_group_as_string(const Buffer::UndoGroup& undo_group, Quoting quoting)
{
auto modification_as_string = [&](const Buffer::Modification& modification) {
return format_modification(modification, quoting);
auto quote = quoter(quoting);
return quote(format("{}{}.{}|{}",
modification.type == Buffer::Modification::Type::Insert ? '+' : '-',
modification.coord.line, modification.coord.column,
modification.content->strview()));
};
return join(undo_group |transform(modification_as_string), ' ', false);
return join(undo_group | transform(modification_as_string), ' ', false);
}
}

View File

@ -85,7 +85,6 @@ void reload_file_buffer(Buffer& buffer);
void write_to_debug_buffer(StringView str);
InplaceString<23> to_string(Buffer::HistoryId id);
String format_modification(const Buffer::Modification& modification, Quoting quoting);
String history_as_string(const Vector<Buffer::HistoryNode>& history, Quoting quoting);
String undo_group_as_string(const Buffer::UndoGroup& undo_group, Quoting quoting);

View File

@ -1,7 +1,6 @@
# Make our expansion have a predictable timestamp
hook global ClientClose .* %{
evaluate-commands %sh{
kak -f 'ghf<space>ec$timestamp<esc>2f<space>ec$timestamp<esc>' <kak_quoted_history >tmp
mv tmp kak_quoted_history
nop %sh{
kak -f 'ghf<space>ec$timestamp<esc>2f<space>ec$timestamp<esc>' kak_quoted_history
}
}