From: Junio C Hamano <gitster@pobox•com>
To: "René Scharfe" <l.s.r@web•de>
Cc: Zoltan Klinger <zoltan.klinger@gmail•com>, git@vger•kernel.org
Subject: Re: [PATCH][RFC] grep: add color.grep.matchcontext and color.grep.matchselected
Date: Mon, 27 Oct 2014 12:29:34 -0700 [thread overview]
Message-ID: <xmqqy4s1s44h.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <544E8D89.3030201@web.de> ("René Scharfe"'s message of "Mon, 27 Oct 2014 19:23:05 +0100")
René Scharfe <l.s.r@web•de> writes:
> The config option color.grep.match can be used to specify the highlighting
> color for matching strings. Add the options matchContext and matchSelected
> to allow different colors to be specified for matching strings in the
> context vs. in selected lines. This is similar to the ms and mc specifiers
> in GNU grep's environment variable GREP_COLORS.
>
> Signed-off-by: Rene Scharfe <l.s.r@web•de>
> ---
> Only *very* lightly tested, and a test for t/is missing anyway. Just
> wanted to quickly show what I meant. You'd set color.grep.matchContext=""
> to turn off highlighting in context lines. What do you think?
I didn't realize that people wanted to see pieces on non-matching
lines highlighted. It makes certain sense, e.g. it would allow you
to spot near-misses, but that is only true for lines that neighbour
real hits, so...
I like this approach better in that it makes those who want a
different behaviour to do the work without breaking the expectation
of those who are used to the established behaviour.
Zoltan?
> Documentation/config.txt | 6 +++++-
> grep.c | 29 ++++++++++++++++++++++-------
> grep.h | 3 ++-
> 3 files changed, 29 insertions(+), 9 deletions(-)
>
> diff --git a/Documentation/config.txt b/Documentation/config.txt
> index 8b49813..78832ae 100644
> --- a/Documentation/config.txt
> +++ b/Documentation/config.txt
> @@ -885,7 +885,11 @@ color.grep.<slot>::
> `linenumber`;;
> line number prefix (when using `-n`)
> `match`;;
> - matching text
> + matching text (same as setting `matchContext` and `matchSelected`)
> +`matchContext`;;
> + matching text in context lines
> +`matchSelected`;;
> + matching text in selected lines
> `selected`;;
> non-matching text in selected lines
> `separator`;;
> diff --git a/grep.c b/grep.c
> index 4dc31ea..6e085f8 100644
> --- a/grep.c
> +++ b/grep.c
> @@ -35,7 +35,8 @@ void init_grep_defaults(void)
> strcpy(opt->color_filename, "");
> strcpy(opt->color_function, "");
> strcpy(opt->color_lineno, "");
> - strcpy(opt->color_match, GIT_COLOR_BOLD_RED);
> + strcpy(opt->color_match_context, GIT_COLOR_BOLD_RED);
> + strcpy(opt->color_match_selected, GIT_COLOR_BOLD_RED);
> strcpy(opt->color_selected, "");
> strcpy(opt->color_sep, GIT_COLOR_CYAN);
> opt->color = -1;
> @@ -101,12 +102,22 @@ int grep_config(const char *var, const char *value, void *cb)
> color = opt->color_function;
> else if (!strcmp(var, "color.grep.linenumber"))
> color = opt->color_lineno;
> - else if (!strcmp(var, "color.grep.match"))
> - color = opt->color_match;
> + else if (!strcmp(var, "color.grep.matchcontext"))
> + color = opt->color_match_context;
> + else if (!strcmp(var, "color.grep.matchselected"))
> + color = opt->color_match_selected;
> else if (!strcmp(var, "color.grep.selected"))
> color = opt->color_selected;
> else if (!strcmp(var, "color.grep.separator"))
> color = opt->color_sep;
> + else if (!strcmp(var, "color.grep.match")) {
> + int rc = 0;
> + if (!value)
> + return config_error_nonbool(var);
> + rc |= color_parse(value, opt->color_match_context);
> + rc |= color_parse(value, opt->color_match_selected);
> + return rc;
> + }
>
> if (color) {
> if (!value)
> @@ -144,7 +155,8 @@ void grep_init(struct grep_opt *opt, const char *prefix)
> strcpy(opt->color_filename, def->color_filename);
> strcpy(opt->color_function, def->color_function);
> strcpy(opt->color_lineno, def->color_lineno);
> - strcpy(opt->color_match, def->color_match);
> + strcpy(opt->color_match_context, def->color_match_context);
> + strcpy(opt->color_match_selected, def->color_match_selected);
> strcpy(opt->color_selected, def->color_selected);
> strcpy(opt->color_sep, def->color_sep);
> }
> @@ -1084,7 +1096,7 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
> const char *name, unsigned lno, char sign)
> {
> int rest = eol - bol;
> - char *line_color = NULL;
> + const char *match_color, *line_color = NULL;
>
> if (opt->file_break && opt->last_shown == 0) {
> if (opt->show_hunk_mark)
> @@ -1123,6 +1135,10 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
> int eflags = 0;
>
> if (sign == ':')
> + match_color = opt->color_match_selected;
> + else
> + match_color = opt->color_match_context;
> + if (sign == ':')
> line_color = opt->color_selected;
> else if (sign == '-')
> line_color = opt->color_context;
> @@ -1135,8 +1151,7 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol,
>
> output_color(opt, bol, match.rm_so, line_color);
> output_color(opt, bol + match.rm_so,
> - match.rm_eo - match.rm_so,
> - opt->color_match);
> + match.rm_eo - match.rm_so, match_color);
> bol += match.rm_eo;
> rest -= match.rm_eo;
> eflags = REG_NOTBOL;
> diff --git a/grep.h b/grep.h
> index eaaced1..95f197a 100644
> --- a/grep.h
> +++ b/grep.h
> @@ -124,7 +124,8 @@ struct grep_opt {
> char color_filename[COLOR_MAXLEN];
> char color_function[COLOR_MAXLEN];
> char color_lineno[COLOR_MAXLEN];
> - char color_match[COLOR_MAXLEN];
> + char color_match_context[COLOR_MAXLEN];
> + char color_match_selected[COLOR_MAXLEN];
> char color_selected[COLOR_MAXLEN];
> char color_sep[COLOR_MAXLEN];
> int regflags;
next prev parent reply other threads:[~2014-10-27 19:29 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-21 5:56 [PATCH] grep: fix match highlighting for combined patterns with context lines Zoltan Klinger
2014-10-21 19:23 ` Junio C Hamano
2014-10-21 22:40 ` Junio C Hamano
2014-10-22 0:45 ` Zoltan Klinger
2014-10-22 19:14 ` Junio C Hamano
2014-10-26 18:15 ` René Scharfe
2014-10-27 18:23 ` [PATCH][RFC] grep: add color.grep.matchcontext and color.grep.matchselected René Scharfe
2014-10-27 19:29 ` Junio C Hamano [this message]
2014-10-27 19:47 ` Junio C Hamano
2014-10-27 23:32 ` Zoltan Klinger
2014-10-28 16:50 ` Junio C Hamano
2014-10-28 18:19 ` René Scharfe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqy4s1s44h.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=l.s.r@web$(echo .)de \
--cc=zoltan.klinger@gmail$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox