From 4600b76efe80c9ba0461276412e58992d2300cae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 13 Jan 2017 13:18:44 +0100 Subject: vis: introduce registers 0-9 and & to capture search matches These are currently only updated for `x` and `y` sam commands, whether they should be updated for other search related activities (`/`, `?`, `n`, `N`, `*`, `#` etc.) needs to be investigated. --- sam.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'sam.c') diff --git a/sam.c b/sam.c index a56bedb..5909a8e 100644 --- a/sam.c +++ b/sam.c @@ -1181,11 +1181,14 @@ static bool cmd_extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Cu if (cmd->regex) { bool trailing_match = false; size_t start = range->start, end = range->end, last_start = EPOS; - RegexMatch match[1]; + size_t nsub = 1 + text_regex_nsub(cmd->regex); + if (nsub > 10) + nsub = 10; + RegexMatch match[nsub]; while (start < end || trailing_match) { trailing_match = false; bool found = text_search_range_forward(txt, start, - end - start, cmd->regex, 1, match, + end - start, cmd->regex, nsub, match, start > range->start ? REG_NOTBOL : 0) == 0; Filerange r = text_range_empty(); if (found) { @@ -1216,6 +1219,12 @@ static bool cmd_extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Cu } if (text_range_valid(&r)) { + if (found) { + for (size_t i = 0; i < nsub; i++) { + Register *reg = &vis->registers[VIS_REG_AMPERSAND+i]; + register_put_range(vis, reg, txt, &match[i]); + } + } ret &= sam_execute(vis, win, cmd->cmd, NULL, &r); last_start = start; } -- cgit v1.2.3