From 25beaeb21f3d0b2fcd9b6c612cd2d7cb25291a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 1 Aug 2015 13:20:40 +0200 Subject: vis: support `ae` and `ie` text objects --- README.md | 3 +++ config.def.h | 2 ++ text-objects.c | 17 +++++++++++++++++ text-objects.h | 4 ++++ vis.c | 4 ++++ 5 files changed, 30 insertions(+) diff --git a/README.md b/README.md index 54ab713..711e6fd 100644 --- a/README.md +++ b/README.md @@ -396,6 +396,9 @@ and their current support in vis. For sentence and paragraph there is no difference between the inner and normal variants. + Furthermore `ae` covers the entire content of a file, whereas `ie` + does not include leading and trailing empty lines. + ### Modes At the moment there exists a more or less functional insert, replace diff --git a/config.def.h b/config.def.h index 181dc7c..1a3a24c 100644 --- a/config.def.h +++ b/config.def.h @@ -165,6 +165,7 @@ static KeyBinding vis_textobjs[] = { { { NONE('a'), NONE('"') }, textobj, { .i = TEXT_OBJ_OUTER_QUOTE } }, { { NONE('a'), NONE('\'') }, textobj, { .i = TEXT_OBJ_OUTER_SINGLE_QUOTE } }, { { NONE('a'), NONE('`') }, textobj, { .i = TEXT_OBJ_OUTER_BACKTICK } }, + { { NONE('a'), NONE('e') }, textobj, { .i = TEXT_OBJ_OUTER_ENTIRE } }, { /* empty last element, array terminator */ }, }; @@ -186,6 +187,7 @@ static KeyBinding vis_inner_textobjs[] = { { { NONE('i'), NONE('"') }, textobj, { .i = TEXT_OBJ_INNER_QUOTE } }, { { NONE('i'), NONE('\'') }, textobj, { .i = TEXT_OBJ_INNER_SINGLE_QUOTE } }, { { NONE('i'), NONE('`') }, textobj, { .i = TEXT_OBJ_INNER_BACKTICK } }, + { { NONE('i'), NONE('e') }, textobj, { .i = TEXT_OBJ_INNER_ENTIRE } }, { /* empty last element, array terminator */ }, }; diff --git a/text-objects.c b/text-objects.c index 0d22ca4..0308e8c 100644 --- a/text-objects.c +++ b/text-objects.c @@ -22,6 +22,23 @@ #define isboundry is_word_boundry +Filerange text_object_entire(Text *txt, size_t pos) { + return text_range_new(0, text_size(txt)); +} + +Filerange text_object_entire_inner(Text *txt, size_t pos) { + char c; + Filerange r = text_object_entire(txt, pos); + Iterator it = text_iterator_get(txt, r.start); + while (text_iterator_byte_get(&it, &c) && (c == '\r' || c == '\n')) + text_iterator_byte_next(&it, NULL); + r.start = it.pos; + it = text_iterator_get(txt, r.end); + while (text_iterator_byte_prev(&it, &c) && (c == '\r' || c == '\n')); + r.end = it.pos; + return text_range_linewise(txt, &r); +} + /* TODO: reduce code duplication? */ Filerange text_object_longword(Text *txt, size_t pos) { diff --git a/text-objects.h b/text-objects.h index 068bafa..fb35d13 100644 --- a/text-objects.h +++ b/text-objects.h @@ -9,6 +9,10 @@ #include #include "text.h" +/* return range covering the entire text */ +Filerange text_object_entire(Text*, size_t pos); +/* entire document except leading and trailing empty lines */ +Filerange text_object_entire_inner(Text*, size_t pos); /* word which happens to be at pos without any neighbouring white spaces */ Filerange text_object_word(Text*, size_t pos); /* includes trailing white spaces. if at pos happens to be a white space diff --git a/vis.c b/vis.c index 976a476..c0c7390 100644 --- a/vis.c +++ b/vis.c @@ -247,6 +247,8 @@ enum { TEXT_OBJ_INNER_SINGLE_QUOTE, TEXT_OBJ_OUTER_BACKTICK, TEXT_OBJ_INNER_BACKTICK, + TEXT_OBJ_OUTER_ENTIRE, + TEXT_OBJ_INNER_ENTIRE, }; static TextObject textobjs[] = { @@ -270,6 +272,8 @@ static TextObject textobjs[] = { [TEXT_OBJ_INNER_SINGLE_QUOTE] = { text_object_single_quote, INNER }, [TEXT_OBJ_OUTER_BACKTICK] = { text_object_backtick, OUTER }, [TEXT_OBJ_INNER_BACKTICK] = { text_object_backtick, INNER }, + [TEXT_OBJ_OUTER_ENTIRE] = { text_object_entire, }, + [TEXT_OBJ_INNER_ENTIRE] = { text_object_entire_inner, }, }; /** functions to be called from keybindings */ -- cgit v1.2.3