diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2021-01-22 18:35:58 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2021-01-22 18:35:58 -0800 |
| commit | bea3e3e268ff3fdc3170ad5ee55b00be09d9ee64 (patch) | |
| tree | 452f22acb233927e26ae1fa1b2009cd83be133c4 /print.c | |
| parent | c46a8227d0bfc31e4f71b6441303348f5c31174b (diff) | |
Added nodent support (\N) for replacement strings. Slightly hacky, but
it works okay.
Diffstat (limited to 'print.c')
| -rw-r--r-- | print.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -307,6 +307,24 @@ static void _print_match(FILE *out, printer_t *pr, match_t *m) if (*r == '\\') { ++r; + if (*r == 'N') { // \N (nodent) + ++r; + // Mildly hacky: nodents here are based on the *first line* + // of the match. If the match spans multiple lines, or if + // the replacement text contains newlines, this may get weird. + const char *line_start = get_line( + pr->file, get_line_number(pr->file, m->start)); + char denter = *line_start; + fputc('\n', out); + ++line; + pr->needs_line_number = 1; + print_line_number(out, pr, 0, pr->use_color ? color_replace : NULL); + if (denter == ' ' || denter == '\t') { + for (const char *p = line_start; *p == denter && p < m->start; ++p) + fputc(denter, out); + } + continue; + } char c = unescapechar(r, &r); (void)fputc(c, out); if (c == '\n') { |
