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 /text-objects.c | |
| parent | 1d315c96a4b53f4bf3e08dfcb8ff6bac01f130e1 (diff) | |
| download | vis-f8503881ded44ed60d5270200a2344fca3849f17.tar.gz vis-f8503881ded44ed60d5270200a2344fca3849f17.tar.xz | |
text-object: add utility function for abitrarily delimited text objects
Diffstat (limited to 'text-objects.c')
| -rw-r--r-- | text-objects.c | 13 |
1 files changed, 13 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); |
