Skip to content

Commit

Permalink
vis: implement g~ using tr(1)
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed May 16, 2018
1 parent f9d0d91 commit 62ea7dc
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 36 deletions.
5 changes: 2 additions & 3 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ static const KeyBinding bindings_operators[] = {
{ "7", ACTION(COUNT) },
{ "8", ACTION(COUNT) },
{ "9", ACTION(COUNT) },
{ "~", ACTION(OPERATOR_CASE_SWAP) },
{ "~", ALIAS("g~") },
{ "=", ALIAS(":|fmt<Enter>") },
{ "<", ACTION(OPERATOR_SHIFT_LEFT) },
{ ">", ACTION(OPERATOR_SHIFT_RIGHT) },
{ "\"", ACTION(REGISTER) },
{ "'", ACTION(MARK) },
{ "c", ACTION(OPERATOR_CHANGE) },
{ "d", ACTION(OPERATOR_DELETE) },
{ "g~", ACTION(OPERATOR_CASE_SWAP) },
{ "g~", ALIAS(":|tr '[:lower:][:upper:]' '[:upper:][:lower:]'<Enter>") },
{ "gp", ACTION(PUT_AFTER_END) },
{ "gP", ACTION(PUT_BEFORE_END) },
{ "gu", ALIAS(":|tr '[:upper:]' '[:lower:]'<Enter>")},
Expand All @@ -202,7 +202,6 @@ static const KeyBinding bindings_normal[] = {
{ "@", ACTION(MACRO_REPLAY) },
{ ":", ACTION(PROMPT_SHOW) },
{ ".", ACTION(REPEAT) },
{ "~", ALIAS("<vis-operator-case-swap>ll") },
{ "C", ALIAS("c$") },
{ "<C-b>", ALIAS("<PageUp>") },
{ "<C-c>", ACTION(SELECTIONS_REMOVE_COLUMN) },
Expand Down
6 changes: 0 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ enum {
VIS_ACTION_OPERATOR_YANK,
VIS_ACTION_OPERATOR_SHIFT_LEFT,
VIS_ACTION_OPERATOR_SHIFT_RIGHT,
VIS_ACTION_OPERATOR_CASE_SWAP,
VIS_ACTION_COUNT,
VIS_ACTION_INSERT_NEWLINE,
VIS_ACTION_INSERT_TAB,
Expand Down Expand Up @@ -777,11 +776,6 @@ static const KeyAction vis_action[] = {
VIS_HELP("Shift right operator")
operator, { .i = VIS_OP_SHIFT_RIGHT }
},
[VIS_ACTION_OPERATOR_CASE_SWAP] = {
"vis-operator-case-swap",
VIS_HELP("Swap case operator")
operator, { .i = VIS_OP_CASE_SWAP }
},
[VIS_ACTION_COUNT] = {
"vis-count",
VIS_HELP("Count specifier")
Expand Down
26 changes: 0 additions & 26 deletions vis-operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,27 +160,6 @@ static size_t op_shift_left(Vis *vis, Text *txt, OperatorContext *c) {
return newpos;
}

static size_t op_case_change(Vis *vis, Text *txt, OperatorContext *c) {
size_t len = text_range_size(&c->range);
char *buf = malloc(len);
if (!buf)
return c->pos;
len = text_bytes_get(txt, c->range.start, len, buf);
size_t rem = len;
for (char *cur = buf; rem > 0; cur++, rem--) {
int ch = (unsigned char)*cur;
if (isascii(ch)) {
if (c->arg->i == VIS_OP_CASE_SWAP)
*cur = islower(ch) ? toupper(ch) : tolower(ch);
}
}

text_delete(txt, c->range.start, len);
text_insert(txt, c->range.start, buf, len);
free(buf);
return c->pos;
}

static size_t op_cursor(Vis *vis, Text *txt, OperatorContext *c) {
View *view = vis->win->view;
Filerange r = text_range_linewise(txt, &c->range);
Expand Down Expand Up @@ -264,10 +243,6 @@ bool vis_operator(Vis *vis, enum VisOperator id, ...) {
case VIS_OP_MODESWITCH:
vis->action.mode = va_arg(ap, int);
break;
case VIS_OP_CASE_SWAP:
vis->action.arg.i = id;
id = VIS_OP_CASE_SWAP;
break;
case VIS_OP_CURSOR_SOL:
case VIS_OP_CURSOR_EOL:
vis->action.arg.i = id;
Expand Down Expand Up @@ -353,7 +328,6 @@ const Operator vis_operators[] = {
[VIS_OP_PUT_AFTER] = { op_put },
[VIS_OP_SHIFT_RIGHT] = { op_shift_right },
[VIS_OP_SHIFT_LEFT] = { op_shift_left },
[VIS_OP_CASE_SWAP] = { op_case_change },
[VIS_OP_JOIN] = { op_join },
[VIS_OP_MODESWITCH] = { op_modeswitch },
[VIS_OP_REPLACE] = { op_replace },
Expand Down
1 change: 0 additions & 1 deletion vis.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ enum VisOperator {
VIS_OP_MODESWITCH,
VIS_OP_REPLACE,
VIS_OP_CURSOR_SOL,
VIS_OP_CASE_SWAP,
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_CURSOR_EOL,
Expand Down

0 comments on commit 62ea7dc

Please sign in to comment.