Cc: stephen.berman@gmx.net, emacs-devel@gnu.org
From: Dmitry Gutov <dgutov@yandex.ru>
Date: Sun, 29 Nov 2020 19:32:17 +0200
If the calls to the conversion program are done in parallel to the
subsequent searches, reading the file twice might not be a problem (with
the benefit of a disk cache).
How do you mean "in parallel"? You cannot start searching until you
decide on the encoding, so it must not be in parallel.
How does Emacs do it? Does it read until the end of the file?
No, just a small initial part of it. That's one reason why the
results are not guaranteed to be correct.
But if we consider that approach good enough for Emacs, it should
probably be good enough for doing a search from inside Emacs.
It's good enough when the encoding is the locale's codeset, and in a
few other (not very important) cases. For an arbitrary combination of
file's encoding and locale's codeset, the result can be wrong every
single time.
And searching in non-ASCII files whose encoding is not the locale's
native one is precisely the case where this will fail. Granted, it's
a relatively rare use case, but when it does happen, all bets are off.