vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit a524929e8dd883cd7887666f94e0510da0cc4342
parent 9f661acb3d187d017625bf5e3a5dbb87d673d24d
Author: Marc André Tanner <mat@brain-dump.org>
Date: Wed, 13 Apr 2016 09:30:43 +0200
text-motion: simplify implementation of [{, ]}, [( and ]) motions
Diffstat:
| M | text-motions.c | | | 29 | ++++++++--------------------- |
1 file changed, 8 insertions(+), 21 deletions(-)
diff --git a/text-motions.c b/text-motions.c @@ -587,37 +587,24 @@ size_t text_function_end_prev(Text *txt, size_t pos) { return text_function_end_direction(txt, pos, -1); } -static size_t text_paren_start_end(Text *txt, size_t pos, int direction, Filerange (*rangefn)(Text *, size_t)) { - /* don't select (as a text obj) a bracket we're currently on */ - size_t offbracketpos = pos + direction; - - Filerange r = rangefn(txt, offbracketpos); - if (!text_range_valid(&r)) - return pos; - - /* we want the outer text object */ - r.start += direction; - r.end -= direction; - if (!text_range_valid(&r)) - return pos; - - return direction < 0 ? r.start : r.end; -} - size_t text_block_start(Text *txt, size_t pos) { - return text_paren_start_end(txt, pos, -1, text_object_curly_bracket); + Filerange r = text_object_curly_bracket(txt, pos-1); + return text_range_valid(&r) ? r.start-1 : pos; } size_t text_block_end(Text *txt, size_t pos) { - return text_paren_start_end(txt, pos, +1, text_object_curly_bracket); + Filerange r = text_object_curly_bracket(txt, pos+1); + return text_range_valid(&r) ? r.end : pos; } size_t text_parenthese_start(Text *txt, size_t pos) { - return text_paren_start_end(txt, pos, -1, text_object_paranthese); + Filerange r = text_object_paranthese(txt, pos-1); + return text_range_valid(&r) ? r.start-1 : pos; } size_t text_parenthese_end(Text *txt, size_t pos) { - return text_paren_start_end(txt, pos, +1, text_object_paranthese); + Filerange r = text_object_paranthese(txt, pos+1); + return text_range_valid(&r) ? r.end : pos; } size_t text_bracket_match(Text *txt, size_t pos) {