vis

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

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

commit 518c9baa8156469d8668cf87d9969c820137b470
parent f8a8bff981596bcc88a3a0199f6a887c6e6cb08e
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Wed,  3 Sep 2014 16:19:17 +0200

Introduce a logical line as text-object

Diffstat:
Mtext-objects.c | 13+++++++++++++
Mtext-objects.h | 1+
2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/text-objects.c b/text-objects.c @@ -41,6 +41,19 @@ Filerange text_object_word(Text *txt, size_t pos) { return r; } +Filerange text_object_line(Text *txt, size_t pos) { + char c; + Filerange r; + r.start = text_line_begin(txt, pos); + Iterator it = text_iterator_get(txt, text_line_end(txt, pos)); + if (text_iterator_byte_get(&it, &c) && c == '\n') + text_iterator_byte_next(&it, NULL); + if (text_iterator_byte_get(&it, &c) && c == '\r') + text_iterator_byte_next(&it, NULL); + r.end = it.pos; + return r; +} + Filerange text_object_sentence(Text *txt, size_t pos) { Filerange r; r.start = text_sentence_prev(txt, pos); diff --git a/text-objects.h b/text-objects.h @@ -8,6 +8,7 @@ * 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_line(Text*, size_t pos); Filerange text_object_sentence(Text*, size_t pos); Filerange text_object_paragraph(Text*, size_t pos);