aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-01-22 18:35:58 -0800
committerBruce Hill <bruce@bruce-hill.com>2021-01-22 18:35:58 -0800
commitbea3e3e268ff3fdc3170ad5ee55b00be09d9ee64 (patch)
tree452f22acb233927e26ae1fa1b2009cd83be133c4
parentc46a8227d0bfc31e4f71b6441303348f5c31174b (diff)
Added nodent support (\N) for replacement strings. Slightly hacky, but
it works okay.
-rw-r--r--print.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/print.c b/print.c
index eba311b..f0e2b9c 100644
--- a/print.c
+++ b/print.c
@@ -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') {