GNU bug report logs - #64986
30.0.50; window-text-pixel-size sometimes returns 0 width when called from temporary buffer

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Ihor Radchenko <yantar92@HIDDEN>; Keywords: confirmed; dated Tue, 1 Aug 2023 07:48:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.
Added tag(s) confirmed. Request was from Stefan Kangas <stefankangas@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 64986 <at> debbugs.gnu.org:


Received: (at 64986) by debbugs.gnu.org; 3 Aug 2023 08:55:34 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Aug 03 04:55:34 2023
Received: from localhost ([127.0.0.1]:50852 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1qRU7J-0003JN-TL
	for submit <at> debbugs.gnu.org; Thu, 03 Aug 2023 04:55:34 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:36138)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1qRU7I-0003JA-1g
 for 64986 <at> debbugs.gnu.org; Thu, 03 Aug 2023 04:55:32 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1qRU7B-0005QO-Io; Thu, 03 Aug 2023 04:55:25 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=SS1tFpmEBJZCnEd/laXyZzTGl1BrHeQrRASBaYhjkco=; b=PO5TI0mwJ939
 740SeJTXPAjGwhddoWtOh6nHjA2zeWHAU1VRGaok7Zw0f68FN3tWqn52krct2rKiMTFckcuZI+Itv
 ZfJ/7jPJgK4m+i1dSPtADKs2kmUEerwvyjATIPRSOg3oSR2lu9CbM7043GFl2hgINQXoh2NQKtnHC
 7nRcoycvSp/9zOyQW7pDJNuwj1mvaoV4exZiAXp9fEdbu48GPf1nBGG4OkjXkFWCXSSL/m9IFhxuz
 Rqwug+mgXX/EYC3hRvIoBJgX5J7LIl2a6sLOg/82pP9porBArPOVLGsDDXsF8Lf3RjZdd6orohUkm
 WzUAs9JslCNj/LLBuM4KPw==;
