aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c17
-rw-r--r--vis.c30
-rw-r--r--vis.h22
3 files changed, 34 insertions, 35 deletions
diff --git a/main.c b/main.c
index 6a2e593..0708e02 100644
--- a/main.c
+++ b/main.c
@@ -31,8 +31,6 @@ static const char *insert(Vis*, const char *keys, const Arg *arg);
static const char *insert_tab(Vis*, const char *keys, const Arg *arg);
/* inserts a newline (either \n or \r\n depending on file type) */
static const char *insert_newline(Vis*, const char *keys, const Arg *arg);
-/* put register content according to arg->i */
-static const char *put(Vis*, const char *keys, const Arg *arg);
/* add a new line either before or after the one where the cursor currently is */
static const char *openline(Vis*, const char *keys, const Arg *arg);
/* join lines from current cursor position to movement indicated by arg */
@@ -822,22 +820,22 @@ static KeyAction vis_action[] = {
[VIS_ACTION_PUT_AFTER] = {
"put-after",
"Put text after the cursor",
- put, { .i = PUT_AFTER }
+ operator, { .i = OP_PUT_AFTER }
},
[VIS_ACTION_PUT_BEFORE] = {
"put-before",
"Put text before the cursor",
- put, { .i = PUT_BEFORE }
+ operator, { .i = OP_PUT_BEFORE }
},
[VIS_ACTION_PUT_AFTER_END] = {
"put-after-end",
"Put text after the cursor, place cursor after new text",
- put, { .i = PUT_AFTER_END }
+ operator, { .i = OP_PUT_AFTER_END }
},
[VIS_ACTION_PUT_BEFORE_END] = {
"put-before-end",
"Put text before the cursor, place cursor after new text",
- put, { .i = PUT_BEFORE_END }
+ operator, { .i = OP_PUT_BEFORE_END }
},
[VIS_ACTION_CURSOR_SELECT_WORD] = {
"cursors-select-word",
@@ -1562,13 +1560,6 @@ static const char *insert_newline(Vis *vis, const char *keys, const Arg *arg) {
return keys;
}
-static const char *put(Vis *vis, const char *keys, const Arg *arg) {
- vis->action.arg = *arg;
- vis_operator(vis, OP_PUT);
- vis_motion(vis, MOVE_NOP);
- return keys;
-}
-
static const char *openline(Vis *vis, const char *keys, const Arg *arg) {
if (arg->i == MOVE_LINE_NEXT) {
vis_motion(vis, MOVE_LINE_END);
diff --git a/vis.c b/vis.c
index 8265182..5b96062 100644
--- a/vis.c
+++ b/vis.c
@@ -569,7 +569,7 @@ static Operator ops[] = {
[OP_DELETE] = { op_delete },
[OP_CHANGE] = { op_change },
[OP_YANK] = { op_yank },
- [OP_PUT] = { op_put },
+ [OP_PUT_AFTER] = { op_put },
[OP_SHIFT_RIGHT] = { op_shift_right },
[OP_SHIFT_LEFT] = { op_shift_left },
[OP_CASE_SWAP] = { op_case_change },
@@ -1046,15 +1046,15 @@ static size_t op_yank(Vis *vis, Text *txt, OperatorContext *c) {
static size_t op_put(Vis *vis, Text *txt, OperatorContext *c) {
size_t pos = c->pos;
switch (c->arg->i) {
- case PUT_AFTER:
- case PUT_AFTER_END:
+ case OP_PUT_AFTER:
+ case OP_PUT_AFTER_END:
if (c->reg->linewise)
pos = text_line_next(txt, pos);
else
pos = text_char_next(txt, pos);
break;
- case PUT_BEFORE:
- case PUT_BEFORE_END:
+ case OP_PUT_BEFORE:
+ case OP_PUT_BEFORE_END:
if (c->reg->linewise)
pos = text_line_begin(txt, pos);
break;
@@ -1067,14 +1067,14 @@ static size_t op_put(Vis *vis, Text *txt, OperatorContext *c) {
if (c->reg->linewise) {
switch (c->arg->i) {
- case PUT_BEFORE_END:
- case PUT_AFTER_END:
+ case OP_PUT_BEFORE_END:
+ case OP_PUT_AFTER_END:
pos = text_line_start(txt, pos);
break;
- case PUT_AFTER:
+ case OP_PUT_AFTER:
pos = text_line_start(txt, text_line_next(txt, c->pos));
break;
- case PUT_BEFORE:
+ case OP_PUT_BEFORE:
pos = text_line_start(txt, c->pos);
break;
}
@@ -2813,6 +2813,13 @@ bool vis_operator(Vis *vis, enum VisOperator id) {
vis->action.arg.i = id;
id = OP_CURSOR_SOL;
break;
+ case OP_PUT_AFTER:
+ case OP_PUT_AFTER_END:
+ case OP_PUT_BEFORE:
+ case OP_PUT_BEFORE_END:
+ vis->action.arg.i = id;
+ id = OP_PUT_AFTER;
+ break;
default:
break;
}
@@ -2835,6 +2842,11 @@ bool vis_operator(Vis *vis, enum VisOperator id) {
} else {
vis->action.op = op;
}
+
+ /* put is not a real operator, does not need a range to operate on */
+ if (id == OP_PUT_AFTER)
+ vis_motion(vis, MOVE_NOP);
+
return true;
}
diff --git a/vis.h b/vis.h
index d6e5546..dee4072 100644
--- a/vis.h
+++ b/vis.h
@@ -128,11 +128,16 @@ void vis_mode_set(Vis*, Mode*);
bool vis_action_register(Vis*, KeyAction*);
+/* TODO: overhaul repeatable infrastructure:
+ * - put is not really an operator, but should still be repeatable
+ * and respect count
+ " - review OP_REPEAT_{REPLACE,INSERT}
+ */
enum VisOperator {
OP_DELETE,
OP_CHANGE,
OP_YANK,
- OP_PUT,
+ OP_PUT_AFTER,
OP_SHIFT_RIGHT,
OP_SHIFT_LEFT,
OP_JOIN,
@@ -144,18 +149,9 @@ enum VisOperator {
OP_CASE_LOWER,
OP_CASE_UPPER,
OP_CURSOR_EOL,
-};
-
-/* TODO: overhaul repeatable infrastructure:
- * - put is not really an operator, but should still be repeatable
- * and respect count
- " - review OP_REPEAT_{REPLACE,INSERT}
- */
-enum {
- PUT_AFTER,
- PUT_AFTER_END,
- PUT_BEFORE,
- PUT_BEFORE_END,
+ OP_PUT_AFTER_END,
+ OP_PUT_BEFORE,
+ OP_PUT_BEFORE_END,
};
bool vis_operator(Vis*, enum VisOperator);