andreyorst / fzf.kak

FZF for Kakoune
MIT License
143 stars 33 forks source link

ignore filenames in grep module #84

Closed purxiz closed 3 years ago

purxiz commented 3 years ago

This commit makes it so that fzf ignores the filenames and line numbers in the recursive grep module. I really couldn't find a nicer place to add these fzf-args, but I'm very open to fixing this PR with feedback from whoever. Basically fzf requires all grep tools to return filename:line_number:text, so we can ignore filename and line number with a column delimiter and then only looking from column 3 onward.

andreyorst commented 3 years ago

fzf.kak uses filename and line number information to jump, if we ignore it, the jump is impossible. But applying your patch I can't see what is actually changed, so I'm not sure what is the impact and what problem you're trying to solve? Can you elaborate a bit more on this?

with this patch: image

Without: image

From the manpage for fzf I see that

   --with-nth=N[,..]
          Transform the presentation of each line using field index expressions

   -d, --delimiter=STR
          Field delimiter regex for --nth and --with-nth (default: AWK-style)

But we don't use --with-nth in this plugin, so --delimeter seems not to have any effect. I assume that you have some local configuration, that sets the with-nth parameter, and I don't have it, so that's why I don't see any difference?

purxiz commented 3 years ago

Hi, --with-nth is the same as -n, which I have added to the config. Here's the relevant flags I've added for the grep module:

--delimiter=':' -n'3..'

Let's say you are in this project, and you try searching for the line fzf in :fzf-mode<g> (grep module, without my patch). Your results would be:

image

Since the program is currently considering the entire string returned by grep/ripgrep/etc., if you search for a phrase contained in a filename, you will get a bunch of results, equal to the number of lines in that file. With my patch, searching for fzf in the grep module only returns results where fzf is in the actual document text, as you would expect from a normal recursive grep:

image

The string and filename are still in the results, so jumping using them is still possible, but they are ignored by fzf for searching purposes, so you don't get a ton of duplicate results if there is a filename matching your search string. You can read a similar issue in the vim fzf repo: https://github.com/junegunn/fzf.vim/issues/346.

Overall, this only affects the functionality of the grep module, and makes it so it actually only greps, instead of also searching by filename and returning a ton of results.

andreyorst commented 3 years ago

Ah, I see, thanks for explanation. Yeah, this is definitively useful change! I think I can use it in some other modules as well

andreyorst commented 3 years ago

@purxiz Thanks for the tip! If you use fzf-project it will now also ignore paths, and use projcect names as match candidates only!