Hi Spencer.

Yes, that does resolve the issue. However, as you hinted, it causes issues with other diagnostic functions. In my tests, `ess-r-flymake' from the emacs speaks statistics (ess) package produces incorrect error positions. I wonder if `flymake-diag-region' should have an optional argument to not widen the buffer before calculating the positions.

Best,
Vangelis

On Sat, 18 May 2024 at 15:58, Spencer Baugh <sbaugh@janestreet.com> wrote:
Spencer Baugh <sbaugh@janestreet.com> writes:
> Can you test with the following patch, please?

Context:

It looks like the latex-mode flymake diagnostic function, tex-chktex,
widens before sending the buffer contents to the external linter
process.  So the line numbers of errors are reported relative to the
widened buffer, not the narrowed buffer.  A number of different checkers
in Emacs seem to do the same thing.

The bug is that these checkers call flymake-diag-region to translate the
line numbers into buffer positions.  But flymake-diag-region does not
widen the buffer when doing this translation, so it fails.

I expect you have some flymake logs of the form "Invalid region line=%s
col=%s". when triggering this bug.

Probably the right fix in flymake is to make flymake-diag-region widen,
as in the patch I posted, but that's a bit of a behavior change...  will
think about it, but it's probably fine.