aboutsummaryrefslogtreecommitdiff
path: root/config.def.h
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-09-04 19:56:30 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-09-04 19:56:30 +0200
commitb6efc2b99cdd1a6ca4e946401ca0661b91754f9c (patch)
tree56c269b203ace3773171f380a672094b5b8ad635 /config.def.h
parent1377a957ce7a7fe70405f8ec1e6cff5a74b9c40a (diff)
downloadvis-b6efc2b99cdd1a6ca4e946401ca0661b91754f9c.tar.gz
vis-b6efc2b99cdd1a6ca4e946401ca0661b91754f9c.tar.xz
Implement to/till movements i.e. 'f', 'F', 't', 'T'
Diffstat (limited to 'config.def.h')
-rw-r--r--config.def.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/config.def.h b/config.def.h
index 82052e0..be00942 100644
--- a/config.def.h
+++ b/config.def.h
@@ -74,6 +74,24 @@ static size_t mark_line_goto(const Arg *arg) {
return text_line_start(vis->win->text, mark_goto(arg));
}
+static size_t to(const Arg *arg) {
+ return text_find_char_next(vis->win->text, window_cursor_get(vis->win->win) + 1,
+ action.key.str, strlen(action.key.str));
+}
+
+static size_t till(const Arg *arg) {
+ return text_char_prev(vis->win->text, to(arg));
+}
+
+static size_t to_left(const Arg *arg) {
+ return text_find_char_prev(vis->win->text, window_cursor_get(vis->win->win) - 1,
+ action.key.str, strlen(action.key.str));
+}
+
+static size_t till_left(const Arg *arg) {
+ return text_char_next(vis->win->text, to_left(arg));
+}
+
static Operator ops[] = {
[OP_DELETE] = { op_delete, false },
[OP_CHANGE] = { op_change, false },
@@ -99,6 +117,10 @@ enum {
MOVE_PARAGRAPH_PREV,
MOVE_PARAGRAPH_NEXT,
MOVE_BRACKET_MATCH,
+ MOVE_LEFT_TO,
+ MOVE_RIGHT_TO,
+ MOVE_LEFT_TILL,
+ MOVE_RIGHT_TILL,
MOVE_FILE_BEGIN,
MOVE_FILE_END,
MOVE_MARK,
@@ -125,6 +147,10 @@ static Movement moves[] = {
[MOVE_BRACKET_MATCH] = { .txt = text_bracket_match, .type = LINEWISE|INCLUSIVE },
[MOVE_FILE_BEGIN] = { .txt = text_begin, .type = LINEWISE },
[MOVE_FILE_END] = { .txt = text_end, .type = LINEWISE },
+ [MOVE_LEFT_TO] = { .cmd = to_left, .type = LINEWISE },
+ [MOVE_RIGHT_TO] = { .cmd = to, .type = LINEWISE },
+ [MOVE_LEFT_TILL] = { .cmd = till_left, .type = LINEWISE },
+ [MOVE_RIGHT_TILL] = { .cmd = till, .type = LINEWISE },
[MOVE_MARK] = { .cmd = mark_goto, .type = LINEWISE },
[MOVE_MARK_LINE] = { .cmd = mark_line_goto, .type = LINEWISE },
};
@@ -239,6 +265,17 @@ static bool operator_invalid(const char *str, size_t len) {
return false;
}
+static void movement_key(const Arg *arg) {
+ Key k = getkey();
+ if (!k.str[0]) {
+ action_reset(&action);
+ return;
+ }
+ action.key = k;
+ action.movement = &moves[arg->i];
+ action_do(&action);
+}
+
static void movement(const Arg *arg) {
if (action.linewise && arg->i < LENGTH(moves_linewise))
action.textobj = moves_linewise[arg->i];
@@ -416,6 +453,10 @@ static KeyBinding vis_movements[] = {
{ { NONE(')') }, movement, { .i = MOVE_SENTENCE_NEXT } },
{ { NONE('g'), NONE('g') }, movement, { .i = MOVE_FILE_BEGIN } },
{ { NONE('G') }, movement, { .i = MOVE_FILE_END } },
+ { { NONE('f') }, movement_key, { .i = MOVE_RIGHT_TO } },
+ { { NONE('F') }, movement_key, { .i = MOVE_LEFT_TO } },
+ { { NONE('t') }, movement_key, { .i = MOVE_RIGHT_TILL } },
+ { { NONE('T') }, movement_key, { .i = MOVE_LEFT_TILL } },
{ /* empty last element, array terminator */ },
};