vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit e24e46370917f07e0d483c2d1f8ac54f37e0537a parent 48621349ea364b4bef8d21f1250eb1a4e79decdd Author: Marc André Tanner <mat@brain-dump.org> Date: Sat, 1 Aug 2015 13:20:40 +0200 vis: support `ae` and `ie` text objects Diffstat:
| M | README.md | | | 3 | +++ |
| M | config.def.h | | | 2 | ++ |
| M | text-objects.c | | | 17 | +++++++++++++++++ |
| M | text-objects.h | | | 4 | ++++ |
| M | vis.c | | | 4 | ++++ |
5 files changed, 30 insertions(+), 0 deletions(-)
diff --git 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 @@ -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 @@ -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 @@ -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 diff --git 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 */