From 3ef242ae90ed7c798b83e2765cb721ef64e7516d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Wed, 3 Sep 2014 16:19:17 +0200 Subject: Introduce a logical line as text-object --- text-objects.c | 13 +++++++++++++ text-objects.h | 1 + 2 files changed, 14 insertions(+) diff --git a/text-objects.c b/text-objects.c index 4063992..bce8b5b 100644 --- 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 index 211e4e6..5b3895d 100644 --- 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); -- cgit v1.2.3