winnow.el icon indicating copy to clipboard operation
winnow.el copied to clipboard

match removes file indicator when ag-group-matches is t

Open yavitzour opened this issue 7 years ago • 1 comments

Hi,

I ran into the following problem - when ag-group-matches is t, the file name does not appear on each line but on a separate line once per group of matches of the same file. The window-match-lines command removes all the lines that do not match the regex, which usually include the lines containing the file names, so that after running the command I can no longer tell to which files the remaining lines belong.

Thanks, Yoav

yavitzour avatar May 22 '18 09:05 yavitzour

Oh ... so this actually the opposite compatibility problem to the issues discussed in https://github.com/dgtized/winnow.el/pull/4. You are entirely correct though, I guess leaning so heavily on keep-lines is pretty fragile and dependent on the grouping mode.

I will have to think on this a bit. I think for winnow-match-lines it's possible to modify the regexp passed to keep-lines to also mask and keep lines starting with ^File: . Unfortunately that wouldn't drop a given filename if it no longer had any matches in it. However, I don't think that hack would work for the corresponding flush-lines call, and I don't know if all of the outputs from ag, rg, ack, etc result in that File: prefix.

An alternative solution would be to use compilation-next-file and compilation-previous-file to find the boundaries between files and then run keep-lines/flush-lines on a per file basis, until no more files were available in the output. That could be further extended to remove file references with all matches dropped. That might not be as happy performance wise though, and is certainly a little more complicated implementation wise.

I might try to do a proof of concept of something tied a little more closely to the compilation mode functions at some point, but would also very much welcome patches for that or alternate solutions from anyone interested.

dgtized avatar Sep 30 '21 15:09 dgtized