vis

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

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

commit 66fdfa420da8a39747b1e04b70fd6d17c223d3fd
parent 40e227ba930e3f45eaac0152d3892c950be6f948
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Thu, 11 Feb 2021 12:58:06 +0100

sam: simplify trailing match handling for x/y commands

Should be no functional change, just a simpler implementation.

Diffstat:
Msam.c | 8++------
1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/sam.c b/sam.c @@ -1393,15 +1393,13 @@ static int extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Selecti Text *txt = win->file->text; if (cmd->regex) { - bool trailing_match = false; size_t start = range->start, end = range->end; size_t last_start = argv[0][0] == 'x' ? EPOS : start; size_t nsub = 1 + text_regex_nsub(cmd->regex); if (nsub > MAX_REGEX_SUB) nsub = MAX_REGEX_SUB; RegexMatch match[MAX_REGEX_SUB]; - while (start < end || trailing_match) { - trailing_match = false; + while (start <= end) { char c; int flags = start > range->start && text_byte_get(txt, start - 1, &c) && c != '\n' ? @@ -1418,7 +1416,6 @@ static int extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Selecti if (match[0].start == match[0].end) { if (last_start == match[0].start) { start++; - trailing_match = start == end; continue; } /* in Plan 9's regexp library ^ matches the beginning @@ -1433,11 +1430,10 @@ static int extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Selecti } else { start = match[0].end; } - trailing_match = start == end; } else { if (argv[0][0] == 'y') r = text_range_new(start, end); - start = end; + start = end + 1; } if (text_range_valid(&r)) {