aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-02-11 10:03:14 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-02-11 10:03:14 +0100
commit979d51bcb65ccceec95f34a10fdf6446ac97473c (patch)
treed06e2b6ed680a5f5a8279afc5fde58dc5a9f7037
parent534000b7831a6b536353053e47d582cf6c7f3053 (diff)
downloadvis-979d51bcb65ccceec95f34a10fdf6446ac97473c.tar.gz
vis-979d51bcb65ccceec95f34a10fdf6446ac97473c.tar.xz
vis: add support for different kind of text objects
Up until now text objects would only ever grow/expand if applied multiple times. The new SPLIT type allows text objects which cover a completely different range when applied with a count.
-rw-r--r--vis-core.h10
-rw-r--r--vis-text-objects.c52
-rw-r--r--vis.c13
3 files changed, 42 insertions, 33 deletions
diff --git a/vis-core.h b/vis-core.h
index f78e8af..74b8940 100644
--- a/vis-core.h
+++ b/vis-core.h
@@ -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, },
};
diff --git a/vis.c b/vis.c
index 96ee002..4c5124a 100644
--- a/vis.c
+++ b/vis.c
@@ -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;