beyondgrep / ack2

**ack 2 is no longer being maintained. ack 3 is the latest version.**
https://github.com/beyondgrep/ack3/
Other
1.48k stars 140 forks source link

Matching context with new lines in the regex doesn't work #522

Closed nowox closed 9 years ago

nowox commented 9 years ago

Inside the latest Ack2 repository I search for this:

 $ ack "current\ndirectory.*then" 
 249:Search for PATTERN in each source file in the tree from the current
 directory on down. If any files or directories are specified, then

But if I search the same with the context:

 $ ack -A2 "current\ndirectory.*then" 
 $ 

I don't see anything. This is because the way ack parse files. It does parse the file iterating lines when context is enabled and the whole file else. No exception is handled here. This is a bug.

hoelzro commented 9 years ago

This is definitely a bug; both in the inconsistency in operation between two modes that should be consistent, but also in your first example. Ack is line-based (see Can I do multi-line regexes? in the FAQ), but we read the file into a single chunk sometimes for optimization purposes.

hoelzro commented 9 years ago

Ok, this is fixed in dev now. Thanks for the report!