aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-01-14 21:07:09 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-01-14 21:07:09 +0100
commit062f8f508372f46d0ea10358e989a0713de28c28 (patch)
tree597e7f8f377887da7fee2d9cea7eff06b8943b18
parente50173b0663997b507a7029ff5d4bb7908040ac8 (diff)
downloadvis-062f8f508372f46d0ea10358e989a0713de28c28.tar.gz
vis-062f8f508372f46d0ea10358e989a0713de28c28.tar.xz
vis: move vis_operator(..) to corresponding file
-rw-r--r--vis-operators.c63
-rw-r--r--vis.c63
2 files changed, 63 insertions, 63 deletions
diff --git a/vis-operators.c b/vis-operators.c
index 1d288ff..836ebed 100644
--- a/vis-operators.c
+++ b/vis-operators.c
@@ -212,6 +212,69 @@ static size_t op_filter(Vis *vis, Text *txt, OperatorContext *c) {
return text_size(txt) + 1; /* do not change cursor position, would destroy selection */
}
+bool vis_operator(Vis *vis, enum VisOperator id, ...) {
+ va_list ap;
+ va_start(ap, id);
+
+ switch (id) {
+ case VIS_OP_CASE_LOWER:
+ case VIS_OP_CASE_UPPER:
+ 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;
+ id = VIS_OP_CURSOR_SOL;
+ break;
+ case VIS_OP_PUT_AFTER:
+ case VIS_OP_PUT_AFTER_END:
+ case VIS_OP_PUT_BEFORE:
+ case VIS_OP_PUT_BEFORE_END:
+ vis->action.arg.i = id;
+ id = VIS_OP_PUT_AFTER;
+ break;
+ case VIS_OP_FILTER:
+ vis->action.type = LINEWISE;
+ vis->action.arg.s = va_arg(ap, char*);
+ break;
+ default:
+ break;
+ }
+ if (id >= LENGTH(ops))
+ goto err;
+ Operator *op = &ops[id];
+ if (vis->mode->visual) {
+ vis->action.op = op;
+ action_do(vis, &vis->action);
+ goto out;
+ }
+
+ /* switch to operator mode inorder to make operator options and
+ * text-object available */
+ vis_mode_switch(vis, VIS_MODE_OPERATOR_PENDING);
+ 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_motion(vis, VIS_MOVE_LINE_NEXT);
+ } else {
+ vis->action.op = op;
+ }
+
+ /* put is not a real operator, does not need a range to operate on */
+ if (id == VIS_OP_PUT_AFTER)
+ vis_motion(vis, VIS_MOVE_NOP);
+
+out:
+ va_end(ap);
+ return true;
+err:
+ va_end(ap);
+ return false;
+}
+
Operator ops[] = {
[VIS_OP_DELETE] = { op_delete },
[VIS_OP_CHANGE] = { op_change },
diff --git a/vis.c b/vis.c
index b9055aa..4246688 100644
--- a/vis.c
+++ b/vis.c
@@ -1030,69 +1030,6 @@ int vis_run(Vis *vis, int argc, char *argv[]) {
return vis->exit_status;
}
-bool vis_operator(Vis *vis, enum VisOperator id, ...) {
- va_list ap;
- va_start(ap, id);
-
- switch (id) {
- case VIS_OP_CASE_LOWER:
- case VIS_OP_CASE_UPPER:
- 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;
- id = VIS_OP_CURSOR_SOL;
- break;
- case VIS_OP_PUT_AFTER:
- case VIS_OP_PUT_AFTER_END:
- case VIS_OP_PUT_BEFORE:
- case VIS_OP_PUT_BEFORE_END:
- vis->action.arg.i = id;
- id = VIS_OP_PUT_AFTER;
- break;
- case VIS_OP_FILTER:
- vis->action.type = LINEWISE;
- vis->action.arg.s = va_arg(ap, char*);
- break;
- default:
- break;
- }
- if (id >= LENGTH(ops))
- goto err;
- Operator *op = &ops[id];
- if (vis->mode->visual) {
- vis->action.op = op;
- action_do(vis, &vis->action);
- goto out;
- }
-
- /* switch to operator mode inorder to make operator options and
- * text-object available */
- vis_mode_switch(vis, VIS_MODE_OPERATOR_PENDING);
- 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_motion(vis, VIS_MOVE_LINE_NEXT);
- } else {
- vis->action.op = op;
- }
-
- /* put is not a real operator, does not need a range to operate on */
- if (id == VIS_OP_PUT_AFTER)
- vis_motion(vis, VIS_MOVE_NOP);
-
-out:
- va_end(ap);
- return true;
-err:
- va_end(ap);
- return false;
-}
-
void vis_mode_switch(Vis *vis, enum VisMode mode) {
mode_set(vis, &vis_modes[mode]);
}