From a9db1caf19d34f13319a3ebf92100c2c92015582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Thu, 11 Feb 2016 10:32:49 +0100 Subject: vis: implement gn and gN text objects The behaviour when no match is found is not yet optimal. --- text-objects.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'text-objects.c') 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); -- cgit v1.2.3