vis

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

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

commit f24c725565f09ebea225d5054ccfde9e38a69c16
parent 9b5c6389c1e561e1016969ee60726209565ace65
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Thu, 28 Aug 2014 15:30:11 +0200

text-object: make word object behave more like in vim

Diffstat:
Mtext-objects.c | 12++++++------
Mtext-objects.h | 2++
2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/text-objects.c b/text-objects.c @@ -17,25 +17,25 @@ Filerange text_object_word(Text *txt, size_t pos) { text_iterator_byte_next(&it, NULL); text_iterator_byte_next(&it, &next); if (isspace(c)) { - /* we are in the middle of two words */ + /* middle of two words, include leading white space */ r.start = text_char_next(txt, text_word_end_prev(txt, pos)); - r.end = text_word_start_next(txt, pos); + r.end = text_char_next(txt, text_word_end_next(txt, pos)); } else if (isspace(prev) && isspace(next)) { /* on a single character */ r.start = pos; - r.end = text_char_next(txt, pos); + r.end = text_word_start_next(txt, pos); } else if (isspace(prev)) { /* at start of a word */ r.start = pos; - r.end = text_char_next(txt, text_word_end_next(txt, pos)); + r.end = text_word_start_next(txt, text_word_end_next(txt, pos)); } else if (isspace(next)) { /* at end of a word */ r.start = text_word_start_prev(txt, pos); - r.end = text_char_next(txt, pos); + r.end = text_word_start_next(txt, pos); } else { /* in the middle of a word */ r.start = text_word_start_prev(txt, pos); - r.end = text_char_next(txt, text_word_end_next(txt, pos)); + r.end = text_word_start_next(txt, text_word_end_next(txt, pos)); } return r; } diff --git a/text-objects.h b/text-objects.h @@ -4,6 +4,8 @@ #include <stddef.h> #include "text.h" +/* word which happens to be at pos, includes trailing white spaces. if at pos happens to + * be a whitespace include all neighbouring leading whitespaces and the following word. */ Filerange text_object_word(Text*, size_t pos); Filerange text_object_word_boundry(Text*, size_t pos, int (*isboundry)(int)); Filerange text_object_char(Text*, size_t pos, char c);