Skip to content

Commit

Permalink
vis: support ae and ie text objects
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Aug 1, 2015
1 parent 99753fa commit 25beaeb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */ },
};

Expand All @@ -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 */ },
};

Expand Down
17 changes: 17 additions & 0 deletions text-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions text-objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand All @@ -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 */
Expand Down

0 comments on commit 25beaeb

Please sign in to comment.