vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit f06cf264866d55f0c43c58e404f998838c60b771
parent 1f396fa323a6ff1748337b4e9550fcb37125e9d1
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Tue, 27 Feb 2018 16:17:55 +0100

vis: implement normal/outer paragraph text object

Diffstat:
Mconfig.def.h | 2+-
Mmain.c | 6++++++
Mtext-objects.c | 6++++++
Mtext-objects.h | 1+
Mvis-text-objects.c | 3+++
Mvis.h | 1+
6 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/config.def.h b/config.def.h @@ -106,7 +106,7 @@ static const KeyBinding bindings_textobjects[] = { { "aB", ALIAS("a{") }, { "ae", ACTION(TEXT_OBJECT_ENTIRE_OUTER) }, { "al", ACTION(TEXT_OBJECT_LINE_OUTER) }, - { "ap", ACTION(TEXT_OBJECT_PARAGRAPH) }, + { "ap", ACTION(TEXT_OBJECT_PARAGRAPH_OUTER) }, { "as", ACTION(TEXT_OBJECT_SENTENCE) }, { "a<Tab>", ACTION(TEXT_OBJECT_INDENTATION) }, { "aW", ACTION(TEXT_OBJECT_LONGWORD_OUTER) }, diff --git a/main.c b/main.c @@ -304,6 +304,7 @@ enum { VIS_ACTION_TEXT_OBJECT_LONGWORD_INNER, VIS_ACTION_TEXT_OBJECT_SENTENCE, VIS_ACTION_TEXT_OBJECT_PARAGRAPH, + VIS_ACTION_TEXT_OBJECT_PARAGRAPH_OUTER, VIS_ACTION_TEXT_OBJECT_SQUARE_BRACKET_OUTER, VIS_ACTION_TEXT_OBJECT_SQUARE_BRACKET_INNER, VIS_ACTION_TEXT_OBJECT_PARANTHESE_OUTER, @@ -1118,6 +1119,11 @@ static const KeyAction vis_action[] = { VIS_HELP("A paragraph") textobj, { .i = VIS_TEXTOBJECT_PARAGRAPH } }, + [VIS_ACTION_TEXT_OBJECT_PARAGRAPH_OUTER] = { + "vis-textobject-paragraph-outer", + VIS_HELP("A paragraph (outer variant)") + textobj, { .i = VIS_TEXTOBJECT_PARAGRAPH_OUTER } + }, [VIS_ACTION_TEXT_OBJECT_SQUARE_BRACKET_OUTER] = { "vis-textobject-square-bracket-outer", VIS_HELP("[] block (outer variant)") diff --git a/text-objects.c b/text-objects.c @@ -205,6 +205,12 @@ Filerange text_object_paragraph(Text *txt, size_t pos) { return r; } +Filerange text_object_paragraph_outer(Text *txt, size_t pos) { + Filerange p1 = text_object_paragraph(txt, pos); + Filerange p2 = text_object_paragraph(txt, p1.end); + return text_range_union(&p1, &p2); +} + static Filerange text_object_bracket(Text *txt, size_t pos, char type) { char c, open, close; int opened = 1, closed = 1; diff --git a/text-objects.h b/text-objects.h @@ -29,6 +29,7 @@ Filerange text_object_line(Text*, size_t pos); Filerange text_object_line_inner(Text*, size_t pos); Filerange text_object_sentence(Text*, size_t pos); Filerange text_object_paragraph(Text*, size_t pos); +Filerange text_object_paragraph_outer(Text*, size_t pos); /* these are inner text objects i.e. the delimiters themself are not * included in the range */ diff --git a/vis-text-objects.c b/vis-text-objects.c @@ -114,6 +114,9 @@ const TextObject vis_textobjects[] = { [VIS_TEXTOBJECT_PARAGRAPH] = { .txt = text_object_paragraph, }, + [VIS_TEXTOBJECT_PARAGRAPH_OUTER] = { + .txt = text_object_paragraph_outer, + }, [VIS_TEXTOBJECT_OUTER_SQUARE_BRACKET] = { .txt = text_object_square_bracket, .type = TEXTOBJECT_DELIMITED_OUTER, diff --git a/vis.h b/vis.h @@ -610,6 +610,7 @@ enum VisTextObject { VIS_TEXTOBJECT_OUTER_LONGWORD, VIS_TEXTOBJECT_SENTENCE, VIS_TEXTOBJECT_PARAGRAPH, + VIS_TEXTOBJECT_PARAGRAPH_OUTER, VIS_TEXTOBJECT_OUTER_SQUARE_BRACKET, VIS_TEXTOBJECT_INNER_SQUARE_BRACKET, VIS_TEXTOBJECT_OUTER_CURLY_BRACKET,