vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 09bacf3f407cf6525eebfd6dc7c3a547615e2d55 parent d76f6b728ddb30447460f29818aff18a06c5451b Author: Marc André Tanner <mat@brain-dump.org> Date: Fri, 1 Apr 2016 21:37:52 +0200 sam: attempt to make x/y commands more robust These commands can be followed by an address which changes the range to which the sub command applies. The looping construct should then continue at the position of the last change within the original range. A previously problemeatic example: :sam x/^static/ .,+/^\}/ c/replaced Diffstat:
| M | sam.c | | | 12 | ++++++++---- |
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/sam.c b/sam.c @@ -685,14 +685,15 @@ static Filerange address_evaluate(Address *addr, File *file, Filerange *range, i static bool sam_execute(Vis *vis, Win *win, Command *cmd, Filerange *range) { bool ret = true; - Filerange r = cmd->address ? address_evaluate(cmd->address, win->file, range, 0) : *range; + if (cmd->address) + *range = address_evaluate(cmd->address, win->file, range, 0); switch (cmd->argv[0][0]) { case '{': { Text *txt = win->file->text; Mark start, end; - Filerange group = r; + Filerange group = *range; for (Command *c = cmd->cmd; c; c = c->next) { if (!text_range_valid(&group)) @@ -712,7 +713,7 @@ static bool sam_execute(Vis *vis, Win *win, Command *cmd, Filerange *range) { break; } default: - ret = cmd->cmddef->func(vis, win, cmd, &r); + ret = cmd->cmddef->func(vis, win, cmd, range); break; } return ret; @@ -823,6 +824,8 @@ static bool cmd_extract(Vis *vis, Win *win, Command *cmd, Filerange *range) { Mark mark_end = text_mark_set(txt, end); ret &= sam_execute(vis, win, cmd->cmd, &r); last_start = start = text_mark_get(txt, mark_start); + if (start == EPOS && last_start != r.end) + last_start = start = r.end; end = text_mark_get(txt, mark_end); if (start == EPOS || end == EPOS) return false; @@ -870,7 +873,8 @@ static bool cmd_select(Vis *vis, Win *win, Command *cmd, Filerange *range) { cursor = view_cursors_new(view, text_size(txt)+1); view_cursors_dispose(c); } - ret &= sam_execute(vis, win, cmd->cmd, &sel); + if (text_range_valid(&sel)) + ret &= sam_execute(vis, win, cmd->cmd, &sel); } if (cursor && !view_cursors_dispose(cursor)) {