From e6f798a651f3fbf7d5bd667d8f956e17ccbca5e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 20 Jan 2017 16:56:52 +0100 Subject: vis: slightly cleanup repeat code, always set dot register --- vis-modes.c | 5 +---- vis-operators.c | 2 +- vis.c | 16 ++++++++-------- vis.h | 2 +- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/vis-modes.c b/vis-modes.c index 84f2e0b..4b5fb3c 100644 --- a/vis-modes.c +++ b/vis-modes.c @@ -201,10 +201,7 @@ static void vis_mode_insert_replace_enter(Vis *vis, Mode *old) { vis->action_prev.op = &vis_operators[VIS_OP_MODESWITCH]; vis->action_prev.mode = vis->mode->id; } - if (!vis->macro_operator) { - macro_operator_record(vis); - vis->action_prev.macro = vis->macro_operator; - } + macro_operator_record(vis); } static void vis_mode_insert_idle(Vis *vis) { diff --git a/vis-operators.c b/vis-operators.c index 8d28dc4..6f3f0d1 100644 --- a/vis-operators.c +++ b/vis-operators.c @@ -274,7 +274,7 @@ bool vis_operator(Vis *vis, enum VisOperator id, ...) { break; case VIS_OP_REPLACE: { - Macro *macro = &vis->registers[VIS_MACRO_OPERATOR].buf; + Macro *macro = &vis->registers[VIS_REG_DOT].buf; macro_reset(macro); macro_append(macro, va_arg(ap, char*)); vis->action.arg.s = macro->data; diff --git a/vis.c b/vis.c index a8bc1ac..12d364a 100644 --- a/vis.c +++ b/vis.c @@ -48,7 +48,7 @@ const RegisterDef vis_registers[] = { [VIS_REG_AMPERSAND] = { '&', "Last regex match" }, [VIS_REG_BLACKHOLE] = { '_', "/dev/null register" }, [VIS_REG_CLIPBOARD] = { '*', "System clipboard register, see vis-clipboard(1)" }, - [VIS_MACRO_REPEAT] = { '.', "Last inserted text" }, + [VIS_REG_DOT] = { '.', "Last inserted text" }, [VIS_REG_SEARCH] = { '/', "Last search pattern" }, [VIS_REG_COMMAND] = { ':', "Last :-command" }, [VIS_REG_SHELL] = { '!', "Last shell command given to either <, >, |, or !" }, @@ -1196,11 +1196,18 @@ static Macro *macro_get(Vis *vis, enum VisRegister id) { } void macro_operator_record(Vis *vis) { + if (vis->macro_operator) + return; vis->macro_operator = macro_get(vis, VIS_MACRO_OPERATOR); macro_reset(vis->macro_operator); } void macro_operator_stop(Vis *vis) { + if (!vis->macro_operator) + return; + Macro *dot = macro_get(vis, VIS_REG_DOT); + buffer_put(dot, vis->macro_operator->data, vis->macro_operator->len); + vis->action_prev.macro = dot; vis->macro_operator = NULL; } @@ -1278,14 +1285,7 @@ bool vis_macro_replay(Vis *vis, enum VisRegister id) { } void vis_repeat(Vis *vis) { - Macro *macro_operator = macro_get(vis, VIS_MACRO_OPERATOR); - Macro *macro_repeat = macro_get(vis, VIS_MACRO_REPEAT); const Macro *macro = vis->action_prev.macro; - if (macro == macro_operator) { - buffer_put(macro_repeat, macro_operator->data, macro_operator->len); - macro = macro_repeat; - vis->action_prev.macro = macro; - } int count = vis->action.count; if (count != VIS_COUNT_UNKNOWN) vis->action_prev.count = count; diff --git a/vis.h b/vis.h index d060628..a57ff94 100644 --- a/vis.h +++ b/vis.h @@ -415,7 +415,7 @@ enum VisRegister { VIS_REG_9, VIS_REG_BLACKHOLE, /* /dev/null register */ VIS_REG_CLIPBOARD, /* system clipboard register */ - VIS_MACRO_REPEAT, /* copy of the above macro once the recording is finished */ + VIS_REG_DOT, /* last inserted text, copy of VIS_MACRO_OPERATOR */ VIS_REG_SEARCH, /* last used search pattern "/ */ VIS_REG_COMMAND, /* last used :-command ": */ VIS_REG_SHELL, /* last used shell command given to either <, >, |, or ! */ -- cgit v1.2.3