From e2c6526a97018f695d3d2e9a420c36bd2797b37b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Wed, 27 Jan 2016 18:30:22 +0100 Subject: vis: let % move to next special char if not already there --- vis-motions.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/vis-motions.c b/vis-motions.c index 3369051..07090c0 100644 --- a/vis-motions.c +++ b/vis-motions.c @@ -173,6 +173,27 @@ static size_t window_nop(Vis *vis, Win *win, size_t pos) { return pos; } +static size_t bracket_match(Text *txt, size_t pos) { + size_t hit = text_bracket_match_except(txt, pos, "<>\"'`"); + if (hit != pos) + return hit; + char current; + Iterator it = text_iterator_get(txt, pos); + while (text_iterator_byte_get(&it, ¤t)) { + switch (current) { + case '(': + case ')': + case '{': + case '}': + case '[': + case ']': + return it.pos; + } + text_iterator_byte_next(&it, NULL); + } + return pos; +} + void vis_motion_type(Vis *vis, enum VisMotionType type) { vis->action.type = type; } @@ -300,7 +321,7 @@ Movement vis_motions[] = { [VIS_MOVE_FUNCTION_START_NEXT] = { .txt = text_function_start_next, .type = LINEWISE|JUMP }, [VIS_MOVE_FUNCTION_END_PREV] = { .txt = text_function_end_prev, .type = LINEWISE|JUMP }, [VIS_MOVE_FUNCTION_END_NEXT] = { .txt = text_function_end_next, .type = LINEWISE|JUMP }, - [VIS_MOVE_BRACKET_MATCH] = { .txt = text_bracket_match, .type = INCLUSIVE|JUMP }, + [VIS_MOVE_BRACKET_MATCH] = { .txt = bracket_match, .type = INCLUSIVE|JUMP }, [VIS_MOVE_FILE_BEGIN] = { .txt = text_begin, .type = LINEWISE|JUMP }, [VIS_MOVE_FILE_END] = { .txt = text_end, .type = LINEWISE|JUMP }, [VIS_MOVE_LEFT_TO] = { .vis = to_left, }, -- cgit v1.2.3