diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-02-11 10:32:49 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-02-11 10:32:49 +0100 |
| commit | a9db1caf19d34f13319a3ebf92100c2c92015582 (patch) | |
| tree | 2bf64c214e276ab4ff7fc460cb889675c93e4d48 /text-objects.c | |
| parent | 979d51bcb65ccceec95f34a10fdf6446ac97473c (diff) | |
| download | vis-a9db1caf19d34f13319a3ebf92100c2c92015582.tar.gz vis-a9db1caf19d34f13319a3ebf92100c2c92015582.tar.xz | |
vis: implement gn and gN text objects
The behaviour when no match is found is not yet optimal.
Diffstat (limited to 'text-objects.c')
| -rw-r--r-- | text-objects.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/text-objects.c b/text-objects.c index a0ffe3c..a6d2230 100644 --- a/text-objects.c +++ b/text-objects.c @@ -340,6 +340,26 @@ Filerange text_object_filename(Text *txt, size_t pos) { return text_object_range(txt, pos, is_filename_boundary); } +Filerange text_object_search_forward(Text *txt, size_t pos, Regex *regex) { + size_t start = pos; + size_t end = text_size(txt); + RegexMatch match[1]; + bool found = start < end && !text_search_range_forward(txt, start, end - start, regex, 1, match, 0); + if (found) + return text_range_new(match[0].start, match[0].end); + return text_range_empty(); +} + +Filerange text_object_search_backward(Text *txt, size_t pos, Regex *regex) { + size_t start = 0; + size_t end = pos; + RegexMatch match[1]; + bool found = !text_search_range_backward(txt, start, end, regex, 1, match, 0); + if (found) + return text_range_new(match[0].start, match[0].end); + return text_range_empty(); +} + Filerange text_range_linewise(Text *txt, Filerange *rin) { Filerange rout = *rin; rout.start = text_line_begin(txt, rin->start); |
