From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#64986: 30.0.50; window-text-pixel-size sometimes returns 0 width when called from temporary buffer Date: Tue, 01 Aug 2023 15:07:52 +0300 Message-ID: <83pm470xuv.fsf@gnu.org> References: <87o7jrgq5n.fsf@localhost> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6299"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 64986@debbugs.gnu.org To: Ihor Radchenko Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Aug 01 14:08:24 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qQoAp-0001P1-0n for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 01 Aug 2023 14:08:23 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQoAX-0007Ku-No; Tue, 01 Aug 2023 08:08:05 -0400 Original-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 ) id 1qQoAV-0007En-6q for bug-gnu-emacs@gnu.org; Tue, 01 Aug 2023 08:08:03 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qQoAU-0000dV-3Q for bug-gnu-emacs@gnu.org; Tue, 01 Aug 2023 08:08:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qQoAT-0008Nc-Qw for bug-gnu-emacs@gnu.org; Tue, 01 Aug 2023 08:08:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 01 Aug 2023 12:08:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64986 X-GNU-PR-Package: emacs Original-Received: via spool by 64986-submit@debbugs.gnu.org id=B64986.169089167832203 (code B ref 64986); Tue, 01 Aug 2023 12:08:01 +0000 Original-Received: (at 64986) by debbugs.gnu.org; 1 Aug 2023 12:07:58 +0000 Original-Received: from localhost ([127.0.0.1]:47353 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qQoAP-0008NK-OA for submit@debbugs.gnu.org; Tue, 01 Aug 2023 08:07:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:53966) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qQoAL-0008N6-I9 for 64986@debbugs.gnu.org; Tue, 01 Aug 2023 08:07:55 -0400 Original-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 ) 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==; Original-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 ) id 1qQoAF-0004c5-GH; Tue, 01 Aug 2023 08:07:47 -0400 In-Reply-To: <87o7jrgq5n.fsf@localhost> (message from Ihor Radchenko on Tue, 01 Aug 2023 07:47:32 +0000) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:266445 Archived-At: > From: Ihor Radchenko > 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.