diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-02-03 13:15:44 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-02-03 16:22:44 +0100 |
| commit | f8503881ded44ed60d5270200a2344fca3849f17 (patch) | |
| tree | 2c8a281eaee2f191ad7e06d7723012a62d2ee7b8 | |
| parent | 1d315c96a4b53f4bf3e08dfcb8ff6bac01f130e1 (diff) | |
| download | vis-f8503881ded44ed60d5270200a2344fca3849f17.tar.gz vis-f8503881ded44ed60d5270200a2344fca3849f17.tar.xz | |
text-object: add utility function for abitrarily delimited text objects
| -rw-r--r-- | text-objects.c | 13 | ||||
| -rw-r--r-- | text-objects.h | 2 |
2 files changed, 15 insertions, 0 deletions
diff --git a/text-objects.c b/text-objects.c index a5d5d1c..b5dec88 100644 --- a/text-objects.c +++ b/text-objects.c @@ -287,6 +287,19 @@ Filerange text_object_backtick(Text *txt, size_t pos) { return text_object_bracket(txt, 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)) + 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)); + return text_range_new(start, it.pos); +} + Filerange text_range_linewise(Text *txt, Filerange *rin) { Filerange rout = *rin; rout.start = text_line_begin(txt, rin->start); diff --git a/text-objects.h b/text-objects.h index 5781b51..127b127 100644 --- a/text-objects.h +++ b/text-objects.h @@ -43,6 +43,8 @@ Filerange text_object_paranthese(Text*, size_t pos); Filerange text_object_quote(Text*, size_t pos); Filerange text_object_single_quote(Text*, size_t pos); Filerange text_object_backtick(Text*, size_t pos); +/* text object delimited by arbitrary chars for which isboundary returns non-zero */ +Filerange text_object_range(Text*, size_t pos, int (*isboundary)(int)); /* extend a range to cover whole lines */ Filerange text_range_linewise(Text*, Filerange*); |
