Skip to content

Commit

Permalink
vis: prefix enum VisOperator values with VIS_
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Nov 7, 2015
1 parent 26b56bc commit 70a8265
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 101 deletions.
40 changes: 20 additions & 20 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,42 +663,42 @@ static KeyAction vis_action[] = {
[VIS_ACTION_OPERATOR_CHANGE] = {
"vis-operator-change",
"Change operator",
operator, { .i = OP_CHANGE }
operator, { .i = VIS_OP_CHANGE }
},
[VIS_ACTION_OPERATOR_DELETE] = {
"vis-operator-delete",
"Delete operator",
operator, { .i = OP_DELETE }
operator, { .i = VIS_OP_DELETE }
},
[VIS_ACTION_OPERATOR_YANK] = {
"vis-operator-yank",
"Yank operator",
operator, { .i = OP_YANK }
operator, { .i = VIS_OP_YANK }
},
[VIS_ACTION_OPERATOR_SHIFT_LEFT] = {
"vis-operator-shift-left",
"Shift left operator",
operator, { .i = OP_SHIFT_LEFT }
operator, { .i = VIS_OP_SHIFT_LEFT }
},
[VIS_ACTION_OPERATOR_SHIFT_RIGHT] = {
"vis-operator-shift-right",
"Shift right operator",
operator, { .i = OP_SHIFT_RIGHT }
operator, { .i = VIS_OP_SHIFT_RIGHT }
},
[VIS_ACTION_OPERATOR_CASE_LOWER] = {
"vis-operator-case-lower",
"Lowercase operator",
operator, { .i = OP_CASE_LOWER }
operator, { .i = VIS_OP_CASE_LOWER }
},
[VIS_ACTION_OPERATOR_CASE_UPPER] = {
"vis-operator-case-upper",
"Uppercase operator",
operator, { .i = OP_CASE_UPPER }
operator, { .i = VIS_OP_CASE_UPPER }
},
[VIS_ACTION_OPERATOR_CASE_SWAP] = {
"vis-operator-case-swap",
"Swap case operator",
operator, { .i = OP_CASE_SWAP }
operator, { .i = VIS_OP_CASE_SWAP }
},
[VIS_ACTION_COUNT] = {
"vis-count",
Expand Down Expand Up @@ -768,7 +768,7 @@ static KeyAction vis_action[] = {
[VIS_ACTION_JOIN_LINES] = {
"join-lines",
"Join selected lines",
operator, { .i = OP_JOIN }
operator, { .i = VIS_OP_JOIN }
},
[VIS_ACTION_PROMPT_SHOW] = {
"prompt-show",
Expand Down Expand Up @@ -833,22 +833,22 @@ static KeyAction vis_action[] = {
[VIS_ACTION_PUT_AFTER] = {
"put-after",
"Put text after the cursor",
operator, { .i = OP_PUT_AFTER }
operator, { .i = VIS_OP_PUT_AFTER }
},
[VIS_ACTION_PUT_BEFORE] = {
"put-before",
"Put text before the cursor",
operator, { .i = OP_PUT_BEFORE }
operator, { .i = VIS_OP_PUT_BEFORE }
},
[VIS_ACTION_PUT_AFTER_END] = {
"put-after-end",
"Put text after the cursor, place cursor after new text",
operator, { .i = OP_PUT_AFTER_END }
operator, { .i = VIS_OP_PUT_AFTER_END }
},
[VIS_ACTION_PUT_BEFORE_END] = {
"put-before-end",
"Put text before the cursor, place cursor after new text",
operator, { .i = OP_PUT_BEFORE_END }
operator, { .i = VIS_OP_PUT_BEFORE_END }
},
[VIS_ACTION_CURSOR_SELECT_WORD] = {
"cursors-select-word",
Expand All @@ -868,12 +868,12 @@ static KeyAction vis_action[] = {
[VIS_ACTION_CURSORS_NEW_LINES_BEGIN] = {
"cursors-new-lines-begin",
"Create a new cursor at the start of every line covered by selection",
operator, { .i = OP_CURSOR_SOL }
operator, { .i = VIS_OP_CURSOR_SOL }
},
[VIS_ACTION_CURSORS_NEW_LINES_END] = {
"cursors-new-lines-end",
"Create a new cursor at the end of every line covered by selection",
operator, { .i = OP_CURSOR_EOL }
operator, { .i = VIS_OP_CURSOR_EOL }
},
[VIS_ACTION_CURSORS_NEW_MATCH_NEXT] = {
"cursors-new-match-next",
Expand Down Expand Up @@ -1201,7 +1201,7 @@ static const char *replace(Vis *vis, const char *keys, const Arg *arg) {
char key[len+1];
memcpy(key, keys, len);
key[len] = '\0';
vis_operator(vis, OP_REPLACE);
vis_operator(vis, VIS_OP_REPLACE);
vis_motion(vis, MOVE_NOP);
vis_keys_inject(vis, next, key);
vis_keys_inject(vis, next+len, "<Escape>");
Expand Down Expand Up @@ -1361,7 +1361,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) {
vis_operator(vis, OP_DELETE);
vis_operator(vis, VIS_OP_DELETE);
vis_motion(vis, arg->i);
return keys;
}
Expand Down Expand Up @@ -1515,7 +1515,7 @@ static const char *window(Vis *vis, const char *keys, const Arg *arg) {
}

static const char *openline(Vis *vis, const char *keys, const Arg *arg) {
vis_operator(vis, OP_INSERT);
vis_operator(vis, VIS_OP_INSERT);
if (arg->i > 0) {
vis_motion(vis, MOVE_LINE_END);
vis_keys_inject(vis, keys, "<Enter>");
Expand All @@ -1530,7 +1530,7 @@ static const char *join(Vis *vis, const char *keys, const Arg *arg) {
int count = vis_count_get(vis);
if (count)
vis_count_set(vis, count-1);
vis_operator(vis, OP_JOIN);
vis_operator(vis, VIS_OP_JOIN);
vis_motion(vis, arg->i);
return keys;
}
Expand All @@ -1541,7 +1541,7 @@ static const char *switchmode(Vis *vis, const char *keys, const Arg *arg) {
}

static const char *insertmode(Vis *vis, const char *keys, const Arg *arg) {
vis_operator(vis, OP_INSERT);
vis_operator(vis, VIS_OP_INSERT);
vis_motion(vis, arg->i);
return keys;
}
Expand Down
4 changes: 2 additions & 2 deletions vis-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ extern Mode vis_modes[VIS_MODE_LAST];

extern Movement moves[MOVE_INVALID];

extern Operator ops[OP_INVALID];
extern Operator ops[VIS_OP_INVALID];

const char *expandtab(Vis *vis);

Expand All @@ -173,4 +173,4 @@ void action_reset(Action*);
void mode_set(Vis *vis, Mode *new_mode);
Mode *mode_get(Vis *vis, enum VisMode mode);

#endif
#endif
4 changes: 2 additions & 2 deletions vis-modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static void vis_mode_insert_enter(Vis *vis, Mode *old) {
macro_operator_record(vis);
action_reset(&vis->action_prev);
vis->action_prev.macro = vis->macro_operator;
vis->action_prev.op = &ops[OP_INSERT];
vis->action_prev.op = &ops[VIS_OP_INSERT];
}
}

Expand All @@ -138,7 +138,7 @@ static void vis_mode_replace_enter(Vis *vis, Mode *old) {
macro_operator_record(vis);
action_reset(&vis->action_prev);
vis->action_prev.macro = vis->macro_operator;
vis->action_prev.op = &ops[OP_REPLACE];
vis->action_prev.op = &ops[VIS_OP_REPLACE];
}
}

Expand Down
67 changes: 27 additions & 40 deletions vis-operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,6 @@
#include "text-util.h"
#include "util.h"

/** operators */
static size_t op_change(Vis*, Text*, OperatorContext *c);
static size_t op_yank(Vis*, Text*, OperatorContext *c);
static size_t op_put(Vis*, Text*, OperatorContext *c);
static size_t op_delete(Vis*, Text*, OperatorContext *c);
static size_t op_shift_right(Vis*, Text*, OperatorContext *c);
static size_t op_shift_left(Vis*, Text*, OperatorContext *c);
static size_t op_case_change(Vis*, Text*, OperatorContext *c);
static size_t op_join(Vis*, Text*, OperatorContext *c);
static size_t op_insert(Vis*, Text*, OperatorContext *c);
static size_t op_replace(Vis*, Text*, OperatorContext *c);
static size_t op_cursor(Vis*, Text*, OperatorContext *c);

Operator ops[] = {
[OP_DELETE] = { op_delete },
[OP_CHANGE] = { op_change },
[OP_YANK] = { op_yank },
[OP_PUT_AFTER] = { op_put },
[OP_SHIFT_RIGHT] = { op_shift_right },
[OP_SHIFT_LEFT] = { op_shift_left },
[OP_CASE_SWAP] = { op_case_change },
[OP_JOIN] = { op_join },
[OP_INSERT] = { op_insert },
[OP_REPLACE] = { op_replace },
[OP_CURSOR_SOL] = { op_cursor },
};

static size_t op_delete(Vis *vis, Text *txt, OperatorContext *c) {
c->reg->linewise = c->linewise;
register_put(c->reg, txt, &c->range);
Expand All @@ -58,15 +31,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 OP_PUT_AFTER:
case OP_PUT_AFTER_END:
case VIS_OP_PUT_AFTER:
case VIS_OP_PUT_AFTER_END:
if (c->reg->linewise)
pos = text_line_next(txt, pos);
else
pos = text_char_next(txt, pos);
break;
case OP_PUT_BEFORE:
case OP_PUT_BEFORE_END:
case VIS_OP_PUT_BEFORE:
case VIS_OP_PUT_BEFORE_END:
if (c->reg->linewise)
pos = text_line_begin(txt, pos);
break;
Expand All @@ -79,21 +52,21 @@ static size_t op_put(Vis *vis, Text *txt, OperatorContext *c) {

if (c->reg->linewise) {
switch (c->arg->i) {
case OP_PUT_BEFORE_END:
case OP_PUT_AFTER_END:
case VIS_OP_PUT_BEFORE_END:
case VIS_OP_PUT_AFTER_END:
pos = text_line_start(txt, pos);
break;
case OP_PUT_AFTER:
case VIS_OP_PUT_AFTER:
pos = text_line_start(txt, text_line_next(txt, c->pos));
break;
case OP_PUT_BEFORE:
case VIS_OP_PUT_BEFORE:
pos = text_line_start(txt, c->pos);
break;
}
} else {
switch (c->arg->i) {
case OP_PUT_AFTER:
case OP_PUT_BEFORE:
case VIS_OP_PUT_AFTER:
case VIS_OP_PUT_BEFORE:
pos = text_char_prev(txt, pos);
break;
}
Expand Down Expand Up @@ -157,9 +130,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 == OP_CASE_SWAP)
if (c->arg->i == VIS_OP_CASE_SWAP)
*cur = islower(ch) ? toupper(ch) : tolower(ch);
else if (c->arg->i == OP_CASE_UPPER)
else if (c->arg->i == VIS_OP_CASE_UPPER)
*cur = toupper(ch);
else
*cur = tolower(ch);
Expand All @@ -179,7 +152,7 @@ static size_t op_cursor(Vis *vis, Text *txt, OperatorContext *c) {
Cursor *cursor = view_cursors_new(view);
if (cursor) {
size_t pos;
if (c->arg->i == OP_CURSOR_EOL)
if (c->arg->i == VIS_OP_CURSOR_EOL)
pos = text_line_finish(txt, line);
else
pos = text_line_start(txt, line);
Expand Down Expand Up @@ -224,3 +197,17 @@ static size_t op_replace(Vis *vis, Text *txt, OperatorContext *c) {
macro_operator_record(vis);
return c->newpos != EPOS ? c->newpos : c->pos;
}

Operator ops[] = {
[VIS_OP_DELETE] = { op_delete },
[VIS_OP_CHANGE] = { op_change },
[VIS_OP_YANK] = { op_yank },
[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_INSERT] = { op_insert },
[VIS_OP_REPLACE] = { op_replace },
[VIS_OP_CURSOR_SOL] = { op_cursor },
};
38 changes: 19 additions & 19 deletions vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,9 @@ static void action_do(Vis *vis, Action *a) {
/* operator implementations must not change the mode,
* they might get called multiple times (once for every cursor)
*/
if (a->op == &ops[OP_INSERT] || a->op == &ops[OP_CHANGE])
if (a->op == &ops[VIS_OP_INSERT] || a->op == &ops[VIS_OP_CHANGE])
vis_mode_switch(vis, VIS_MODE_INSERT);
else if (a->op == &ops[OP_REPLACE])
else if (a->op == &ops[VIS_OP_REPLACE])
vis_mode_switch(vis, VIS_MODE_REPLACE);
else if (vis->mode == &vis_modes[VIS_MODE_OPERATOR])
mode_set(vis, vis->mode_prev);
Expand Down Expand Up @@ -964,23 +964,23 @@ int vis_run(Vis *vis, int argc, char *argv[]) {

bool vis_operator(Vis *vis, enum VisOperator id) {
switch (id) {
case OP_CASE_LOWER:
case OP_CASE_UPPER:
case OP_CASE_SWAP:
case VIS_OP_CASE_LOWER:
case VIS_OP_CASE_UPPER:
case VIS_OP_CASE_SWAP:
vis->action.arg.i = id;
id = OP_CASE_SWAP;
id = VIS_OP_CASE_SWAP;
break;
case OP_CURSOR_SOL:
case OP_CURSOR_EOL:
case VIS_OP_CURSOR_SOL:
case VIS_OP_CURSOR_EOL:
vis->action.arg.i = id;
id = OP_CURSOR_SOL;
id = VIS_OP_CURSOR_SOL;
break;
case OP_PUT_AFTER:
case OP_PUT_AFTER_END:
case OP_PUT_BEFORE:
case OP_PUT_BEFORE_END:
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 = OP_PUT_AFTER;
id = VIS_OP_PUT_AFTER;
break;
default:
break;
Expand All @@ -1006,7 +1006,7 @@ bool vis_operator(Vis *vis, enum VisOperator id) {
}

/* put is not a real operator, does not need a range to operate on */
if (id == OP_PUT_AFTER)
if (id == VIS_OP_PUT_AFTER)
vis_motion(vis, MOVE_NOP);

return true;
Expand All @@ -1022,11 +1022,11 @@ bool vis_motion(Vis *vis, enum VisMotion motion, ...) {

switch (motion) {
case MOVE_WORD_START_NEXT:
if (vis->action.op == &ops[OP_CHANGE])
if (vis->action.op == &ops[VIS_OP_CHANGE])
motion = MOVE_WORD_END_NEXT;
break;
case MOVE_LONGWORD_START_NEXT:
if (vis->action.op == &ops[OP_CHANGE])
if (vis->action.op == &ops[VIS_OP_CHANGE])
motion = MOVE_LONGWORD_END_NEXT;
break;
case MOVE_SEARCH_FORWARD:
Expand Down Expand Up @@ -1183,15 +1183,15 @@ void vis_repeat(Vis *vis) {
vis->action_prev.count = count;
count = vis->action_prev.count;
/* for some operators count should be applied only to the macro not the motion */
if (vis->action_prev.op == &ops[OP_INSERT] || vis->action_prev.op == &ops[OP_REPLACE])
if (vis->action_prev.op == &ops[VIS_OP_INSERT] || vis->action_prev.op == &ops[VIS_OP_REPLACE])
vis->action_prev.count = 1;
action_do(vis, &vis->action_prev);
vis->action_prev.count = count;
if (macro) {
Mode *mode = vis->mode;
Action action_prev = vis->action_prev;
count = action_prev.count;
if (count < 1 || action_prev.op == &ops[OP_CHANGE])
if (count < 1 || action_prev.op == &ops[VIS_OP_CHANGE])
count = 1;
for (int i = 0; i < count; i++) {
mode_set(vis, mode);
Expand Down
Loading

0 comments on commit 70a8265

Please sign in to comment.