Received: from [87.69.77.57] (helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1qRU7B-0002GA-23; Thu, 03 Aug 2023 04:55:25 -0400
Date: Thu, 03 Aug 2023 11:55:35 +0300
Message-Id: <83fs50y06w.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Ihor Radchenko <yantar92@HIDDEN>,
 Lars Ingebrigtsen <larsi@HIDDEN>
In-Reply-To: <87edkmq523.fsf@localhost> (message from Ihor Radchenko on Tue,
 01 Aug 2023 13:13:08 +0000)
Subject: Re: bug#64986: 30.0.50; window-text-pixel-size sometimes returns 0
 width when called from temporary buffer
References: <87o7jrgq5n.fsf@localhost> <83pm470xuv.fsf@HIDDEN>
 <87edkmq523.fsf@localhost>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 64986
Cc: 64986 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Ihor Radchenko <yantar92@HIDDEN>
> Cc: 64986 <at> debbugs.gnu.org
> Date: Tue, 01 Aug 2023 13:13:08 +0000
> 
> Eli Zaretskii <eliz@HIDDEN> writes:
> 
> > 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.

Probably.  Patches to that effect are welcome.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#64986; Package emacs. Full text available.

Message received at 64986 <at> debbugs.gnu.org:


Received: (at 64986) by debbugs.gnu.org; 1 Aug 2023 13:13:03 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Aug 01 09:13:03 2023
Received: from localhost ([127.0.0.1]:47389 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1qQpBP-00049N-7B
	for submit <at> debbugs.gnu.org; Tue, 01 Aug 2023 09:13:03 -0400
Received: from mout01.posteo.de ([185.67.36.65]:35745)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <yantar92@HIDDEN>) id 1qQpBN-00048s-Ov
 for 64986 <at> debbugs.gnu.org; Tue, 01 Aug 2023 09:13:02 -0400
Received: from submission (posteo.de [185.67.36.169]) 
 by mout01.posteo.de (Postfix) with ESMTPS id B1887240029
 for <64986 <at> debbugs.gnu.org>; Tue,  1 Aug 2023 15:12:55 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017;
 t=1690895575; bh=p/nRSL2ShaxAwOUs0dzUvuDYJrclXyfrXqz4k5+0ZWY=;
 h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From;
 b=nc8q2nx/9CEkSDO511wd36DfFrT6TOm+8ZqBsPc9X9b7G9m2hnF5cYEfyJFbZoLt9
 n4s7n0L83JbWSDXBsXIj7DH3+Kz4NNXlJ3j8PNVnylY1FpjaplMkxb9IgO3aqUV/cj
 hHNlfhU1qb9HXpmXAdM8tY2tQOlAUJmvCNTPl5xqc3VRxk7w/An8Tl8C5SH6pEgvcp
 jJViIdbNOq5RcE8nY7I5pj7DbmA7FeysXNpvl6w0a1Zy1ION29sOeZn3m95gIukzs/
 G+4o+RW+eulk0s52GSrkXL6iT3EcMHYhL/icYJe8Mqo4rUcDICyp7rrhqhkQXIXacd
 dLryucjpswOyA==
Received: from customer (localhost [127.0.0.1])
 by submission (posteo.de) with ESMTPSA id 4RFbBZ37Sqz9rxD;
 Tue,  1 Aug 2023 15:12:54 +0200 (CEST)
From: Ihor Radchenko <yantar92@HIDDEN>
To: Eli Zaretskii <eliz@HIDDEN>
Subject: Re: bug#64986: 30.0.50; window-text-pixel-size sometimes returns 0
 width when called from temporary buffer
In-Reply-To: <83pm470xuv.fsf@HIDDEN>
References: <87o7jrgq5n.fsf@localhost> <83pm470xuv.fsf@HIDDEN>
Date: Tue, 01 Aug 2023 13:13:08 +0000
Message-ID: <87edkmq523.fsf@localhost>
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: -3.3 (---)
X-Debbugs-Envelope-To: 64986
Cc: 64986 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -4.3 (----)

Eli Zaretskii <eliz@HIDDEN> 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>




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#64986; Package emacs. Full text available.

Message received at 64986 <at> debbugs.gnu.org:


Received: (at 64986) by debbugs.gnu.org; 1 Aug 2023 12:07:58 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Aug 01 08:07:58 2023
Received: from localhost ([127.0.0.1]:47353 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1qQoAP-0008NK-OA
	for submit <at> debbugs.gnu.org; Tue, 01 Aug 2023 08:07:58 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:53966)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1qQoAL-0008N6-I9
 for 64986 <at> debbugs.gnu.org; Tue, 01 Aug 2023 08:07:55 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1qQoAG-0008Rq-3Q; Tue, 01 Aug 2023 08:07:48 -0400
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org;
 s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date:
 mime-version; bh=Zk9QHSFlD4QOcUquM3FX0IJnN2aj4irK7vDUgMnSkRE=; b=qq1vEH4Kw85G
 LLCcuinJj6CkiEuOtdQTw0xpP+yrWT4vPuseCgaG10tInQSn1bDTRQj/i5sqL7Kbu6/9LtwMad0y8
 OjIBRXsvCpQ4ISz2WT6NjVxrJVB27SoPboimZj/m4MAp6l3Xs1lELy5aHgs5CE8rUrh6WStf7WmA8
 IvUYlCUe5CHwtLCzdOpMFqraMkH9m8xway658WRXMR5Nc8CJN1TNzcS0Qma3+k5t+5NG8p7FSOHvD
 VfITCmT7pJJJeqviIPE+MqaEWQusTtnV5uVfPrsimVLTM4FZKNP6yT8qpdLl6tPYhHRM1gu9AJFee
 aNi13csEnyJGVBSp19e+9g==;
Received: from [87.69.77.57] (helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <eliz@HIDDEN>)
 id 1qQoAF-0004c5-GH; Tue, 01 Aug 2023 08:07:47 -0400
Date: Tue, 01 Aug 2023 15:07:52 +0300
Message-Id: <83pm470xuv.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Ihor Radchenko <yantar92@HIDDEN>
In-Reply-To: <87o7jrgq5n.fsf@localhost> (message from Ihor Radchenko on Tue,
 01 Aug 2023 07:47:32 +0000)
Subject: Re: bug#64986: 30.0.50;
 window-text-pixel-size sometimes returns 0 width when called from
 temporary buffer
References: <87o7jrgq5n.fsf@localhost>
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 64986
Cc: 64986 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Ihor Radchenko <yantar92@HIDDEN>
> Date: Tue, 01 Aug 2023 07:47:32 +0000
> 
>       (with-current-buffer (get-buffer-create " *Org string width*")
>         (setq-local display-line-numbers nil
>                     line-prefix nil
>                     wrap-prefix nil)
>         (setq-local buffer-invisibility-spec
>                     (if (listp current-invisibility-spec)
>                         (mapcar (lambda (el)
>                                   ;; Consider ellipsis to have 0 width.
>                                   ;; It is what Emacs 28+ does, but we have
>                                   ;; to force it in earlier Emacs versions.
>                                   (if (and (consp el) (cdr el))
>                                       (list (car el))
>                                     el))
>                                 current-invisibility-spec)
>                       current-invisibility-spec))
>         (setq-local char-property-alias-alist
>                     current-char-property-alias-alist)
>         (let (pixel-width symbol-width)
>           (with-silent-modifications
>             (erase-buffer)
>             (insert string)
>             (setq pixel-width
>                   (car (window-text-pixel-size
>                         nil (line-beginning-position) (point-max))))
>             (unless pixels
>               (erase-buffer)
>               (insert "a")
>               (setq symbol-width
>                     (car (window-text-pixel-size ;; <---- unexpected return
>                           nil (line-beginning-position) (point-max))))))
>           (if pixels
>               pixel-width
>             (/ pixel-width symbol-width)))))))

