diff options
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | config.def.h | 2 | ||||
| -rw-r--r-- | text-objects.c | 17 | ||||
| -rw-r--r-- | text-objects.h | 4 | ||||
| -rw-r--r-- | vis.c | 4 |
5 files changed, 30 insertions, 0 deletions
@@ -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 <stddef.h> #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 @@ -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 */ |
