Thanks, this is a solid proposal, but as per comment:
;; TODO: Show these matches as well somehow?
we would probably want to print these weird matches as well, in the
future. As you mention, search programs have a flag which avoids
printing these matches, but in certain rare cases it might happen that a
mostly text file is detected as binary - and then it seems preferable to
print all of such matches in the buffer rather than ignore them. (Unless
people disagree?)
And yeah, it's an old comment, so this improvement is not high on the
list, but whenever we (I/you/anybody else) get around to implementing
it,
What would be the "right thing to do"? Should we call grep and ugrep with "--binary-files=text" (and ripgrep has the equivalent "-a") and then ask Emacs to guess whether each match is "compatible" with the process encoding system and based on that decide whether to display the match or print a warning like "match found among unprintable binary data" nearby the file name?
--