aboutsummaryrefslogtreecommitdiff
path: root/sam.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-04-01 21:37:52 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-04-03 21:38:04 +0200
commit2c03c9797c06ec03de6f629cc3e73e447249a3bf (patch)
treea9d02c7a849399f8256f116d23c9c9b27e52f68e /sam.c
parent0ee497280f6fb6e293d5bba1efb7bc63eea2a05e (diff)
downloadvis-2c03c9797c06ec03de6f629cc3e73e447249a3bf.tar.gz
vis-2c03c9797c06ec03de6f629cc3e73e447249a3bf.tar.xz
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 (limited to 'sam.c')
-rw-r--r--sam.c12
1 files changed, 8 insertions, 4 deletions
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)) {