vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 1e8ecf8e90ac7b606a3a6b88152a633d1072cbf9 parent 41af1ed639a68396880b4f3590638cce677f2828 Author: Marc André Tanner <mat@brain-dump.org> Date: Wed, 27 Jan 2016 18:30:22 +0100 vis: let % move to next special char if not already there Diffstat:
| M | vis-motions.c | | | 23 | ++++++++++++++++++++++- |
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git 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, },