From 2c03c9797c06ec03de6f629cc3e73e447249a3bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 1 Apr 2016 21:37:52 +0200 Subject: 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 --- sam.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'sam.c') diff --git a/sam.c b/sam.c index 69f57da..8956c47 100644 --- 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)) { -- cgit v1.2.3