From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: David Ponce via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#73129: 31.0.50; buffer-text-pixel-size vs. newlines Date: Mon, 9 Sep 2024 00:22:11 +0200 Message-ID: <76135c62-bc5c-4bcd-9caa-ccd9f939d78f@orange.fr> Reply-To: David Ponce Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7128"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla Thunderbird To: 73129@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Sep 09 00:23:16 2024 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 1snQJQ-0001jo-9V for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 09 Sep 2024 00:23:16 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1snQJC-0005YI-0E; Sun, 08 Sep 2024 18:23:02 -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 1snQJA-0005Xv-7g for bug-gnu-emacs@gnu.org; Sun, 08 Sep 2024 18:23:00 -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 1snQJ9-0005jx-Up for bug-gnu-emacs@gnu.org; Sun, 08 Sep 2024 18:22:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=From:MIME-Version:Date:To:Subject; bh=aTiBrMz/4VEju3pejI30rqdqFLvppE9BaHgA7BcVt1s=; b=KyPhDKxXSE6gfm07DFjkHxyPuPCkiahKyMZoWVVx2fRV9efhgaWvZjdtgGZaY1d9hGD2OZ0Q1UzouhCKKlhdhXCsfntt3MyX78kmdUftlnUuYDpvmc4HkPhx7HdXtLfTBBnyMszV4f89eWxAQcmL/PPT0ijmoBXQdCcY8PUIZS3i87fhpgPVZvrExCUjAZPSoW+whR/+jG3BU65AT4DxiOOfCE6+9YJYd1RAA8od2EPD6Z8TZRohkdcvItWWCpFbZm2zQqSZiAx9goMEjTGUjUSX4w/128LsqPA3vL2XzZxa/ALfqGdkolHKpmfGCLuR4tpxq6gI2f/1eUImplfLcQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1snQJC-0007yC-Jw for bug-gnu-emacs@gnu.org; Sun, 08 Sep 2024 18:23:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: David Ponce Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 08 Sep 2024 22:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 73129 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.172583415130589 (code B ref -1); Sun, 08 Sep 2024 22:23:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 8 Sep 2024 22:22:31 +0000 Original-Received: from localhost ([127.0.0.1]:60258 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1snQIg-0007xI-W1 for submit@debbugs.gnu.org; Sun, 08 Sep 2024 18:22:31 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:54178) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1snQIe-0007x8-Oh for submit@debbugs.gnu.org; Sun, 08 Sep 2024 18:22:29 -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 1snQIY-0005W1-GU for bug-gnu-emacs@gnu.org; Sun, 08 Sep 2024 18:22:24 -0400 Original-Received: from smtp-26.smtpout.orange.fr ([80.12.242.26] helo=smtp.smtpout.orange.fr) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1snQIV-0005hs-8G for bug-gnu-emacs@gnu.org; Sun, 08 Sep 2024 18:22:22 -0400 Original-Received: from [192.168.1.21] ([2.7.225.247]) by smtp.orange.fr with ESMTPA id nQINsls3DQYYunQINsjKHw; Mon, 09 Sep 2024 00:22:13 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=orange.fr; s=t20230301; t=1725834133; bh=aTiBrMz/4VEju3pejI30rqdqFLvppE9BaHgA7BcVt1s=; h=Message-ID:Date:MIME-Version:To:From:Subject; b=QmucgkLvonCqqKx0fgJ7eTZwHwq8xza/o+8WS7WH/mqnO/H3bnVabUGZ086OKwcaq dzL3yrC4Z07PvJejRHBE6Ap/dvo7p4mEN0po3oS1C4gD+AMcuXoPuCR8plWBxMjoqv NCdD9UMX+NVkQteHXTRFT9WRakbn3z3aJjAJ4f5tUqn0Y2BGpBbU0ZGzbZzj9PfGAV XSGfBe2GiAR5Iab1aiBP52qkHr4eM8UFGLzyeOl1PGayNsJAbuZo0dANOnR0l0BaDq c84oCduQ4JPkxd19IJk28N4vP1aZFa7tn1nrV9v8+S4YqGBU6bgPnG+QMzptv60TQQ Tswy/223iOHEA== X-ME-Helo: [192.168.1.21] X-ME-Auth: ZGFfdmlkQHdhbmFkb28uZnI= X-ME-Date: Mon, 09 Sep 2024 00:22:13 +0200 X-ME-IP: 2.7.225.247 Content-Language: fr, en-US Received-SPF: pass client-ip=80.12.242.26; envelope-from=da_vid@orange.fr; helo=smtp.smtpout.orange.fr X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:291481 Archived-At: Hello, Its seems that the function `buffer-text-pixel-size' is not working as described when there are newlines in the buffer. Here is a quick illustration (on my laptop (frame-char-width) returns 12 pixels): ;; As expected. (with-temp-buffer (insert "abcdef") (car (buffer-text-pixel-size nil nil t))) 72 ;; I suppose it is as expected because newline is not displayed. (with-temp-buffer (insert "\n") (car (buffer-text-pixel-size nil nil t))) 0 ;; ? (with-temp-buffer (insert "abcd\nef") (car (buffer-text-pixel-size nil nil t))) 48 The doc string of `buffer-text-pixel-size' mentions: "Return size of whole text of BUFFER-OR-NAME in WINDOW." So ,I expect that the last example will return 72px (6 x 12px) + 0px for the newline. But the result is 48px, which means that all the text after the first newline is not counted. This also impacts "string-pixel-width" which is supposed to return the pixel size of the passed string, not part of it: (string-pixel-width "abcdef") => 72 (string-pixel-width "\n") => 0 (string-pixel-width "abcd\nef") => 48 (string-pixel-width "abcd\nef\ngh") => 48 At least this limitation should be mentioned in the doc string? A possible fix for `string-pixel-width' could be to remove all the newlines from the passed string before to call `buffer-text-pixel-size'? Something like this: diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index 4cdb065feeb..c68b3b37f9b 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el @@ -406,6 +406,11 @@ string-pixel-width face-remapping-alist)) (kill-local-variable 'face-remapping-alist)) (insert string) + ;; Remove newlines. + (forward-line 0) + (while (not (bobp)) + (delete-char -1) + (forward-line 0)) ;; Prefer `remove-text-properties' to `propertize' to avoid ;; creating a new string on each call. (remove-text-properties Thanks! In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.43, cairo version 1.18.0) Repository revision: 2ce0d397b12cafcb3e1ac5630bc3fbca61bd6b87 Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12014000 System Description: Fedora Linux 40 (KDE Plasma) Configured using: 'configure --with-x-toolkit=gtk3 --with-cairo-xcb --with-native-compilation=no PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig' Configured features: ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB Important settings: value of $LC_TIME: fr_FR.utf8 value of $LANG: fr_FR.UTF-8 locale-coding-system: utf-8-unix