diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2017-01-13 13:18:44 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2017-01-13 13:31:14 +0100 |
| commit | 4600b76efe80c9ba0461276412e58992d2300cae (patch) | |
| tree | cacbd17ffca5a50c541e9c8582df99f64e11bf89 /sam.c | |
| parent | 42d169f374f14595c52c523b40c97dc90707c46f (diff) | |
| download | vis-4600b76efe80c9ba0461276412e58992d2300cae.tar.gz vis-4600b76efe80c9ba0461276412e58992d2300cae.tar.xz | |
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.
Diffstat (limited to 'sam.c')
| -rw-r--r-- | sam.c | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -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; } |
