Subject: Re: bug#64986: 30.0.50; window-text-pixel-size sometimes returns 0 width when called from temporary buffer

From: Ihor Radchenko <[email-masked]>
Date: Tue, 01 Aug 2023 13:13:08 +0000

Eli Zaretskii <[email-masked]> writes:

> So what your code is doing is measure the size of the text of the
> buffer shown in WINDOW (in your case, the selected window) between
> buffer positions 1 and 2.  And the buffer shown in the selected
> window, the one created by org-test-with-temp-text-in-file, begins
> with an empty line, so the function correctly returns zero as the
> horizontal dimensions of the text.

Ouch! Thanks for the explanation.

> This tricky part is why we now have buffer-text-pixel-size: it takes
> care of making the buffer "temporarily shown" in the window.  So I
> believe you should use that function instead.

Indeed. We previously used `set-window-buffer' as in shr.el, but that
felt like an awkward workaround because it can sometimes err when
selected-window is dedicated.

I am wondering if `shr-pixel-buffer-width' and `shr-pixel-column' should
also use `buffer-text-pixel-size'. The `(set-window-dedicated-p nil
nil)` is not nice as it could override user customization.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>