From dec8bc0015c9fc0e6f4283557cb088718348ec80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 1 Aug 2015 19:50:56 +0200 Subject: vis: add text objects `af` and `if` They try to match C-like function definitions. The inner variant only contains the function body. --- text-objects.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'text-objects.c') diff --git a/text-objects.c b/text-objects.c index 0308e8c..9f646dc 100644 --- a/text-objects.c +++ b/text-objects.c @@ -235,6 +235,25 @@ Filerange text_object_paragraph(Text *txt, size_t pos) { return r; } +Filerange text_object_function(Text *txt, size_t pos) { + size_t a = text_function_start_prev(txt, pos); + size_t b = text_function_end_next(txt, pos); + if (text_function_end_next(txt, a) == b) { + Filerange r = text_range_new(a, b+1); + return text_range_linewise(txt, &r); + } + return text_range_empty(); +} + +Filerange text_object_function_inner(Text *txt, size_t pos) { + Filerange r = text_object_function(txt, pos); + if (!text_range_valid(&r)) + return r; + size_t b = text_function_end_next(txt, pos); + size_t a = text_bracket_match(txt, b); + return text_range_new(a+1, b-1); +} + static Filerange text_object_bracket(Text *txt, size_t pos, char type) { char c, open, close; int opened = 1, closed = 1; -- cgit v1.2.3