aboutsummaryrefslogtreecommitdiff
path: root/vis.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-10-23 12:38:02 +0200
committerMarc André Tanner <mat@brain-dump.org>2015-10-23 23:01:56 +0200
commit1dc99b23e393086076bb08318b560b9d85673480 (patch)
tree324bcde3eb0a8ecbfadb277de0d24dc9d97e43d1 /vis.c
parentafb87c6d29275e18faec6a8b96e7d5ab57bcb0f9 (diff)
downloadvis-1dc99b23e393086076bb08318b560b9d85673480.tar.gz
vis-1dc99b23e393086076bb08318b560b9d85673480.tar.xz
vis: introduce vis_operator API
Diffstat (limited to 'vis.c')
-rw-r--r--vis.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/vis.c b/vis.c
index 2261285..9ede18e 100644
--- a/vis.c
+++ b/vis.c
@@ -880,7 +880,8 @@ static const char *cursors_new(Vis *vis, const char *keys, const Arg *arg) {
static const char *cursors_split(Vis *vis, const char *keys, const Arg *arg) {
vis->action.arg = *arg;
- return operator(vis, keys, &(const Arg){ .i = OP_CURSOR });
+ vis_operator(vis, OP_CURSOR);
+ return keys;
}
static const char *cursors_align(Vis *vis, const char *keys, const Arg *arg) {
@@ -1005,30 +1006,13 @@ static const char *motiontype(Vis *vis, const char *keys, const Arg *arg) {
}
static const char *operator(Vis *vis, const char *keys, const Arg *arg) {
- Operator *op = &ops[arg->i];
- if (vis->mode->visual) {
- vis->action.op = op;
- action_do(vis, &vis->action);
- return keys;
- }
- /* switch to operator mode inorder to make operator options and
- * text-object available */
- switchmode(vis, keys, &(const Arg){ .i = VIS_MODE_OPERATOR });
- if (vis->action.op == op) {
- /* hacky way to handle double operators i.e. things like
- * dd, yy etc where the second char isn't a movement */
- vis->action.type = LINEWISE;
- vis->action.movement = &moves[MOVE_LINE_NEXT];
- action_do(vis, &vis->action);
- } else {
- vis->action.op = op;
- }
+ vis_operator(vis, arg->i);
return keys;
}
static const char *changecase(Vis *vis, const char *keys, const Arg *arg) {
vis->action.arg = *arg;
- operator(vis, keys, &(const Arg){ .i = OP_CASE_CHANGE });
+ vis_operator(vis, OP_CASE_CHANGE);
return keys;
}
@@ -1179,7 +1163,7 @@ static const char *later(Vis *vis, const char *keys, const Arg *arg) {
}
static const char *delete(Vis *vis, const char *keys, const Arg *arg) {
- operator(vis, keys, &(const Arg){ .i = OP_DELETE });
+ vis_operator(vis, OP_DELETE);
movement(vis, keys, arg);
return keys;
}
@@ -1399,7 +1383,7 @@ static const char *insert_newline(Vis *vis, const char *keys, const Arg *arg) {
static const char *put(Vis *vis, const char *keys, const Arg *arg) {
vis->action.arg = *arg;
- operator(vis, keys, &(const Arg){ .i = OP_PUT });
+ vis_operator(vis, OP_PUT);
action_do(vis, &vis->action);
return keys;
}
@@ -1420,7 +1404,7 @@ static const char *openline(Vis *vis, const char *keys, const Arg *arg) {
static const char *join(Vis *vis, const char *keys, const Arg *arg) {
if (vis->action.count)
vis->action.count--;
- operator(vis, keys, &(const Arg){ .i = OP_JOIN });
+ vis_operator(vis, OP_JOIN);
movement(vis, keys, arg);
return keys;
}
@@ -2850,3 +2834,23 @@ Vis *vis_new(Ui *ui) {
return vis;
}
+void vis_operator(Vis *vis, enum VisOperator opi) {
+ Operator *op = &ops[opi];
+ if (vis->mode->visual) {
+ vis->action.op = op;
+ action_do(vis, &vis->action);
+ return;
+ }
+ /* switch to operator mode inorder to make operator options and
+ * text-object available */
+ switchmode(vis, NULL, &(const Arg){ .i = VIS_MODE_OPERATOR });
+ if (vis->action.op == op) {
+ /* hacky way to handle double operators i.e. things like
+ * dd, yy etc where the second char isn't a movement */
+ vis->action.type = LINEWISE;
+ vis->action.movement = &moves[MOVE_LINE_NEXT];
+ action_do(vis, &vis->action);
+ } else {
+ vis->action.op = op;
+ }
+}