You are using window-text-pixel-size incorrectly.  Its doc string
says:

   Return the size of the text of WINDOW's buffer in pixels.

Note the "WINDOW's buffer" part: it is there for a reason.

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.

Your code seems to assume that with-current-buffer makes the named
buffer be "temporarily shown" in the selected window, but that is not
what happens: it just makes that buffer the current buffer.

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.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#64986; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 1 Aug 2023 07:47:34 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Aug 01 03:47:34 2023
Received: from localhost ([127.0.0.1]:47107 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1qQk6P-0007Jt-UC
	for submit <at> debbugs.gnu.org; Tue, 01 Aug 2023 03:47:34 -0400
Received: from lists.gnu.org ([2001:470:142::17]:58600)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <yantar92@HIDDEN>) id 1qQk6O-0007Jf-3t
 for submit <at> debbugs.gnu.org; Tue, 01 Aug 2023 03:47:32 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <yantar92@HIDDEN>)
 id 1qQk6I-0004su-TV
 for bug-gnu-emacs@HIDDEN; Tue, 01 Aug 2023 03:47:26 -0400
Received: from mout01.posteo.de ([185.67.36.65])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <yantar92@HIDDEN>)
 id 1qQk6G-0001C8-D3
 for bug-gnu-emacs@HIDDEN; Tue, 01 Aug 2023 03:47:26 -0400
Received: from submission (posteo.de [185.67.36.169]) 
 by mout01.posteo.de (Postfix) with ESMTPS id C8B91240028
 for <bug-gnu-emacs@HIDDEN>; Tue,  1 Aug 2023 09:47:21 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017;
 t=1690876041; bh=dIcgUhnuolgVext6gDl+gdy6cGtGkBfEiEmUwOncPPA=;
 h=From:To:Subject:Date:Message-ID:MIME-Version:From;
 b=U2tZxXOqCAsInmOUc4SaH81pTed6si5chlBuHXRMlkQr1dnYRSdrudrd6Z+CH1OTm
 4sGj1HUyT5Ml/XnOUTKd6TkXBjB23iskFZn5G3bKlGJ/0WKJYfVpmt20TFZ235cazw
 7AaHpEi+QTUkORQfh3C6HUmPbcRk/hQJd2ceTqmelrHwJgVhAXvWumniriewNENlM2
 Sv/T72f3XLRRWFfJIkkDVvloXHI7LgZCNM1Eqg676kjD4dfq4NEI8/kcI3lRoEddet
 dijlE6Oub2G42hZYtSQIlRRFIAhwRFNWxZ4SRg+cM2uSA0wyRfzOrHgLtG7OVmfZGb
 nzUG0Lhk2jffQ==
