Closed rkleemann closed 7 years ago
See also #324 and #304.
@hoelzro: I think it would behoove us to stop and rethinking highlighting entirely, including coming up with a way to do Perl tests on highlights. This is clearly a pain point for us, and we need seat belts.
Yup, this is definitely a repeat of those bugs.
It would seem that since -o is outputting the correct match, that you have the right logic somewhere, and it just needs to be replicated.
There's that word, "just". :smiley:
The highlighting code is not simple, @rkleemann, which is why I want to overhaul it.
Yeah, it could probably use some love. Especially since we have a lot of duplicated stuff for optimization reasons.
one workaround for this is to use (?:...)
( echo foobar ; echo foobaz ; echo foobat ) | ack '\w+(?:bar|bat|baz)'
@gedge, yes, that would work around that problem. If you needed to repeat a pattern somewhere though, then it's not going to work properly:
$ ( echo foobarfoo ; echo FoobazFoo ; echo foobatfoo ) | ack '(\w+)(?:bar|bat|baz)\1'
_foo_barfoo
_Foo_bazFoo
_foo_batfoo
This is an intentional feature. It is removed in ack3.
I disagree that this is an intentional feature, but I'll patiently wait for ack3 to address it.
I'm not sure how it is that you can "disagree" that it's a feature.
Go look at print_line_with_options
and the section of code at if ( @+ > 1 ) { # If we have captures...
Ah, well then I have more faith in the description of it being an intended "feature".
When specifying a pattern with a set of parenthesis, the highlighted portion is not the full match, but only the parenthesized portion. Interestingly, -o outputs the correct thing.
For example:
Where the highlighted portions are surrounded by the underscores.