diff options
| -rw-r--r-- | vis-core.h | 10 | ||||
| -rw-r--r-- | vis-text-objects.c | 52 | ||||
| -rw-r--r-- | vis.c | 13 |
3 files changed, 42 insertions, 33 deletions
@@ -70,10 +70,12 @@ typedef struct { /* Motion implementation, takes a cursor postion and returns a typedef struct { /* gets a cursor position and returns a file range (or text_range_empty()) * representing the text object containing the position. */ - Filerange (*range)(Text*, size_t pos); - enum { /* whether the object should include the delimiting symbols or not */ - INNER, - OUTER, + Filerange (*txt)(Text*, size_t pos); + Filerange (*vis)(Vis*, Text*, size_t pos); + enum { + INNER = 1 << 0, /* whether the object should include */ + OUTER = 1 << 1, /* the delimiting symbols or not */ + SPLIT = 1 << 2, /* whether multiple applications will yield a split range */ } type; } TextObject; diff --git a/vis-text-objects.c b/vis-text-objects.c index 76c7f1f..a4fe36f 100644 --- a/vis-text-objects.c +++ b/vis-text-objects.c @@ -10,31 +10,31 @@ void vis_textobject(Vis *vis, enum VisTextObject id) { } TextObject vis_textobjects[] = { - [VIS_TEXTOBJECT_INNER_WORD] = { text_object_word }, - [VIS_TEXTOBJECT_OUTER_WORD] = { text_object_word_outer }, - [VIS_TEXTOBJECT_INNER_LONGWORD] = { text_object_longword }, - [VIS_TEXTOBJECT_OUTER_LONGWORD] = { text_object_longword_outer }, - [VIS_TEXTOBJECT_SENTENCE] = { text_object_sentence }, - [VIS_TEXTOBJECT_PARAGRAPH] = { text_object_paragraph }, - [VIS_TEXTOBJECT_OUTER_SQUARE_BRACKET] = { text_object_square_bracket, OUTER }, - [VIS_TEXTOBJECT_INNER_SQUARE_BRACKET] = { text_object_square_bracket, INNER }, - [VIS_TEXTOBJECT_OUTER_CURLY_BRACKET] = { text_object_curly_bracket, OUTER }, - [VIS_TEXTOBJECT_INNER_CURLY_BRACKET] = { text_object_curly_bracket, INNER }, - [VIS_TEXTOBJECT_OUTER_ANGLE_BRACKET] = { text_object_angle_bracket, OUTER }, - [VIS_TEXTOBJECT_INNER_ANGLE_BRACKET] = { text_object_angle_bracket, INNER }, - [VIS_TEXTOBJECT_OUTER_PARANTHESE] = { text_object_paranthese, OUTER }, - [VIS_TEXTOBJECT_INNER_PARANTHESE] = { text_object_paranthese, INNER }, - [VIS_TEXTOBJECT_OUTER_QUOTE] = { text_object_quote, OUTER }, - [VIS_TEXTOBJECT_INNER_QUOTE] = { text_object_quote, INNER }, - [VIS_TEXTOBJECT_OUTER_SINGLE_QUOTE] = { text_object_single_quote, OUTER }, - [VIS_TEXTOBJECT_INNER_SINGLE_QUOTE] = { text_object_single_quote, INNER }, - [VIS_TEXTOBJECT_OUTER_BACKTICK] = { text_object_backtick, OUTER }, - [VIS_TEXTOBJECT_INNER_BACKTICK] = { text_object_backtick, INNER }, - [VIS_TEXTOBJECT_OUTER_ENTIRE] = { text_object_entire, }, - [VIS_TEXTOBJECT_INNER_ENTIRE] = { text_object_entire_inner, }, - [VIS_TEXTOBJECT_OUTER_FUNCTION] = { text_object_function, }, - [VIS_TEXTOBJECT_INNER_FUNCTION] = { text_object_function_inner, }, - [VIS_TEXTOBJECT_OUTER_LINE] = { text_object_line, }, - [VIS_TEXTOBJECT_INNER_LINE] = { text_object_line_inner, }, + [VIS_TEXTOBJECT_INNER_WORD] = { .txt = text_object_word }, + [VIS_TEXTOBJECT_OUTER_WORD] = { .txt = text_object_word_outer }, + [VIS_TEXTOBJECT_INNER_LONGWORD] = { .txt = text_object_longword }, + [VIS_TEXTOBJECT_OUTER_LONGWORD] = { .txt = text_object_longword_outer }, + [VIS_TEXTOBJECT_SENTENCE] = { .txt = text_object_sentence }, + [VIS_TEXTOBJECT_PARAGRAPH] = { .txt = text_object_paragraph }, + [VIS_TEXTOBJECT_OUTER_SQUARE_BRACKET] = { .txt = text_object_square_bracket, .type = OUTER }, + [VIS_TEXTOBJECT_INNER_SQUARE_BRACKET] = { .txt = text_object_square_bracket, .type = INNER }, + [VIS_TEXTOBJECT_OUTER_CURLY_BRACKET] = { .txt = text_object_curly_bracket, .type = OUTER }, + [VIS_TEXTOBJECT_INNER_CURLY_BRACKET] = { .txt = text_object_curly_bracket, .type = INNER }, + [VIS_TEXTOBJECT_OUTER_ANGLE_BRACKET] = { .txt = text_object_angle_bracket, .type = OUTER }, + [VIS_TEXTOBJECT_INNER_ANGLE_BRACKET] = { .txt = text_object_angle_bracket, .type = INNER }, + [VIS_TEXTOBJECT_OUTER_PARANTHESE] = { .txt = text_object_paranthese, .type = OUTER }, + [VIS_TEXTOBJECT_INNER_PARANTHESE] = { .txt = text_object_paranthese, .type = INNER }, + [VIS_TEXTOBJECT_OUTER_QUOTE] = { .txt = text_object_quote, .type = OUTER }, + [VIS_TEXTOBJECT_INNER_QUOTE] = { .txt = text_object_quote, .type = INNER }, + [VIS_TEXTOBJECT_OUTER_SINGLE_QUOTE] = { .txt = text_object_single_quote, .type = OUTER }, + [VIS_TEXTOBJECT_INNER_SINGLE_QUOTE] = { .txt = text_object_single_quote, .type = INNER }, + [VIS_TEXTOBJECT_OUTER_BACKTICK] = { .txt = text_object_backtick, .type = OUTER }, + [VIS_TEXTOBJECT_INNER_BACKTICK] = { .txt = text_object_backtick, .type = INNER }, + [VIS_TEXTOBJECT_OUTER_ENTIRE] = { .txt = text_object_entire, }, + [VIS_TEXTOBJECT_INNER_ENTIRE] = { .txt = text_object_entire_inner, }, + [VIS_TEXTOBJECT_OUTER_FUNCTION] = { .txt = text_object_function, }, + [VIS_TEXTOBJECT_INNER_FUNCTION] = { .txt = text_object_function_inner, }, + [VIS_TEXTOBJECT_OUTER_LINE] = { .txt = text_object_line, }, + [VIS_TEXTOBJECT_INNER_LINE] = { .txt = text_object_line_inner, }, }; @@ -503,15 +503,22 @@ void action_do(Vis *vis, Action *a) { else c.range.start = c.range.end = pos; for (int i = 0; i < count; i++) { - Filerange r = a->textobj->range(txt, pos); + Filerange r; + if (a->textobj->txt) + r = a->textobj->txt(txt, pos); + else + r = a->textobj->vis(vis, txt, pos); if (!text_range_valid(&r)) break; - if (a->textobj->type == OUTER) { + if (a->textobj->type & OUTER) { r.start--; r.end++; } - c.range = text_range_union(&c.range, &r); + if (a->textobj->type & SPLIT) + c.range = r; + else + c.range = text_range_union(&c.range, &r); if (i < count - 1) pos = c.range.end + 1; |