Received: from customer (localhost [127.0.0.1])
 by submission (posteo.de) with ESMTPSA id 4RFRyx11VGz9sH8
 for <bug-gnu-emacs@HIDDEN>; Tue,  1 Aug 2023 09:47:20 +0200 (CEST)
From: Ihor Radchenko <yantar92@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 30.0.50; window-text-pixel-size sometimes returns 0 width when
 called from temporary buffer
Date: Tue, 01 Aug 2023 07:47:32 +0000
Message-ID: <87o7jrgq5n.fsf@localhost>
MIME-Version: 1.0
Content-Type: text/plain
Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@HIDDEN;
 helo=mout01.posteo.de
X-Spam_score_int: -53
X-Spam_score: -5.4
X-Spam_bar: -----
X-Spam_report: (-5.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
 RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01,
 SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
 T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 1.0 (+)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)

Hi,

I stumbled upon apparently unexpected return value of
`window-text-pixel-size'. There is no easy reproducer involving emacs
-Q, but I can reliably reproduce it with certain variant of
`org-string-width' function. I am not 100% sure if it is a real Emacs
bug or if it is my misunderstanding of `window-text-pixel-size'.

Steps to reproduce:

1. git clone --depth 1 --branch bug/window-text-pixel-size https://git.sr.ht/~yantar92/org-mode
2. cd org-mode
3. make repro REPRO_ARGS="-l ./testing/org-test.el"
4. (setq org-confirm-babel-evaluate nil)
5. M-x debug-on-entry org-string-width
6. Insert and execute the following in *scratch*

  (org-test-with-temp-text-in-file "

#+NAME: example-list
- simple
  - not
  - nested
- list

<point>#+BEGIN_SRC emacs-lisp :var x=example-list
(print x)
#+END_SRC"

    (should (equal '("simple" "list") (org-babel-execute-src-block)))
    (forward-line 5)
    (should (string=
             "| simple | list |"
             (buffer-substring
	      (point-at-bol)
	      (point-at-eol)))))

7. If we "c" in the debugger, there is arith error originating from the
   second call to `window-text-pixel-size' returning (0 . X) in buffer
   containing text "a".

The code of `org-string-width' is:

(defun org-string-width (string &optional pixels)
  "Return width of STRING when displayed in the current buffer.
Return width in pixels when PIXELS is non-nil."
       ....
      (with-current-buffer (get-buffer-create " *Org string width*")
        (setq-local display-line-numbers nil
                    line-prefix nil
                    wrap-prefix nil)
        (setq-local buffer-invisibility-spec
                    (if (listp current-invisibility-spec)
                        (mapcar (lambda (el)
                                  ;; Consider ellipsis to have 0 width.
                                  ;; It is what Emacs 28+ does, but we have
                                  ;; to force it in earlier Emacs versions.
                                  (if (and (consp el) (cdr el))
                                      (list (car el))
                                    el))
                                current-invisibility-spec)
                      current-invisibility-spec))
        (setq-local char-property-alias-alist
                    current-char-property-alias-alist)
        (let (pixel-width symbol-width)
          (with-silent-modifications
            (erase-buffer)
            (insert string)
            (setq pixel-width
                  (car (window-text-pixel-size
                        nil (line-beginning-position) (point-max))))
            (unless pixels
              (erase-buffer)
              (insert "a")
              (setq symbol-width
                    (car (window-text-pixel-size ;; <---- unexpected return
                          nil (line-beginning-position) (point-max))))))
          (if pixels
              pixel-width
            (/ pixel-width symbol-width)))))))

In GNU Emacs 30.0.50 (build 5, x86_64-pc-linux-gnu, GTK+ Version
 3.24.38, cairo version 1.17.8) of 2023-07-29 built on localhost
Repository revision: ce48073f1597ceecb82800e71c89b53badc9f9d0
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101008
System Description: Gentoo Linux

Configured using:
 'configure --with-native-compilation'


-- 
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>




Acknowledgement sent to Ihor Radchenko <yantar92@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#64986; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Fri, 1 Sep 2023 20:45:01 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.