vis

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

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

commit 87881fe218550d71915014ad6bbb7da746f7060c
parent 120319a513c4ebe230f81c1a5f14227d38f7578c
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Fri,  4 Nov 2016 12:21:54 +0100

sam: y should also loop over empty trailing matches

The following

  x/example/ y/e/ i/-/

should produce `-e-xample-` where before it would wrongly
result in `-e-xample`.

Diffstat:
Msam.c | 6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sam.c b/sam.c @@ -895,9 +895,11 @@ static bool cmd_extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Cu Text *txt = win->file->text; if (cmd->regex) { + bool trailing_match = false; size_t start = range->start, end = range->end, last_start = EPOS; RegexMatch match[1]; - while (start < end) { + while (start < end || trailing_match) { + trailing_match = false; bool found = text_search_range_forward(txt, start, end - start, cmd->regex, 1, match, start > range->start ? REG_NOTBOL : 0) == 0; @@ -921,6 +923,8 @@ static bool cmd_extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Cu break; } start = match[0].end; + if (start == end) + trailing_match = true; } else { if (argv[0][0] == 'y') r = text_range_new(start, end);