Subject: bug#26694: preview-at-point fails on very long lines with "End of buffer"

From: Mosè Giordano <[email-masked]>
Date: Fri, 28 Apr 2017 17:42:38 +0200

Hi Frank,

2017-04-28 15:26 GMT+02:00 Frank Fischer <[email-masked]>:
> Hi,
>
> consider the following example file https://pastebin.com/73W7EbCa
>
> This file has a single very long line with one math item at the end. Do
> the following:
>
> 1. generate the preview with C-c C-p C-p
> 2. move point to the "x" in the math block, change it to "y" and leave
> point within the math block
> 3. execute C-c C-p C-p again
>
> One should get the message "End of buffer" without the preview being
> regenerated.
>
> AFAICT the reason is that in this case only the snippet $x$ without the
> text preceding the snippet in the line is copied to the temporary file
> for generating the preview. However line 2103 in tex-buf.el (that is the
> line with "(forward-char (cdr line-col))") tries to move point to the
> *original* column of the snippet. This number is so large that
> "(forward-char ...)" will actually reach the end of the buffer and the
> error occurs.
>
> However, I would say the the column offset is just wrong. Either
> subtract the length of the preceding text (in the original buffer) from
> the column number or copy the preceding text to the temp buffer as well.
>
> I hope my description is clear, if not, please ask ;)

Thanks for the detailed bug report, I can reproduce it.  However,
right now I don't have the time to dig into it, but I found that the
issue should be in `TeX-region-create' and can be reproduced with
point on the "y" with

--8<---------------cut here---------------start------------->8---
(preview-region (preview-next-border t)
        (preview-next-border nil))
--8<---------------cut here---------------end--------------->8---

If someone else wants to look into it, please go ahead.

Bye,
Mosè