vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit e627df41fb121f1db75902406d05d91074718fab
parent 502340a5f7d27b71126cd84293ccdb0381b5ff24
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Wed,  9 Nov 2016 13:52:17 +0100

vis: perform undo snapshotting more rarerly

Do not take snapshots after every operation in insert/replace mode.
As an example up until now we would take a snapshot after every
<Backspace>/<Delete> press, hence when undoing changes each character
would be restored individually. The same applies for <C-w> and related
actions.

From now on we only snaphost when:

 - transitioning from insert/replace mode to normal mode (but not when
   switching to operator pending mode)

 - an operation takes place from normal mode

 - an idle time expires in normal/replace mode

Diffstat:
Mvis-modes.c | 14++++++++------
Mvis.c | 4+++-
2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/vis-modes.c b/vis-modes.c @@ -132,10 +132,11 @@ static void vis_mode_insert_enter(Vis *vis, Mode *old) { } static void vis_mode_insert_leave(Vis *vis, Mode *new) { - /* make sure we can recover the current state after an editing operation */ - text_snapshot(vis->win->file->text); - if (new == mode_get(vis, VIS_MODE_NORMAL)) + if (new == mode_get(vis, VIS_MODE_NORMAL)) { + /* make sure we can recover the current state after an editing operation */ + text_snapshot(vis->win->file->text); macro_operator_stop(vis); + } } static void vis_mode_insert_idle(Vis *vis) { @@ -161,10 +162,11 @@ static void vis_mode_replace_enter(Vis *vis, Mode *old) { } static void vis_mode_replace_leave(Vis *vis, Mode *new) { - /* make sure we can recover the current state after an editing operation */ - text_snapshot(vis->win->file->text); - if (new == mode_get(vis, VIS_MODE_NORMAL)) + if (new == mode_get(vis, VIS_MODE_NORMAL)) { + /* make sure we can recover the current state after an editing operation */ + text_snapshot(vis->win->file->text); macro_operator_stop(vis); + } } static void vis_mode_replace_input(Vis *vis, const char *str, size_t len) { diff --git a/vis.c b/vis.c @@ -718,7 +718,9 @@ void vis_do(Vis *vis) { } else if (vis->mode->visual) { vis_mode_switch(vis, VIS_MODE_NORMAL); } - text_snapshot(txt); + + if (vis->mode == &vis_modes[VIS_MODE_NORMAL]) + text_snapshot(txt); vis_draw(vis); }