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

Provide filtering function for matching extension

Open elton2048 opened this issue 4 years ago • 1 comments

Provide winnow-match-lines-with-extension for filtering certain extension in the result. All results in certain extension are shown for the result.

The function requires input for extension, a preset REGEXP representing the compilation results in a file in ag format is built to filter the result.

elton2048 avatar Mar 15 '20 13:03 elton2048

Apologies for such a long delay in response, but taking a look now. Unfortunately this isn't working for me locally. As example, I searched for interactive in the repo and generated:

-*- mode: ag; default-directory: "~/code/elisp/winnow.el/" -*-
Ag started at Thu Sep 30 09:51:59

ag --ignore TAGS --ignore .idea/ --ignore .vscode/ --ignore .ensime_cache/ --ignore .eunit/ --ignore .git/ --ignore .hg/ --ignore .fslckout/ --ignore _FOSSIL_/ --ignore .bzr/ --ignore _darcs/ --ignore .tox/ --ignore .svn/ --ignore .stack-work/ --ignore .ccls-cache/ --ignore .cache/ --ignore .clangd/ --literal --nogroup --line-number --column --color --color-match 30\;43 --color-path 1\;32 --smart-case --stats -- interactive .
test/output-grep.txt:7:72:winnow.el:66:(defun winnow-exclude-lines (regexp &optional rstart rend interactive)
test/output-ag-groups.txt:2:70:winnow.el:89:(defun winnow-match-lines (regexp &optional rstart rend interactive)
test/output-ag-groups.txt:3:86:winnow.el:104:(defun winnow-match-lines-with-extension (regexp &optional rstart rend interactive)
winnow.el:75:59:(defun winnow-exclude-lines (regexp &optional rstart rend interactive)
winnow.el:81:15:RSTART, REND, INTERACTIVE."
winnow.el:82:4:  (interactive (keep-lines-read-args "Flush lines containing match for regexp"))
winnow.el:86:35:    (flush-lines regexp start end interactive)
winnow.el:89:57:(defun winnow-match-lines (regexp &optional rstart rend interactive)
winnow.el:96:15:RSTART, REND, INTERACTIVE."
winnow.el:97:4:  (interactive (keep-lines-read-args "Keep lines containing match for regexp"))
winnow.el:101:34:    (keep-lines regexp start end interactive)
winnow.el:104:72:(defun winnow-match-lines-with-extension (regexp &optional rstart rend interactive)
winnow.el:114:15:RSTART, REND, INTERACTIVE."
winnow.el:115:4:  (interactive (keep-lines-read-args "Keep lines containing extension for regexp"))
winnow.el:123:37:    (keep-lines fullregex start end interactive)
15 matches
3 files contained matches
9 files searched
10762 bytes searched
0.000818 seconds

Ag finished at Thu Sep 30 09:51:59

If I use winnow-match-lines with the search regexp of keep it limits to the 5 matches expected. If I run winnow-match-lines-with-extentions with the argument el or .el or really any input it deletes everything including the initial ag command, which doesn't seem like the intended output. It also appears to be failing the test case that was modified.

I did some deeper debugging and discovered if I set (setq ag-group-matches t) then this filter will work. That option removes each of the file headers and places the filename on every line of match. That's likely part of the reason I haven't needed an extension filter is I can just first match on the filename type and then filter from there.

For context, with ag-group-matches t the interactive search in the repo looks like:

-*- mode: ag; default-directory: "~/code/elisp/winnow.el/" -*-
Ag started at Thu Sep 30 10:12:53

ag --ignore TAGS --ignore .idea/ --ignore .vscode/ --ignore .ensime_cache/ --ignore .eunit/ --ignore .git/ --ignore .hg/ --ignore .fslckout/ --ignore _FOSSIL_/ --ignore .bzr/ --ignore _darcs/ --ignore .tox/ --ignore .svn/ --ignore .stack-work/ --ignore .ccls-cache/ --ignore .cache/ --ignore .clangd/ --literal --group --line-number --column --color --color-match 30\;43 --color-path 1\;32 --smart-case --stats -- interactive .
File: test/output-grep.txt
7:72:winnow.el:66:(defun winnow-exclude-lines (regexp &optional rstart rend interactive)

File: test/output-ag-groups.txt
2:70:winnow.el:89:(defun winnow-match-lines (regexp &optional rstart rend interactive)
3:86:winnow.el:104:(defun winnow-match-lines-with-extension (regexp &optional rstart rend interactive)

File: winnow.el
75:59:(defun winnow-exclude-lines (regexp &optional rstart rend interactive)
81:15:RSTART, REND, INTERACTIVE."
82:4:  (interactive (keep-lines-read-args "Flush lines containing match for regexp"))
86:35:    (flush-lines regexp start end interactive)
89:57:(defun winnow-match-lines (regexp &optional rstart rend interactive)
96:15:RSTART, REND, INTERACTIVE."
97:4:  (interactive (keep-lines-read-args "Keep lines containing match for regexp"))
101:34:    (keep-lines regexp start end interactive)
104:72:(defun winnow-match-lines-with-extension (regexp &optional rstart rend interactive)
114:15:RSTART, REND, INTERACTIVE."
115:4:  (interactive (keep-lines-read-args "Keep lines containing extension for regexp"))
123:37:    (keep-lines fullregex start end interactive)
15 matches
3 files contained matches
9 files searched
10770 bytes searched
0.010180 seconds

Ag finished at Thu Sep 30 10:12:53

So I'm not quite sure how to proceed. I realize that the default is to keep matches grouped and I have opted into turning it off, but I would much prefer if this extension filter supported both modes of ag output. Maybe it should detect if there are grouping filename headers and only apply the filter if they exist. Perhaps it should fallback to matching on the line as a whole if no grouping filenames match, or throw an error that they are missing.

One extra design consideration, as it currently stands, all the functions in this plugin work with anything that produces compilation-mode compliant "error" output. While ag, ack, and rg all default to including the grouped filename, git grep doesn't appear to? I'm interested in merging some sort of functionality like this PR, but I would prefer it be a bit more resilient and less fragile to the input format. Happy to discuss though. Thoughts?

dgtized avatar Sep 30 '21 15:09 dgtized