From 6ff7a6753032bc41098042258096bde73ed4bd1c Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 19 May 2021 21:12:41 -0700 Subject: When printing with zero context, put each match on its own line --- print.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/print.c b/print.c index a9a2f57..9e0897c 100644 --- a/print.c +++ b/print.c @@ -377,6 +377,13 @@ void print_match(FILE *out, printer_t *pr, match_t *m) if (m) { const char *before_m = context_before(pr, m->start); if (!first) { + // When not printing context lines, print each match on its own + // line instead of jamming them all together: + if (pr->context_lines == 0 && (!pr->needs_line_number || !pr->print_line_numbers)) { + fprintf(out, "\n"); + pr->needs_line_number = 1; + } + const char *after_last = context_after(pr, pr->pos); if (after_last >= before_m) { // Overlapping ranges: @@ -395,7 +402,7 @@ void print_match(FILE *out, printer_t *pr, match_t *m) const char *after_last = context_after(pr, pr->pos); print_between(out, pr, pr->pos, after_last, pr->use_color ? color_normal : NULL); // Guarantee trailing newline - if (!pr->needs_line_number) fprintf(out, "\n"); + if (!pr->needs_line_number || !pr->print_line_numbers) fprintf(out, "\n"); } if (pr->use_color) fprintf(out, "%s", color_normal); } -- cgit v1.2.3