aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vis-core.h1
-rw-r--r--vis-modes.c6
-rw-r--r--vis.c27
-rw-r--r--vis.h3
4 files changed, 29 insertions, 8 deletions
diff --git a/vis-core.h b/vis-core.h
index b5a44ff..debd994 100644
--- a/vis-core.h
+++ b/vis-core.h
@@ -160,6 +160,7 @@ struct Vis {
Win *message_window; /* special window to display multi line messages */
Register registers[VIS_REG_INVALID]; /* registers used for text manipulations yank/put etc. and macros */
Macro *recording, *last_recording; /* currently (if non NULL) and least recently recorded macro */
+ const Macro *replaying; /* macro currently being replayed */
Macro *macro_operator; /* special macro used to repeat certain operators */
Mode *mode_before_prompt; /* user mode which was active before entering prompt */
char search_char[8]; /* last used character to search for via 'f', 'F', 't', 'T' */
diff --git a/vis-modes.c b/vis-modes.c
index 8df7b16..c3ade9f 100644
--- a/vis-modes.c
+++ b/vis-modes.c
@@ -190,13 +190,13 @@ static void vis_mode_insert_enter(Vis *vis, Mode *old) {
static void vis_mode_insert_leave(Vis *vis, Mode *new) {
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);
+ vis_file_snapshot(vis, vis->win->file);
macro_operator_stop(vis);
}
}
static void vis_mode_insert_idle(Vis *vis) {
- text_snapshot(vis->win->file->text);
+ vis_file_snapshot(vis, vis->win->file);
}
static void vis_mode_insert_input(Vis *vis, const char *str, size_t len) {
@@ -220,7 +220,7 @@ static void vis_mode_replace_enter(Vis *vis, Mode *old) {
static void vis_mode_replace_leave(Vis *vis, Mode *new) {
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);
+ vis_file_snapshot(vis, vis->win->file);
macro_operator_stop(vis);
}
}
diff --git a/vis.c b/vis.c
index a89cb8d..ab2f244 100644
--- a/vis.c
+++ b/vis.c
@@ -56,6 +56,7 @@ const RegisterDef vis_registers[] = {
static Macro *macro_get(Vis *vis, enum VisRegister);
static void macro_replay(Vis *vis, const Macro *macro);
+static void macro_replay_internal(Vis *vis, const Macro *macro);
static void vis_keys_push(Vis *vis, const char *input, size_t pos, bool record);
bool vis_event_emit(Vis *vis, enum VisEvents id, ...) {
@@ -673,7 +674,8 @@ static void window_jumplist_invalidate(Win *win) {
void vis_do(Vis *vis) {
Win *win = vis->win;
- Text *txt = win->file->text;
+ File *file = win->file;
+ Text *txt = file->text;
View *view = win->view;
Action *a = &vis->action;
@@ -693,7 +695,7 @@ void vis_do(Vis *vis) {
size_t pos = view_cursors_pos(cursor);
Register *reg = multiple_cursors ? view_cursors_register(cursor) : a->reg;
if (!reg)
- reg = &vis->registers[win->file->internal ? VIS_REG_PROMPT : VIS_REG_DEFAULT];
+ reg = &vis->registers[file->internal ? VIS_REG_PROMPT : VIS_REG_DEFAULT];
OperatorContext c = {
.count = count,
@@ -714,7 +716,7 @@ void vis_do(Vis *vis) {
else if (a->movement->cur)
pos = a->movement->cur(cursor);
else if (a->movement->file)
- pos = a->movement->file(vis, vis->win->file, pos);
+ pos = a->movement->file(vis, file, pos);
else if (a->movement->vis)
pos = a->movement->vis(vis, txt, pos);
else if (a->movement->view)
@@ -844,7 +846,7 @@ void vis_do(Vis *vis) {
}
if (vis->mode == &vis_modes[VIS_MODE_NORMAL])
- text_snapshot(txt);
+ vis_file_snapshot(vis, file);
vis_draw(vis);
}
@@ -1038,7 +1040,8 @@ void vis_keys_feed(Vis *vis, const char *input) {
macro_init(&macro);
if (!macro_append(&macro, input))
return;
- macro_replay(vis, &macro);
+ /* use internal function, to keep Lua based tests which use undo points working */
+ macro_replay_internal(vis, &macro);
macro_release(&macro);
}
@@ -1230,6 +1233,13 @@ bool vis_macro_recording(Vis *vis) {
}
static void macro_replay(Vis *vis, const Macro *macro) {
+ const Macro *replaying = vis->replaying;
+ vis->replaying = macro;
+ macro_replay_internal(vis, macro);
+ vis->replaying = replaying;
+}
+
+static void macro_replay_internal(Vis *vis, const Macro *macro) {
size_t pos = buffer_length0(vis->keys);
for (char *key = macro->data, *next; key; key = next) {
char tmp;
@@ -1258,6 +1268,7 @@ bool vis_macro_replay(Vis *vis, enum VisRegister id) {
if (!macro || macro == vis->recording)
return false;
macro_replay(vis, macro);
+ vis_file_snapshot(vis, vis->win->file);
return true;
}
@@ -1293,6 +1304,7 @@ void vis_repeat(Vis *vis) {
vis->action_prev = action_prev;
}
vis_cancel(vis);
+ vis_file_snapshot(vis, vis->win->file);
}
enum VisMark vis_mark_from(Vis *vis, char mark) {
@@ -1644,6 +1656,11 @@ bool vis_cmd(Vis *vis, const char *cmdline) {
return err == SAM_ERR_OK;
}
+void vis_file_snapshot(Vis *vis, File *file) {
+ if (!vis->replaying)
+ text_snapshot(file->text);
+}
+
Text *vis_text(Vis *vis) {
return vis->win->file->text;
}
diff --git a/vis.h b/vis.h
index 4853c48..d060628 100644
--- a/vis.h
+++ b/vis.h
@@ -120,6 +120,9 @@ bool vis_window_syntax_set(Win*, const char *name);
int vis_window_width_get(const Win*);
int vis_window_height_get(const Win*);
+/* take an undo snaphost to which we can later revert to */
+void vis_file_snapshot(Vis*, File*);
+
/* display a user prompt with a certain title and default text */
void vis_prompt_show(Vis*, const char *title);