Skip to content

Commit

Permalink
vis: remove ! operator
Browse files Browse the repository at this point in the history
Use visual mode and :| to filter text through external commands.
The mapping was already reused for selection complement.
  • Loading branch information
martanne committed Sep 15, 2017
1 parent 7913305 commit 8162e86
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 41 deletions.
2 changes: 1 addition & 1 deletion config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Enter>") },
{ "gu", ACTION(OPERATOR_CASE_LOWER) },
{ "gU", ACTION(OPERATOR_CASE_UPPER) },
{ "p", ACTION(PUT_AFTER) },
Expand Down
19 changes: 0 additions & 19 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 0 additions & 8 deletions vis-operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 },
};
12 changes: 1 addition & 11 deletions vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions vis.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 8162e86

Please sign in to comment.