From 8162e86bc20a581cb7e82ba51893acbdbb7c6a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Thu, 27 Jul 2017 23:57:33 +0200 Subject: [PATCH] vis: remove ! operator Use visual mode and :| to filter text through external commands. The mapping was already reused for selection complement. --- config.def.h | 2 +- main.c | 19 ------------------- vis-operators.c | 8 -------- vis.c | 12 +----------- vis.h | 2 -- 5 files changed, 2 insertions(+), 41 deletions(-) diff --git a/config.def.h b/config.def.h index 4791fe484..ca05c0f3e 100644 --- a/config.def.h +++ b/config.def.h @@ -182,7 +182,7 @@ static const KeyBinding bindings_operators[] = { { "g~", ACTION(OPERATOR_CASE_SWAP) }, { "gp", ACTION(PUT_AFTER_END) }, { "gP", ACTION(PUT_BEFORE_END) }, - { "gq", ACTION(OPERATOR_FILTER_FMT) }, + { "gq", ALIAS(":| fmt") }, { "gu", ACTION(OPERATOR_CASE_LOWER) }, { "gU", ACTION(OPERATOR_CASE_UPPER) }, { "p", ACTION(PUT_AFTER) }, diff --git a/main.c b/main.c index 3334ed9a2..a41c25305 100644 --- a/main.c +++ b/main.c @@ -101,8 +101,6 @@ static const char *gotoline(Vis*, const char *keys, const Arg *arg); static const char *motiontype(Vis*, const char *keys, const Arg *arg); /* make the current action use the operator indicated by arg->i */ static const char *operator(Vis*, const char *keys, const Arg *arg); -/* use arg->s as command for the filter operator */ -static const char *operator_filter(Vis*, const char *keys, const Arg *arg); /* blocks to read a key and performs movement indicated by arg->i which * should be one of VIS_MOVE_{RIGHT,LEFT}_{TO,TILL} */ static const char *movement_key(Vis*, const char *keys, const Arg *arg); @@ -241,8 +239,6 @@ enum { VIS_ACTION_OPERATOR_CASE_LOWER, VIS_ACTION_OPERATOR_CASE_UPPER, VIS_ACTION_OPERATOR_CASE_SWAP, - VIS_ACTION_OPERATOR_FILTER, - VIS_ACTION_OPERATOR_FILTER_FMT, VIS_ACTION_COUNT, VIS_ACTION_INSERT_NEWLINE, VIS_ACTION_INSERT_TAB, @@ -797,16 +793,6 @@ static const KeyAction vis_action[] = { VIS_HELP("Swap case operator") operator, { .i = VIS_OP_CASE_SWAP } }, - [VIS_ACTION_OPERATOR_FILTER] = { - "vis-operator-filter", - VIS_HELP("Filter operator") - operator_filter, - }, - [VIS_ACTION_OPERATOR_FILTER_FMT] = { - "vis-operator-filter-format", - VIS_HELP("Formatting operator, filter range through fmt(1)") - operator_filter, { .s = "|fmt" } - }, [VIS_ACTION_COUNT] = { "vis-count", VIS_HELP("Count specifier") @@ -1957,11 +1943,6 @@ static const char *operator(Vis *vis, const char *keys, const Arg *arg) { return keys; } -static const char *operator_filter(Vis *vis, const char *keys, const Arg *arg) { - vis_operator(vis, VIS_OP_FILTER, arg->s); - return keys; -} - static const char *movement_key(Vis *vis, const char *keys, const Arg *arg) { if (!keys[0]) { vis_keymap_disable(vis); diff --git a/vis-operators.c b/vis-operators.c index 38dfbae23..bd09f244d 100644 --- a/vis-operators.c +++ b/vis-operators.c @@ -244,10 +244,6 @@ static size_t op_replace(Vis *vis, Text *txt, OperatorContext *c) { return c->range.start; } -static size_t op_filter(Vis *vis, Text *txt, OperatorContext *c) { - return text_size(txt) + 1; /* do not change cursor position, would destroy selection */ -} - int vis_operator_register(Vis *vis, VisOperatorFunction *func, void *context) { Operator *op = calloc(1, sizeof *op); if (!op) @@ -289,9 +285,6 @@ bool vis_operator(Vis *vis, enum VisOperator id, ...) { case VIS_OP_JOIN: vis->action.arg.s = va_arg(ap, char*); break; - case VIS_OP_FILTER: - vis->action.arg.s = va_arg(ap, char*); - /* fall through */ case VIS_OP_SHIFT_LEFT: case VIS_OP_SHIFT_RIGHT: vis_motion_type(vis, VIS_MOTIONTYPE_LINEWISE); @@ -359,5 +352,4 @@ const Operator vis_operators[] = { [VIS_OP_MODESWITCH] = { op_modeswitch }, [VIS_OP_REPLACE] = { op_replace }, [VIS_OP_CURSOR_SOL] = { op_cursor }, - [VIS_OP_FILTER] = { op_filter }, }; diff --git a/vis.c b/vis.c index fe466902c..b1b90024e 100644 --- a/vis.c +++ b/vis.c @@ -813,9 +813,6 @@ void vis_do(Vis *vis) { View *view = win->view; Action *a = &vis->action; - if (a->op == &vis_operators[VIS_OP_FILTER] && !vis->mode->visual) - vis_mode_switch(vis, VIS_MODE_VISUAL_LINE); - int count = MAX(a->count, 1); if (a->op == &vis_operators[VIS_OP_MODESWITCH]) count = 1; /* count should apply to inserted text not motion */ @@ -1000,11 +997,6 @@ void vis_do(Vis *vis) { vis_mode_switch(vis, VIS_MODE_INSERT); } 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); - else - vis_prompt_show(vis, ":|"); } else if (vis->mode == &vis_modes[VIS_MODE_OPERATOR_PENDING]) { mode_set(vis, vis->mode_prev); } else if (vis->mode->visual) { @@ -1490,9 +1482,7 @@ void vis_repeat(Vis *vis) { if (macro) { Mode *mode = vis->mode; Action action_prev = vis->action_prev; - if (count < 1 || - action_prev.op == &vis_operators[VIS_OP_CHANGE] || - action_prev.op == &vis_operators[VIS_OP_FILTER]) + if (count < 1 || action_prev.op == &vis_operators[VIS_OP_CHANGE]) count = 1; if (vis->action_prev.op == &vis_operators[VIS_OP_MODESWITCH]) vis->action_prev.count = 1; diff --git a/vis.h b/vis.h index 178aae222..a89819b83 100644 --- a/vis.h +++ b/vis.h @@ -386,7 +386,6 @@ enum VisOperator { VIS_OP_REPLACE, VIS_OP_CURSOR_SOL, VIS_OP_CASE_SWAP, - VIS_OP_FILTER, VIS_OP_INVALID, /* denotes the end of the "real" operators */ /* pseudo operators: keep them at the end to save space in array definition */ VIS_OP_CASE_LOWER, @@ -434,7 +433,6 @@ int vis_operator_register(Vis*, VisOperatorFunction*, void *context); * * The expected varying arguments are: * - * - `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` an ``enum VisMode`` indicating the mode to switch to. * - `VIS_OP_REPLACE` a char pointer reffering to the replacement character.