diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-11-09 11:58:29 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-11-09 12:34:55 +0100 |
| commit | 51bf6abad037a333ad3b8f760150de4d834bb900 (patch) | |
| tree | c2c8d9e5fc4d6f76c310202dfc096ca98f375084 | |
| parent | 0e74ee26ef3d441a559ea18bec08018c0c2ef461 (diff) | |
| download | vis-51bf6abad037a333ad3b8f760150de4d834bb900.tar.gz vis-51bf6abad037a333ad3b8f760150de4d834bb900.tar.xz | |
vis: unify VIS_OP_{INSERT,REPLACE} implementation
They both perform a motion before changing mode.
| -rw-r--r-- | main.c | 6 | ||||
| -rw-r--r-- | vis-core.h | 1 | ||||
| -rw-r--r-- | vis-modes.c | 6 | ||||
| -rw-r--r-- | vis-operators.c | 12 | ||||
| -rw-r--r-- | vis.c | 8 | ||||
| -rw-r--r-- | vis.h | 4 |
6 files changed, 19 insertions, 18 deletions
@@ -1637,7 +1637,7 @@ static const char *replace(Vis *vis, const char *keys, const Arg *arg) { const char *next = vis_keys_next(vis, keys); if (!next) return NULL; - vis_operator(vis, VIS_OP_REPLACE); + vis_operator(vis, VIS_OP_MODESWITCH, VIS_MODE_REPLACE); vis_motion(vis, VIS_MOVE_NOP); vis_keys_feed(vis, keys); vis_keys_feed(vis, "<Escape>"); @@ -1967,7 +1967,7 @@ static const char *window(Vis *vis, const char *keys, const Arg *arg) { } static const char *openline(Vis *vis, const char *keys, const Arg *arg) { - vis_operator(vis, VIS_OP_INSERT); + vis_operator(vis, VIS_OP_MODESWITCH, VIS_MODE_INSERT); if (arg->i > 0) { vis_motion(vis, VIS_MOVE_LINE_END); vis_keys_feed(vis, "<insert-newline>"); @@ -2000,7 +2000,7 @@ static const char *switchmode(Vis *vis, const char *keys, const Arg *arg) { } static const char *insertmode(Vis *vis, const char *keys, const Arg *arg) { - vis_operator(vis, VIS_OP_INSERT); + vis_operator(vis, VIS_OP_MODESWITCH, VIS_MODE_INSERT); vis_motion(vis, arg->i); return keys; } @@ -95,6 +95,7 @@ typedef Buffer Macro; typedef struct { /** collects all information until an operator is executed */ int count; + enum VisMode mode; enum VisMotionType type; const Operator *op; const Movement *movement; diff --git a/vis-modes.c b/vis-modes.c index 967feb9..a10d214 100644 --- a/vis-modes.c +++ b/vis-modes.c @@ -122,7 +122,8 @@ static void vis_mode_insert_enter(Vis *vis, Mode *old) { return; if (!vis->action.op) { action_reset(&vis->action_prev); - vis->action_prev.op = &vis_operators[VIS_OP_INSERT]; + vis->action_prev.op = &vis_operators[VIS_OP_MODESWITCH]; + vis->action_prev.mode = VIS_MODE_INSERT; } if (!vis->macro_operator) { macro_operator_record(vis); @@ -150,7 +151,8 @@ static void vis_mode_replace_enter(Vis *vis, Mode *old) { return; if (!vis->action.op) { action_reset(&vis->action_prev); - vis->action_prev.op = &vis_operators[VIS_OP_REPLACE]; + vis->action_prev.op = &vis_operators[VIS_OP_MODESWITCH]; + vis->action_prev.mode = VIS_MODE_REPLACE; } if (!vis->macro_operator) { macro_operator_record(vis); diff --git a/vis-operators.c b/vis-operators.c index 3ce7689..5784115 100644 --- a/vis-operators.c +++ b/vis-operators.c @@ -214,11 +214,7 @@ static size_t op_join(Vis *vis, Text *txt, OperatorContext *c) { return newpos != EPOS ? newpos : c->range.start; } -static size_t op_insert(Vis *vis, Text *txt, OperatorContext *c) { - return c->newpos != EPOS ? c->newpos : c->pos; -} - -static size_t op_replace(Vis *vis, Text *txt, OperatorContext *c) { +static size_t op_modeswitch(Vis *vis, Text *txt, OperatorContext *c) { return c->newpos != EPOS ? c->newpos : c->pos; } @@ -231,6 +227,9 @@ bool vis_operator(Vis *vis, enum VisOperator id, ...) { va_start(ap, id); switch (id) { + case VIS_OP_MODESWITCH: + vis->action.mode = va_arg(ap, int); + break; case VIS_OP_CASE_LOWER: case VIS_OP_CASE_UPPER: case VIS_OP_CASE_SWAP: @@ -304,8 +303,7 @@ const Operator vis_operators[] = { [VIS_OP_SHIFT_LEFT] = { op_shift_left }, [VIS_OP_CASE_SWAP] = { op_case_change }, [VIS_OP_JOIN] = { op_join }, - [VIS_OP_INSERT] = { op_insert }, - [VIS_OP_REPLACE] = { op_replace }, + [VIS_OP_MODESWITCH] = { op_modeswitch }, [VIS_OP_CURSOR_SOL] = { op_cursor }, [VIS_OP_FILTER] = { op_filter }, }; @@ -704,10 +704,10 @@ void vis_do(Vis *vis) { /* operator implementations must not change the mode, * they might get called multiple times (once for every cursor) */ - if (a->op == &vis_operators[VIS_OP_INSERT] || a->op == &vis_operators[VIS_OP_CHANGE]) { + if (a->op == &vis_operators[VIS_OP_CHANGE]) { vis_mode_switch(vis, VIS_MODE_INSERT); - } else if (a->op == &vis_operators[VIS_OP_REPLACE]) { - vis_mode_switch(vis, VIS_MODE_REPLACE); + } else if (a->op == &vis_operators[VIS_OP_MODESWITCH]) { + vis_mode_switch(vis, a->mode); } else if (a->op == &vis_operators[VIS_OP_FILTER]) { if (a->arg.s) vis_cmd(vis, a->arg.s); @@ -1127,7 +1127,7 @@ void vis_repeat(Vis *vis) { vis->action_prev.count = count; count = vis->action_prev.count; /* for some operators count should be applied only to the macro not the motion */ - if (vis->action_prev.op == &vis_operators[VIS_OP_INSERT] || vis->action_prev.op == &vis_operators[VIS_OP_REPLACE]) + if (vis->action_prev.op == &vis_operators[VIS_OP_MODESWITCH]) vis->action_prev.count = 1; vis->action = vis->action_prev; vis_do(vis); @@ -182,8 +182,7 @@ enum VisOperator { VIS_OP_SHIFT_RIGHT, VIS_OP_SHIFT_LEFT, VIS_OP_JOIN, - VIS_OP_INSERT, - VIS_OP_REPLACE, + VIS_OP_MODESWITCH, VIS_OP_CURSOR_SOL, VIS_OP_CASE_SWAP, VIS_OP_FILTER, @@ -208,6 +207,7 @@ enum VisOperator { * * - VIS_OP_FILTER a char pointer referring to the command to run * - VIS_OP_JOIN a char pointer referring to the text to insert between lines + * - VIS_OP_MODESWITCH a enum VisMode constant indicating the mode to switch to */ bool vis_operator(Vis*, enum VisOperator, ...); |
