`--and $pattern` to require non-ordered conjunction of RE matches
In the Slack we've discussed --and a few times, and most recently it was favorable, but never opened a ticket, so here is one.
--and $pattern opens a can of semantics worms: it could mean any of
- in the same line (obvious meaning / likely intent usually)
- in the same file (possibly ditto with
-fbut files withpatA --and patBin same line equally plausible) - same paragraph #171
- mutual -C12 context
(For --and with N>2 patterns, I'd consider allowing chained in-context but not fully-mutal matches (meaning each match within -C$nn lines of at least one other pattern's match in the current match context, but possibly more than $nn lines from some other matches) if and only if --proximate also set, as that is our existing feature that requires merging match contexts. Without it, each match context is exactly 1+2*$nn lines or with -B$bb -A$aa, $bb+1+$aa lines, and all N patterns must match at least once within that context, and at least one matches the current line.)
Slack discussion 2018-11-29 https://beyondgrep.slack.com/archives/C4J886HT2/p1543503390000600 highlights -
Andy > One thing to think about when we purse --and switches: Does the --and apply to the same line, or the same file? I think we’d want to support both.
ack loggingfunction --and Log4perl. Does that mean that the two things have to appear on the same line? Or is it that they are both in the same file somewhere?
I don’t think it makes sense to introduce one without the other.
Although the “both in the same file” can be done now with two ack invocations.
Bill > --and could be useful for several scopes --
- Same line (for which there is a regex workaround in cookbook)
- Same paragraph (doable with perl oneliner but not with any Ack cookbook today #171 )
- Within each-other's -C$n (doable with pipe in cookbook approximately)
- Same file (particularly useful with -f; emulable with pipe )
Andy > My first thought would be --and means same line. Clearly we need two different --ands.
Bill > Same line is the simplest and probably most useful particularly if we allow multiple of them (Same line And of two isn't hard to make in regex but 3+ gets ugly) (Cookbook has examples...)
I think we must have two --ands and --ors. They might be --andononesameline and --orononeline and --andinthesamefile and --orinthesamefile. Those names are horrible, of course, but they need to be explicit in how they're differnet.
Also, we can't combine any --and and --or options together. Also, we can't combine ononeline and inthesamefile options. It will be a nightmare.
And if we open this can of worms, are we going to want --not versions of everything too?