vis

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

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

commit 781de2e66b803483223645685f1eaa58c2a719be
parent df42b0f87715bc62b7a94d750e0eda5007d01ce9
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Fri, 24 Jan 2020 11:14:57 +0100

sam: fix ^ anchor behavior in looping commands

Previsouly a command like:

    x/^.*\n/

would only select every second line.

Fixes #774

Diffstat:
Msam.c | 10+++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/sam.c b/sam.c @@ -1385,9 +1385,13 @@ static int extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Selecti RegexMatch match[nsub]; while (start < end || trailing_match) { trailing_match = false; - bool found = text_search_range_forward(txt, start, - end - start, cmd->regex, nsub, match, - start > range->start ? REG_NOTBOL : 0) == 0; + char c; + int flags = start > range->start && + text_byte_get(txt, start - 1, &c) && c != '\n' ? + REG_NOTBOL : 0; + bool found = !text_search_range_forward(txt, start, end - start, + cmd->regex, nsub, match, + flags); Filerange r = text_range_empty(); if (found) { if (argv[0][0] == 'x')