From 8b6ed26e8ce1cd0266deeb720d17d92b43e0ceff Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 2 Jan 2020 21:27:16 +1100 Subject: [PATCH] Few style changes on history exposition code --- doc/pages/changelog.asciidoc | 5 +++++ src/buffer_utils.cc | 30 ++++++++++-------------------- src/buffer_utils.hh | 1 - test/compose/history/rc | 5 ++--- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/doc/pages/changelog.asciidoc b/doc/pages/changelog.asciidoc index fc9dd94c..25a45aa4 100644 --- a/doc/pages/changelog.asciidoc +++ b/doc/pages/changelog.asciidoc @@ -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 ``, `` are not normal mode commands diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc index fe1a4fa7..67bd97fe 100644 --- a/src/buffer_utils.cc +++ b/src/buffer_utils.cc @@ -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(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(id)); } String history_as_string(const Vector& history, Quoting quoting) @@ -251,15 +237,19 @@ String history_as_string(const Vector& 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); } } diff --git a/src/buffer_utils.hh b/src/buffer_utils.hh index a7589864..e4081568 100644 --- a/src/buffer_utils.hh +++ b/src/buffer_utils.hh @@ -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& history, Quoting quoting); String undo_group_as_string(const Buffer::UndoGroup& undo_group, Quoting quoting); diff --git a/test/compose/history/rc b/test/compose/history/rc index 931d0d1c..7f83692e 100644 --- a/test/compose/history/rc +++ b/test/compose/history/rc @@ -1,7 +1,6 @@ # Make our expansion have a predictable timestamp hook global ClientClose .* %{ - evaluate-commands %sh{ - kak -f 'ghfec$timestamp2fec$timestamp' tmp - mv tmp kak_quoted_history + nop %sh{ + kak -f 'ghfec$timestamp2fec$timestamp' kak_quoted_history } }