vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 0154e8e7a2505f19a768bf390c2e707e37de12d3
parent f0089e7f94597ad93c1a08f40cdc500d978bac71
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Fri, 12 Feb 2016 18:34:39 +0100

text-object: simplify text_object_range implementation

We can copy the initial iterator and use it in reverse direction.

Diffstat:
Mtext-objects.c | 11+++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/text-objects.c b/text-objects.c @@ -292,13 +292,12 @@ Filerange text_object_backtick(Text *txt, size_t pos) { Filerange text_object_range(Text *txt, size_t pos, int (*isboundary)(int)) { char c; size_t start; - Iterator it = text_iterator_get(txt, pos); - if (!text_iterator_byte_get(&it, &c) || boundary(c)) + Iterator it = text_iterator_get(txt, pos), rit = it; + if (!text_iterator_byte_get(&rit, &c) || boundary(c)) return text_range_empty(); - do start = it.pos; while (text_iterator_char_prev(&it, &c) && !boundary(c)); - it = text_iterator_get(txt, pos); - text_iterator_byte_get(&it, &c); - while (!boundary(c) && text_iterator_byte_next(&it, &c)); + char tmp = c; + do start = rit.pos; while (text_iterator_char_prev(&rit, &c) && !boundary(c)); + for (c = tmp; !boundary(c) && text_iterator_byte_next(&it, &c);); return text_range_new(start, it.pos); }