aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c14
-rw-r--r--vis.c25
-rw-r--r--vis.h7
3 files changed, 27 insertions, 19 deletions
diff --git a/main.c b/main.c
index 9be0525..40de71b 100644
--- a/main.c
+++ b/main.c
@@ -69,8 +69,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);
-/* change case of a file range to upper (arg->i > 0) or lowercase (arg->i < 0) */
-static const char *changecase(Vis*, const char *keys, const Arg *arg);
/* blocks to read a key and performs movement indicated by arg->i which
* should be one of MOVE_{RIGHT,LEFT}_{TO,TILL} */
static const char *movement_key(Vis*, const char *keys, const Arg *arg);
@@ -697,17 +695,17 @@ static KeyAction vis_action[] = {
[VIS_ACTION_OPERATOR_CASE_LOWER] = {
"vis-operator-case-lower",
"Lowercase operator",
- changecase, { .i = -1 }
+ operator, { .i = OP_CASE_LOWER }
},
[VIS_ACTION_OPERATOR_CASE_UPPER] = {
"vis-operator-case-upper",
"Uppercase operator",
- changecase, { .i = +1 }
+ operator, { .i = OP_CASE_UPPER }
},
[VIS_ACTION_OPERATOR_CASE_SWAP] = {
"vis-operator-case-swap",
"Swap case operator",
- changecase, { .i = 0 }
+ operator, { .i = OP_CASE_SWAP }
},
[VIS_ACTION_COUNT] = {
"vis-count",
@@ -1237,12 +1235,6 @@ static const char *operator(Vis *vis, const char *keys, const Arg *arg) {
return keys;
}
-static const char *changecase(Vis *vis, const char *keys, const Arg *arg) {
- vis->action.arg = *arg;
- vis_operator(vis, OP_CASE_CHANGE);
- return keys;
-}
-
static const char *movement_key(Vis *vis, const char *keys, const Arg *arg) {
if (!keys[0])
return NULL;
diff --git a/vis.c b/vis.c
index 2e24fe9..134b332 100644
--- a/vis.c
+++ b/vis.c
@@ -572,7 +572,7 @@ static Operator ops[] = {
[OP_PUT] = { op_put },
[OP_SHIFT_RIGHT] = { op_shift_right },
[OP_SHIFT_LEFT] = { op_shift_left },
- [OP_CASE_CHANGE] = { op_case_change },
+ [OP_CASE_SWAP] = { op_case_change },
[OP_JOIN] = { op_join },
[OP_REPEAT_INSERT] = { op_repeat_insert },
[OP_REPEAT_REPLACE] = { op_repeat_replace },
@@ -1148,9 +1148,9 @@ static size_t op_case_change(Vis *vis, Text *txt, OperatorContext *c) {
for (char *cur = buf; rem > 0; cur++, rem--) {
int ch = (unsigned char)*cur;
if (isascii(ch)) {
- if (c->arg->i == 0)
+ if (c->arg->i == OP_CASE_SWAP)
*cur = islower(ch) ? toupper(ch) : tolower(ch);
- else if (c->arg->i > 0)
+ else if (c->arg->i == OP_CASE_UPPER)
*cur = toupper(ch);
else
*cur = tolower(ch);
@@ -2800,12 +2800,24 @@ int vis_run(Vis *vis, int argc, char *argv[]) {
return vis->exit_status;
}
-void vis_operator(Vis *vis, enum VisOperator opi) {
- Operator *op = &ops[opi];
+bool vis_operator(Vis *vis, enum VisOperator id) {
+ switch (id) {
+ case OP_CASE_LOWER:
+ case OP_CASE_UPPER:
+ case OP_CASE_SWAP:
+ vis->action.arg.i = id;
+ id = OP_CASE_SWAP;
+ break;
+ default:
+ break;
+ }
+ if (id >= LENGTH(ops))
+ return false;
+ Operator *op = &ops[id];
if (vis->mode->visual) {
vis->action.op = op;
action_do(vis, &vis->action);
- return;
+ return true;
}
/* switch to operator mode inorder to make operator options and
* text-object available */
@@ -2818,6 +2830,7 @@ void vis_operator(Vis *vis, enum VisOperator opi) {
} else {
vis->action.op = op;
}
+ return true;
}
void vis_mode_switch(Vis *vis, enum VisMode mode) {
diff --git a/vis.h b/vis.h
index 5e371e3..e1361d6 100644
--- a/vis.h
+++ b/vis.h
@@ -135,11 +135,14 @@ enum VisOperator {
OP_PUT,
OP_SHIFT_RIGHT,
OP_SHIFT_LEFT,
- OP_CASE_CHANGE,
OP_JOIN,
OP_REPEAT_INSERT,
OP_REPEAT_REPLACE,
OP_CURSOR,
+ OP_CASE_SWAP,
+ /* pseudo operators: keep them at the end to save space in array definition */
+ OP_CASE_LOWER,
+ OP_CASE_UPPER,
};
/* TODO: overhaul repeatable infrastructure:
@@ -154,7 +157,7 @@ enum {
PUT_BEFORE_END,
};
-void vis_operator(Vis*, enum VisOperator);
+bool vis_operator(Vis*, enum VisOperator);
enum VisMotion {
MOVE_LINE_DOWN,