Subject: bug#76107: Consider image specs when scanning for a column

From: Thuna <[email-masked]>
Date: Tue, 18 Mar 2025 02:59:37 +0100

I have been using the patch for a while now.  I have just been using it
for regular tasks, so I have not been explicitly testing any edge cases.

I have not yet had any crashes, and as far as I can see, image sizes are
being calculated correctly.

So far, I have only had two related issues: The width calculation is
incorrect when dealing with characters which are not full-sized (they
are being calculated as though they were full-sized), and left margin[1]
is being included in the column number, but only when there is an image
from line start to point.

For the second situation, here's the MRE:
1. emacs -q
2. Switch to a new buffer, turn on org-mode, insert the text
   > foo \( \mathbb{R}^{*} \)
3. Call org-latex-preview on the latex fragment.
4. Eval (current-column) at the start of line, end of "foo", and the end
   of line, you should see 0, 3, and 6.
5. Turn on display-line-numbers-mode, and repeat above, you should now
   see 0, 3, and 10.

Alternatively, you could have the buffer contents be
> --------
> * Foo
> foo \( \mathbb{R}^{*} \)
and turn on org-indent-mode (but not display-line-numbers-mode).  You'll
then see that the column at the end of the latex preview is the same as
if it were calculated from the left edge of the buffer (using the dashes
as reference).

[1] That's probably what it is?  The specific thing I am
referring to is org-indent-mode and display-line-numbers-mode, which I
assume works using left margin.