From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Daniel Mendler Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 11 Apr 2021 21:17:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 47712@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16181757955315 (code B ref -1); Sun, 11 Apr 2021 21:17:02 +0000 Received: (at submit) by debbugs.gnu.org; 11 Apr 2021 21:16:35 +0000 Received: from localhost ([127.0.0.1]:55948 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVhRb-0001Nd-6V for submit@debbugs.gnu.org; Sun, 11 Apr 2021 17:16:35 -0400 Received: from lists.gnu.org ([209.51.188.17]:36724) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVhRZ-0001NV-28 for submit@debbugs.gnu.org; Sun, 11 Apr 2021 17:16:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVhRT-0006Vr-Ce for bug-gnu-emacs@gnu.org; Sun, 11 Apr 2021 17:16:32 -0400 Received: from server.qxqx.de ([2a01:4f8:121:346::180]:52291 helo=mail.qxqx.de) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVhRP-0007JX-5Q for bug-gnu-emacs@gnu.org; Sun, 11 Apr 2021 17:16:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=qxqx.de; s=mail1392553390; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Date: Message-ID:Subject:From:To:Sender:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=RCU83ztfaG9K95VfGgkpI6x3M0cQ3yT54yt6RlVZPv0=; b=uculD7Jx+kyPamAaUGOFcmPiXF MfrZ6MyTE94nRmFJcMBkFiDS412qxh1tVN9CJT1r7lLPLnB37PZTkH4ksExhvk2oOU6AgF4LctGpK qULVzDK4kPtWTghhg7DJGZbIMzDO6p9bUYVO/n2kD7O/uF7Wcl5gWDZr2BKW5Z/umvEU=; From: Daniel Mendler Message-ID: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> Date: Sun, 11 Apr 2021 23:16:13 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=2a01:4f8:121:346::180; envelope-from=mail@daniel-mendler.de; helo=mail.qxqx.de X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) Provide a `string-display-width' function, which computes the `string-width', but takes invisible display properties into account. This function is often needed by packages. For example my Consult package (https://github.com/minad/consult) has a crude (non-recursive) version of that function. Then the Embark package has (https://github.com/oantolin/embark) has a similar function. Last but not least, the function already exists in Org under the name `org-string-width'. It is reasonable to implement this function in Elisp. But all the implementations have to use `string-width' for measuring the parts which make up the actual string. Unfortunately this requires allocations for the substrings. A possible solution to this problem is to implement a primitive function `substring-width' and implement `string-width' in terms of that function. (defun consult--display-width (string) "Compute width of STRING taking display and invisible properties into account." (let ((pos 0) (width 0) (end (length string))) (while (< pos end) (let ((nextd (next-single-property-change pos 'display string end)) (display (get-text-property pos 'display string))) (if (stringp display) (setq width (+ width (string-width display)) pos nextd) (while (< pos nextd) (let ((nexti (next-single-property-change pos 'invisible string nextd))) (unless (get-text-property pos 'invisible string) (setq width (+ width (string-width ;; Avoid allocation for the full string. ;; There should be a `substring-width' ;; provided by Emacs. TODO: Propose ;; upstream? Alternatively propose this ;; whole `display-width' function to ;; upstream. (if (and (= pos 0) (= nexti end)) string (substring-no-properties string pos nexti)))))) (setq pos nexti)))))) width)) From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Apr 2021 02:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Daniel Mendler Cc: 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.16181944262557 (code B ref 47712); Mon, 12 Apr 2021 02:28:02 +0000 Received: (at 47712) by debbugs.gnu.org; 12 Apr 2021 02:27:06 +0000 Received: from localhost ([127.0.0.1]:56126 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVmI5-0000fA-Tr for submit@debbugs.gnu.org; Sun, 11 Apr 2021 22:27:06 -0400 Received: from eggs.gnu.org ([209.51.188.92]:41060) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVmI4-0000eh-TD for 47712@debbugs.gnu.org; Sun, 11 Apr 2021 22:27:05 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:45418) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lVmHz-0002Y4-IT; Sun, 11 Apr 2021 22:26:59 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:2651 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lVmHx-0003n0-BX; Sun, 11 Apr 2021 22:26:57 -0400 Date: Mon, 12 Apr 2021 05:26:41 +0300 Message-Id: <83r1jg2q72.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> (message from Daniel Mendler on Sun, 11 Apr 2021 23:16:13 +0200) References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > From: Daniel Mendler > Date: Sun, 11 Apr 2021 23:16:13 +0200 > > Provide a `string-display-width' function, which computes the > `string-width', but takes invisible display properties into account. > This function is often needed by packages. We already have window-text-pixel-size; doesn't it fit the bill? If not, why not? From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Daniel Mendler Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Apr 2021 08:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.161821715618638 (code B ref 47712); Mon, 12 Apr 2021 08:46:02 +0000 Received: (at 47712) by debbugs.gnu.org; 12 Apr 2021 08:45:56 +0000 Received: from localhost ([127.0.0.1]:56401 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVsCi-0004qF-7v for submit@debbugs.gnu.org; Mon, 12 Apr 2021 04:45:56 -0400 Received: from server.qxqx.de ([178.63.65.180]:35125 helo=mail.qxqx.de) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVsCg-0004iv-AG for 47712@debbugs.gnu.org; Mon, 12 Apr 2021 04:45:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=qxqx.de; s=mail1392553390; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=pKl1qI9zFf/mKrYwiucwlHpfmNjhbU1ljTUoyZhPZwQ=; b=ZbwxqYLXHwG8sDv95wdQBtEH4o 0YHyo031227ntIB+/FaqTZLcBPecxmjewFUwX6P5GBf8zxXsyfqOLhWvZsF0SgIQo8Mbiynm/a/dd a5DHaqX8VpAfJMvygnroqGSBAgvo/MJVtTUeXBfjPFucU/s3VM0Ch/eRZyWP94NAkE6s=; References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> From: Daniel Mendler Message-ID: Date: Mon, 12 Apr 2021 10:45:45 +0200 MIME-Version: 1.0 In-Reply-To: <83r1jg2q72.fsf@gnu.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) On 4/12/21 4:26 AM, Eli Zaretskii wrote: > We already have window-text-pixel-size; doesn't it fit the bill? If > not, why not? `window-text-pixel-size` computes the size of a portion of the window, it does not take a string argument. The function `string-width` instead takes a string argument returning the number of columns needed to display this string. This function is needed to compute widths of strings which are not yet displayed. `string-display-width` is a proposed function which takes properties into account as `window-text-pixel-size` does, but without going through the display system first. Instead it computes the `string-width` of a flattened string, where the invisible parts have been removed and the displayed parts have been replaced. Orgmode uses its incarnation of `string-display-width`, `org-string-width`, for formatting its tables (see org-table.el). The width computation is performed before displaying the strings in the window. `substring-width` is a proposed generalization of `string-width` which allows computation of the width of a substring, without requiring the allocation of a substring. `string-display-width` or `substring-display-width` can be implemented based on `string-width` or `substring-width`, with`substring-width` being advantageous since it does not require the substring allocation. From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Apr 2021 08:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Daniel Mendler Cc: Eli Zaretskii , 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.161821764224409 (code B ref 47712); Mon, 12 Apr 2021 08:55:02 +0000 Received: (at 47712) by debbugs.gnu.org; 12 Apr 2021 08:54:02 +0000 Received: from localhost ([127.0.0.1]:56423 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVsKY-0006Ld-52 for submit@debbugs.gnu.org; Mon, 12 Apr 2021 04:54:02 -0400 Received: from quimby.gnus.org ([95.216.78.240]:48928) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVsKW-0006LA-Sd for 47712@debbugs.gnu.org; Mon, 12 Apr 2021 04:54:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=ikX8ltpt17yxtNWJwZEwCCsSo3E9yl5FpGa7aRaJBhk=; b=gdjq8B/QTjIga4eNdzt9LR1BIb GezBcDsng6r2vcJDvrv5pkQ9cO5jcEVKbqD4qB31yv2OG7TqUsJ7S28U38wDDtJGYQtgOy2QgsA7t qnRIi3CQivXOZ/PKcSbxtxEf/krbt4QDhFGR6gO9kVwDESaqPeJS51SYJQVi6tg/mhLU=; Received: from cm-84.212.220.105.getinternet.no ([84.212.220.105] helo=xo) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lVsKO-0005PI-Hz; Mon, 12 Apr 2021 10:53:55 +0200 From: Lars Ingebrigtsen References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> X-Now-Playing: Bertine Zetlitz's _Morbid Latenight Show_: "Snow On A Hot Day" Date: Mon, 12 Apr 2021 10:53:50 +0200 In-Reply-To: (Daniel Mendler's message of "Mon, 12 Apr 2021 10:45:45 +0200") Message-ID: <87h7kbzxwh.fsf@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: Daniel Mendler writes: > `window-text-pixel-size` computes the size of a portion of the window, > it does not take a string argument. The function `string-width` > instead takes a string argument returning the number of col [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Daniel Mendler writes: > `window-text-pixel-size` computes the size of a portion of the window, > it does not take a string argument. The function `string-width` > instead takes a string argument returning the number of columns needed > to display this string. This function is needed to compute widths of > strings which are not yet displayed. If I understand correctly (and I may not), the proposed function just takes properties into account (like `invisible' and `display'), but does not compute pixel sizes at all? I can see how that may be useful in some cases (and is very different from `window-text-pixel-size'), so I think adding something like that would be nice. But the name is confusing -- it sounds like it's computing the displayed width, and it's not -- if there's images or text with a different font in there, it's not taken into account? -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Daniel Mendler Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Apr 2021 09:10:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Lars Ingebrigtsen Cc: Eli Zaretskii , 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.16182185451635 (code B ref 47712); Mon, 12 Apr 2021 09:10:01 +0000 Received: (at 47712) by debbugs.gnu.org; 12 Apr 2021 09:09:05 +0000 Received: from localhost ([127.0.0.1]:56457 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVsZ6-0000QJ-TN for submit@debbugs.gnu.org; Mon, 12 Apr 2021 05:09:05 -0400 Received: from server.qxqx.de ([178.63.65.180]:53119 helo=mail.qxqx.de) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVsZ2-0000PZ-Ai for 47712@debbugs.gnu.org; Mon, 12 Apr 2021 05:09:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=qxqx.de; s=mail1392553390; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=9ntiCRVqOS8HKxTf41XkoOKgD2mt2pyfTal23PKK+/A=; b=pXUpaoy4xboSJJ8lkDonIJOtuS ZCoXXX0WAyhpzHho2wixg7NaMYBmLdCWz/9nUtHGAr/eYkC76DIRSzu7iWUobMVnpZPMmtHcfqZLX sbGuykhmkYxMtAWziV1gJFz4ldmzRQaybdK60usUGgiZVyGiu+yRvDyGyKfT9wuBm1DQ=; References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <87h7kbzxwh.fsf@gnus.org> From: Daniel Mendler Message-ID: <7c96d858-7947-0cca-60fc-1f6d027bb909@daniel-mendler.de> Date: Mon, 12 Apr 2021 11:08:52 +0200 MIME-Version: 1.0 In-Reply-To: <87h7kbzxwh.fsf@gnus.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) On 4/12/21 10:53 AM, Lars Ingebrigtsen wrote: > I can see how that may be useful in some cases (and is very different > from `window-text-pixel-size'), so I think adding something like that > would be nice. But the name is confusing -- it sounds like it's > computing the displayed width, and it's not -- if there's images or text > with a different font in there, it's not taken into account? Yes, a better name could be `string-property-width`? I proposed `string-display-width` since it takes the 'display property into account, but maybe this gives false associations. Note that I would like to have an implementation of `substring-width`/`string-display-width`/`substring-display-width` which does not allocate, since this reduces the GC pressure when formatting many items. How do you think about this? Regarding images, different fonts, maybe a `string-property-pixel-width` would be useful too. But for the use cases I have in mind (formatting monospaced text) computing columns is sufficient. From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Apr 2021 12:23:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Daniel Mendler Cc: 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.161823012421079 (code B ref 47712); Mon, 12 Apr 2021 12:23:01 +0000 Received: (at 47712) by debbugs.gnu.org; 12 Apr 2021 12:22:04 +0000 Received: from localhost ([127.0.0.1]:56726 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVvZs-0005Tu-CC for submit@debbugs.gnu.org; Mon, 12 Apr 2021 08:22:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50884) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVvZq-0005TQ-Gm for 47712@debbugs.gnu.org; Mon, 12 Apr 2021 08:22:02 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:53262) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lVvZk-0005bq-FJ; Mon, 12 Apr 2021 08:21:56 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:3089 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lVvZj-0001u5-Q6; Mon, 12 Apr 2021 08:21:56 -0400 Date: Mon, 12 Apr 2021 15:21:38 +0300 Message-Id: <83lf9n3d7x.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: (message from Daniel Mendler on Mon, 12 Apr 2021 10:45:45 +0200) References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > Cc: 47712@debbugs.gnu.org > From: Daniel Mendler > Date: Mon, 12 Apr 2021 10:45:45 +0200 > > On 4/12/21 4:26 AM, Eli Zaretskii wrote: > > We already have window-text-pixel-size; doesn't it fit the bill? If > > not, why not? > > `window-text-pixel-size` computes the size of a portion of the window, > it does not take a string argument. That is easy to work around, right? Just insert the string into a temporary buffer and say with-current-buffer (and/or with-selected-window, if needed). > The function `string-width` instead takes a string argument > returning the number of columns needed to display this string. This > function is needed to compute widths of strings which are not yet > displayed. But you compute the width because you are going to display that string soon enough, right? Or did I misunderstand the purpose? In general, calculating a string's width out of display context is meaningless in Emacs. More about that below. > `string-display-width` is a proposed function which takes properties > into account as `window-text-pixel-size` does, but without going through > the display system first. That's exactly my point: by not using the display code, you allow up front inaccurate results. There's no practical way to implement this in Lisp without yielding inaccurate and even grossly incorrect results in some cases (see below), so any such implementation will be limited from the get-go, in ways that are hard to even document precisely, let alone use reliably. Thus, users of such an implementation are bound to be unpleasantly surprised if they try using it in a situation different from yours. > Instead it computes the `string-width` of a flattened string, where > the invisible parts have been removed and the displayed parts have > been replaced. Yes, I understood what the code does. But it only handles some of the possible use cases, and will fail in others. For example, it ignores faces (which could change the metrics of characters); it assumes that all the characters of the string can be displayed by the buffer's fonts (because "tofu" has very different dimensions); it uses char-width to measure a character's width (which is only accurate for text-mode frames); it doesn't handle display properties that aren't strings, such as (space :align-to N); etc. > Orgmode uses its incarnation of `string-display-width`, > `org-string-width`, for formatting its tables (see org-table.el). The > width computation is performed before displaying the strings in the window. What you propose might be good enough for org-table, but it falls short of what is required from a general-purpose core feature: such a feature needs to support, or at least be able to support, all the possible display-related features that could affect the string's width. Your proposed implementation cannot support all of those features even in principle, because some of the display features mentioned above aren't accessible directly from Lisp. And if we try implementing this in C, we will end up with window-text-pixel-size, because that's why it was written in the first place. It was written to use the display code and requires a context of a window, because otherwise the problem you are trying to solve cannot be solved: features like fonts, faces, invisibility specs, etc. -- all of those depend on windows or buffers or frames, so trying to estimate a string's width without that context will produce incorrect results. So I urge you to try to use window-text-pixel-size for org-table and elsewhere, because that's what that function is for. If it lacks some feature or has bugs, we will improve it. Thanks. From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Daniel Mendler Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Apr 2021 12:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.161823183623965 (code B ref 47712); Mon, 12 Apr 2021 12:51:02 +0000 Received: (at 47712) by debbugs.gnu.org; 12 Apr 2021 12:50:36 +0000 Received: from localhost ([127.0.0.1]:56804 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVw1T-0006ET-Qc for submit@debbugs.gnu.org; Mon, 12 Apr 2021 08:50:36 -0400 Received: from server.qxqx.de ([178.63.65.180]:47231 helo=mail.qxqx.de) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVw1R-0006ED-LW for 47712@debbugs.gnu.org; Mon, 12 Apr 2021 08:50:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=qxqx.de; s=mail1392553390; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=p5PDg2yPlO4WqJMmcVNI16Oyp8YIylC/DDcP3ckC5iM=; b=kNOMnra7a7TvtOdYmojJu9hoXL NCUJFoK73PaWBH2Rx1qqHiOBKeRSzfDrfzU/8Xbr8fa7zYTnhyvBf3sUAPL3ww6HCeqcg+qxYZWAx A0HJ7+Z0XnDaHy8bxrGBU0yiRHsMsjvNkVdDteZTBcKwLbXvAa29hwo8fPdTwvNCwrjc=; References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <83lf9n3d7x.fsf@gnu.org> From: Daniel Mendler Message-ID: <1c8f7066-3da2-d960-11e7-a42f567432bd@daniel-mendler.de> Date: Mon, 12 Apr 2021 14:50:25 +0200 MIME-Version: 1.0 In-Reply-To: <83lf9n3d7x.fsf@gnu.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) On 4/12/21 2:21 PM, Eli Zaretskii wrote: > That is easy to work around, right? Just insert the string into a > temporary buffer and say with-current-buffer (and/or > with-selected-window, if needed). I have not tested this but I suspect this to be slow for a few thousand strings. >> The function `string-width` instead takes a string argument >> returning the number of columns needed to display this string. This >> function is needed to compute widths of strings which are not yet >> displayed. > > But you compute the width because you are going to display that string > soon enough, right? Or did I misunderstand the purpose? I am using it to generate candidate strings for `completing-read` and Org is using it to format tables. So no, I don't think that's soon enough. > In general, calculating a string's width out of display context is > meaningless in Emacs. More about that below. I know about the context dependence. But there is the `string-width` function which is also computed in the current context. I am only asking for an improved version of already existing functionality. My most minimal feature request is just a function `substring-width`. > That's exactly my point: by not using the display code, you allow up > front inaccurate results. There's no practical way to implement this > in Lisp without yielding inaccurate and even grossly incorrect results > in some cases (see below), so any such implementation will be limited > from the get-go, in ways that are hard to even document precisely, let > alone use reliably. Thus, users of such an implementation are bound > to be unpleasantly surprised if they try using it in a situation > different from yours. I agree that it would not work in all case. But why does `string-width` exist then? Is it deprecated? >> Instead it computes the `string-width` of a flattened string, where >> the invisible parts have been removed and the displayed parts have >> been replaced. > > Yes, I understood what the code does. But it only handles some of the > possible use cases, and will fail in others. For example, it ignores > faces (which could change the metrics of characters); it assumes that > all the characters of the string can be displayed by the buffer's > fonts (because "tofu" has very different dimensions); it uses > char-width to measure a character's width (which is only accurate for > text-mode frames); it doesn't handle display properties that aren't > strings, such as (space :align-to N); etc. That's right. In particular not supporting the :space alignment property is a serious limitation. But in text-mode frames the computation will return a correct result if it considers 'invisible and 'display recursively. > So I urge you to try to use window-text-pixel-size for org-table and > elsewhere, because that's what that function is for. If it lacks some > feature or has bugs, we will improve it. It is fair to reject the feature request for a `string-display/property-width` function, because it would be hard to implement a generally useful function. However if you attack `string-width` for not computing something correct, then one may want to consider deprecating `string-width` altogether or at least make it clear in the documentation that this function should not be used and something else based on the window function should be used instead. Note that `gnus-correct-length` has been replaced by `string-width`, so maybe Lars can say something about the justification for `string-width`? From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Apr 2021 13:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Daniel Mendler Cc: 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.161823370327331 (code B ref 47712); Mon, 12 Apr 2021 13:22:02 +0000 Received: (at 47712) by debbugs.gnu.org; 12 Apr 2021 13:21:43 +0000 Received: from localhost ([127.0.0.1]:56867 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVwVb-00076k-EZ for submit@debbugs.gnu.org; Mon, 12 Apr 2021 09:21:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39822) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVwVZ-00076W-Id for 47712@debbugs.gnu.org; Mon, 12 Apr 2021 09:21:42 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:54264) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lVwVT-0006rl-IE; Mon, 12 Apr 2021 09:21:35 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:2755 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lVwVQ-0003wt-BM; Mon, 12 Apr 2021 09:21:33 -0400 Date: Mon, 12 Apr 2021 16:21:15 +0300 Message-Id: <83im4r3agk.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <1c8f7066-3da2-d960-11e7-a42f567432bd@daniel-mendler.de> (message from Daniel Mendler on Mon, 12 Apr 2021 14:50:25 +0200) References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <83lf9n3d7x.fsf@gnu.org> <1c8f7066-3da2-d960-11e7-a42f567432bd@daniel-mendler.de> X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > Cc: 47712@debbugs.gnu.org > From: Daniel Mendler > Date: Mon, 12 Apr 2021 14:50:25 +0200 > > On 4/12/21 2:21 PM, Eli Zaretskii wrote: > > That is easy to work around, right? Just insert the string into a > > temporary buffer and say with-current-buffer (and/or > > with-selected-window, if needed). > > I have not tested this but I suspect this to be slow for a few thousand > strings. Can we please see both methods benchmarked? I'd also like to understand better in which situation you need to do this with thousands of strings in one go. In any case, I presume that running your code on thousands of strings also takes some time, let alone conses many strings. > > In general, calculating a string's width out of display context is > > meaningless in Emacs. More about that below. > > I know about the context dependence. But there is the `string-width` > function which is also computed in the current context. I am only asking > for an improved version of already existing functionality. My most > minimal feature request is just a function `substring-width`. string-width is from my POV a historical accident. The accident happened long ago enough to preclude deleting it, but I'd like to limit its use as much as possible. I certainly would like to avoid extending it or making it support more features (it currently supports only composed characters). > However if you attack `string-width` for not computing something > correct, then one may want to consider deprecating `string-width` > altogether or at least make it clear in the documentation that this > function should not be used and something else based on the window > function should be used instead. I'm fine with doing that, of course. From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Daniel Mendler Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Apr 2021 13:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.161823436528445 (code B ref 47712); Mon, 12 Apr 2021 13:33:02 +0000 Received: (at 47712) by debbugs.gnu.org; 12 Apr 2021 13:32:45 +0000 Received: from localhost ([127.0.0.1]:56877 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVwgG-0007Oj-Oj for submit@debbugs.gnu.org; Mon, 12 Apr 2021 09:32:44 -0400 Received: from server.qxqx.de ([178.63.65.180]:46497 helo=mail.qxqx.de) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVwgE-0007OS-14 for 47712@debbugs.gnu.org; Mon, 12 Apr 2021 09:32:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=qxqx.de; s=mail1392553390; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=I4YmBvHa2iFgUa4kKYpukVa5dW5/NURePC80Cjc3b6M=; b=WFnIqIpepRZ18R6AEqHY1E9Kb8 1pxKIIn5FlsH9j5aJQcwsJieSGmLk63pgtcu1vp1ZxojbsLiuXs6rQpdI2xu3ebeoCcnrNflYLdHh aYzM41QOWJ54PpYS0o10j7ibEOphAsr+1lSzgTRxK0ovtvqYP+QdsIChIeMriAJrLCjA=; References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <83lf9n3d7x.fsf@gnu.org> <1c8f7066-3da2-d960-11e7-a42f567432bd@daniel-mendler.de> <83im4r3agk.fsf@gnu.org> From: Daniel Mendler Message-ID: Date: Mon, 12 Apr 2021 15:32:33 +0200 MIME-Version: 1.0 In-Reply-To: <83im4r3agk.fsf@gnu.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) On 4/12/21 3:21 PM, Eli Zaretskii wrote: > Can we please see both methods benchmarked? I'd also like to > understand better in which situation you need to do this with > thousands of strings in one go. In any case, I presume that running > your code on thousands of strings also takes some time, let alone > conses many strings. Sure, I can prepare something in order to check if the slowdown is significant. > string-width is from my POV a historical accident. The accident > happened long ago enough to preclude deleting it, but I'd like to > limit its use as much as possible. I certainly would like to avoid > extending it or making it support more features (it currently supports > only composed characters). Okay, fair enough. I am all for removing/obsoleting functionality which is considered an accident as long as a good alternative exists. But if no acceptable alternative exists, the function has a justification and then it may also be possible to improve upon it. From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Apr 2021 13:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Daniel Mendler Cc: 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.161823487329277 (code B ref 47712); Mon, 12 Apr 2021 13:42:02 +0000 Received: (at 47712) by debbugs.gnu.org; 12 Apr 2021 13:41:13 +0000 Received: from localhost ([127.0.0.1]:56881 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVwoS-0007c8-KV for submit@debbugs.gnu.org; Mon, 12 Apr 2021 09:41:12 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45372) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVwoR-0007bw-Sd for 47712@debbugs.gnu.org; Mon, 12 Apr 2021 09:41:12 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:54677) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lVwoM-00022Z-7E; Mon, 12 Apr 2021 09:41:06 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:3951 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lVwoL-0000Dm-K3; Mon, 12 Apr 2021 09:41:06 -0400 Date: Mon, 12 Apr 2021 16:40:51 +0300 Message-Id: <83czuz39jw.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: (message from Daniel Mendler on Mon, 12 Apr 2021 15:32:33 +0200) References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <83lf9n3d7x.fsf@gnu.org> <1c8f7066-3da2-d960-11e7-a42f567432bd@daniel-mendler.de> <83im4r3agk.fsf@gnu.org> X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > Cc: 47712@debbugs.gnu.org > From: Daniel Mendler > Date: Mon, 12 Apr 2021 15:32:33 +0200 > > Okay, fair enough. I am all for removing/obsoleting functionality which > is considered an accident as long as a good alternative exists. But if > no acceptable alternative exists, the function has a justification and > then it may also be possible to improve upon it. Let's first establish whether indeed there's no alternative. I'd be surprised if that's the case, since window-text-pixel-size was written to support precisely this kind of need. From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Daniel Mendler Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Apr 2021 14:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.161823635232304 (code B ref 47712); Mon, 12 Apr 2021 14:06:01 +0000 Received: (at 47712) by debbugs.gnu.org; 12 Apr 2021 14:05:52 +0000 Received: from localhost ([127.0.0.1]:57631 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVxCK-0008Ox-5D for submit@debbugs.gnu.org; Mon, 12 Apr 2021 10:05:52 -0400 Received: from server.qxqx.de ([178.63.65.180]:57611 helo=mail.qxqx.de) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVxCI-0008Ok-25 for 47712@debbugs.gnu.org; Mon, 12 Apr 2021 10:05:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=qxqx.de; s=mail1392553390; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=bBWSU3M2wVGPk5qdZApeHZsZ1WFRUQVLVcvcxsX/stk=; b=aM+m1CsFlUY64r/fKzqooLEYso XIkcJ5un+R4vhYAFxA8g5QLusVC/kad8Q47L60zCMFMbR7V1zAvx0HUHxZQW+8azp3cGr0gmUpIR5 v0nfxxHY4u5U3FIK6O0VgwlLFwc7MMcKHXnb0lQASGsAaY8kCzenJt/J47b+Fgqsx/rQ=; References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <83lf9n3d7x.fsf@gnu.org> <1c8f7066-3da2-d960-11e7-a42f567432bd@daniel-mendler.de> <83im4r3agk.fsf@gnu.org> <83czuz39jw.fsf@gnu.org> From: Daniel Mendler Message-ID: Date: Mon, 12 Apr 2021 16:05:41 +0200 MIME-Version: 1.0 In-Reply-To: <83czuz39jw.fsf@gnu.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) I gave it a quick test. See the function `string-pixel-width` below. It seems that it does not take 'invisible and 'display into account. I probably have to change something to ensure that the properties are not ignored. But for we can still look at the micro benchmark. The `string-width` function is 200 times faster than the `string-pixel-width` function. This is a huge difference, but as usual with microbenchmarks, one can argue that the difference will be less pronounced in a realistic computation. I am still not happy with replacing `string-width` with something so much slower. However `window-text-pixel-size` also gives a different, much more precise result since it takes everything into account (or at least it should, invisible and display properties included). In the uses cases I mentioned one relies on monospace faces and formatting. (defmacro bench (&rest body) (let ((start (make-symbol "t"))) `(let (,start) (setq ,start (current-time)) ,@body (float-time (time-since ,start))))) (defun string-pixel-width (string) (with-temp-buffer (insert string) (car (window-text-pixel-size nil (point-min) (point-max))))) ;; returns 56 for all of the following strings, which is wrong (string-pixel-width "1234") (string-pixel-width (propertize "1234" 'invisible t)) (string-pixel-width (propertize "1234" 'display " ")) (defvar test-string (concat "some string with " (propertize "invisible substring" 'invisible t) " and " (propertize "a displayed substring" 'display "an overwritten substring"))) ;; 5s (bench (dotimes (_ 10000) (string-pixel-width test-string))) ;; 2.5s (bench (dotimes (_ 1000000) (string-width test-string))) ;; 3.5s (bench (dotimes (_ 1000000) (consult--display-width test-string))) From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Apr 2021 14:16:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Daniel Mendler Cc: 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.1618236943752 (code B ref 47712); Mon, 12 Apr 2021 14:16:01 +0000 Received: (at 47712) by debbugs.gnu.org; 12 Apr 2021 14:15:43 +0000 Received: from localhost ([127.0.0.1]:57641 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVxLr-0000C4-Cr for submit@debbugs.gnu.org; Mon, 12 Apr 2021 10:15:43 -0400 Received: from eggs.gnu.org ([209.51.188.92]:56038) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVxLp-0000Bp-7i for 47712@debbugs.gnu.org; Mon, 12 Apr 2021 10:15:41 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:55442) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lVxLj-0005Ay-Bi; Mon, 12 Apr 2021 10:15:35 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:2340 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lVxLi-0002p0-Ik; Mon, 12 Apr 2021 10:15:35 -0400 Date: Mon, 12 Apr 2021 17:15:17 +0300 Message-Id: <83blaj37yi.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: (message from Daniel Mendler on Mon, 12 Apr 2021 16:05:41 +0200) References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <83lf9n3d7x.fsf@gnu.org> <1c8f7066-3da2-d960-11e7-a42f567432bd@daniel-mendler.de> <83im4r3agk.fsf@gnu.org> <83czuz39jw.fsf@gnu.org> X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > Cc: 47712@debbugs.gnu.org > From: Daniel Mendler > Date: Mon, 12 Apr 2021 16:05:41 +0200 > > I gave it a quick test. See the function `string-pixel-width` below. It > seems that it does not take 'invisible and 'display into account. I > probably have to change something to ensure that the properties are not > ignored. If these properties are ignored, they will also be ignored on display. > But for we can still look at the micro benchmark. The `string-width` > function is 200 times faster than the `string-pixel-width` function. And if you reuse the same temp buffer? > I am still not happy with replacing `string-width` with something so > much slower. With 0.5 millisecond per call, I don't see a problem. And I expect that to go down if the buffer is reused. > (defmacro bench (&rest body) > (let ((start (make-symbol "t"))) > `(let (,start) > (setq ,start (current-time)) > ,@body > (float-time (time-since ,start))))) Please use benchmark-run, as that also tells us about GC during the run, and important aspect. From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Apr 2021 14:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: mail@daniel-mendler.de Cc: 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.16182380022910 (code B ref 47712); Mon, 12 Apr 2021 14:34:02 +0000 Received: (at 47712) by debbugs.gnu.org; 12 Apr 2021 14:33:22 +0000 Received: from localhost ([127.0.0.1]:57667 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVxcw-0000ks-19 for submit@debbugs.gnu.org; Mon, 12 Apr 2021 10:33:22 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60426) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVxcv-0000kf-DG for 47712@debbugs.gnu.org; Mon, 12 Apr 2021 10:33:21 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:55875) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lVxcp-0006t7-Bv; Mon, 12 Apr 2021 10:33:15 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:3417 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lVxcn-0000JD-C1; Mon, 12 Apr 2021 10:33:14 -0400 Date: Mon, 12 Apr 2021 17:32:56 +0300 Message-Id: <83a6q33753.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <83blaj37yi.fsf@gnu.org> (message from Eli Zaretskii on Mon, 12 Apr 2021 17:15:17 +0300) References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <83lf9n3d7x.fsf@gnu.org> <1c8f7066-3da2-d960-11e7-a42f567432bd@daniel-mendler.de> <83im4r3agk.fsf@gnu.org> <83czuz39jw.fsf@gnu.org> <83blaj37yi.fsf@gnu.org> X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > Date: Mon, 12 Apr 2021 17:15:17 +0300 > From: Eli Zaretskii > Cc: 47712@debbugs.gnu.org > > > But for we can still look at the micro benchmark. The `string-width` > > function is 200 times faster than the `string-pixel-width` function. > > And if you reuse the same temp buffer? My benchmarking indicates that reusing the buffer makes string-pixel-width only 10 times slower than string-width, i.e. 50 about microseconds per call. From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Daniel Mendler Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Apr 2021 14:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.16182381753236 (code B ref 47712); Mon, 12 Apr 2021 14:37:01 +0000 Received: (at 47712) by debbugs.gnu.org; 12 Apr 2021 14:36:15 +0000 Received: from localhost ([127.0.0.1]:57671 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVxfj-0000q8-Fp for submit@debbugs.gnu.org; Mon, 12 Apr 2021 10:36:15 -0400 Received: from server.qxqx.de ([178.63.65.180]:41767 helo=mail.qxqx.de) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVxfi-0000pt-3f for 47712@debbugs.gnu.org; Mon, 12 Apr 2021 10:36:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=qxqx.de; s=mail1392553390; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=YMfuFSGXQv0WAumb7pPyVZQ5orKoIourlPqGVyUfxwQ=; b=bRELxWVUO/paq1XENaAqYJGuoN oSchXGUtzBZnfUtNGet6EJdVXFsZgbjpilSM5emE+FlXp7roq4L8hrnRL13hV0vv4oDhte9ECCRxa WZ8XUar0ehcgfuU3c3d6t8bXpdIM6nImhSdispGKeR4FQyGzGyxjS6wkOFedb5vIVuWU=; References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <83lf9n3d7x.fsf@gnu.org> <1c8f7066-3da2-d960-11e7-a42f567432bd@daniel-mendler.de> <83im4r3agk.fsf@gnu.org> <83czuz39jw.fsf@gnu.org> <83blaj37yi.fsf@gnu.org> From: Daniel Mendler Message-ID: Date: Mon, 12 Apr 2021 16:36:05 +0200 MIME-Version: 1.0 In-Reply-To: <83blaj37yi.fsf@gnu.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) On 4/12/21 4:15 PM, Eli Zaretskii wrote: > If these properties are ignored, they will also be ignored on display. No, something is wrong. 'display should not be ignored. >> But for we can still look at the micro benchmark. The `string-width` >> function is 200 times faster than the `string-pixel-width` function. > > And if you reuse the same temp buffer? Sorry, I should have said that I tried reusing the same buffer. But it was not faster when I tried that. The buffer switching has a significant overhead. In order to get a fair benchmark one should measure the following: ;; 1.4s (with-temp-buffer (bench (dotimes (_ 10000) (erase-buffer) (insert test-string) (car (window-text-pixel-size nil (point-min) (point-max)))))) Given that benchmark the `window-text-pixel-size` function is still over 50 times slower. > With 0.5 millisecond per call, I don't see a problem. And I expect > that to go down if the buffer is reused. No, 0.5ms per call is not acceptable. When processing 2000 strings takes a second, it is not viable to use this to preprocess and format many strings. It may be okay for computing a handful strings which are being displayed right away. Given the benchmark I think it makes sense to continue to use `string-width` for certain use cases which can live with the limitations of only working correctly in text mode. But I understand that you don't want to add a half-broken `string-display-width` API on top of the already half-broken `string-width` API. One may still discuss the implementation of a `substring-width` API which generalizes `string-width`. (defun string-width (s) (substring-width s 0 (length s))) (defun substring-width (s a b) (string-width (substring s a b))) From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Daniel Mendler Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Apr 2021 14:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.16182382983483 (code B ref 47712); Mon, 12 Apr 2021 14:39:02 +0000 Received: (at 47712) by debbugs.gnu.org; 12 Apr 2021 14:38:18 +0000 Received: from localhost ([127.0.0.1]:57679 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVxhi-0000u7-7B for submit@debbugs.gnu.org; Mon, 12 Apr 2021 10:38:18 -0400 Received: from server.qxqx.de ([178.63.65.180]:36507 helo=mail.qxqx.de) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVxhf-0000tX-Qj for 47712@debbugs.gnu.org; Mon, 12 Apr 2021 10:38:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=qxqx.de; s=mail1392553390; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=WdQauIDWd4h1Yg7k0Vp0O32goc3uKrIEZunLvP1Vf4M=; b=R+hALW5QH2VTIGArMvcTBrqGk/ jJlV4gAWAhNM6ngAGdng/wgu8oDduoA929+Cjt/WqI3c9/hz3TfYVRFD+jYEuqbmWU99UybnZIEwc /lmvqihcySNQa++kIHrwsSohWNxOwmlObV6sKQP6v5K4egHeD5RWEA3LgevsTG55A7vQ=; References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <83lf9n3d7x.fsf@gnu.org> <1c8f7066-3da2-d960-11e7-a42f567432bd@daniel-mendler.de> <83im4r3agk.fsf@gnu.org> <83czuz39jw.fsf@gnu.org> <83blaj37yi.fsf@gnu.org> <83a6q33753.fsf@gnu.org> From: Daniel Mendler Message-ID: <23ea6bd4-8d2d-51cc-b1f7-58eb7316d5d3@daniel-mendler.de> Date: Mon, 12 Apr 2021 16:38:08 +0200 MIME-Version: 1.0 In-Reply-To: <83a6q33753.fsf@gnu.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) On 4/12/21 4:32 PM, Eli Zaretskii wrote: > My benchmarking indicates that reusing the buffer makes > string-pixel-width only 10 times slower than string-width, i.e. 50 > about microseconds per call. Can you please paste the exact code you used? As I wrote in my previous mail, I tried without buffer switching, but it was still 50 times slower. 10 times slower is still not good, but given that number I may stop arguing, since the factor will be even less in real code. From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Apr 2021 17:03:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Daniel Mendler Cc: 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.161824694517942 (code B ref 47712); Mon, 12 Apr 2021 17:03:02 +0000 Received: (at 47712) by debbugs.gnu.org; 12 Apr 2021 17:02:25 +0000 Received: from localhost ([127.0.0.1]:57933 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVzxB-0004fJ-9Y for submit@debbugs.gnu.org; Mon, 12 Apr 2021 13:02:25 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53592) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVzx9-0004ev-HS for 47712@debbugs.gnu.org; Mon, 12 Apr 2021 13:02:23 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:58671) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lVzwy-0005w6-TK; Mon, 12 Apr 2021 13:02:17 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:4549 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lVzwv-0007JM-Rh; Mon, 12 Apr 2021 13:02:10 -0400 Date: Mon, 12 Apr 2021 20:01:53 +0300 Message-Id: <835z0r308u.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <23ea6bd4-8d2d-51cc-b1f7-58eb7316d5d3@daniel-mendler.de> (message from Daniel Mendler on Mon, 12 Apr 2021 16:38:08 +0200) References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <83lf9n3d7x.fsf@gnu.org> <1c8f7066-3da2-d960-11e7-a42f567432bd@daniel-mendler.de> <83im4r3agk.fsf@gnu.org> <83czuz39jw.fsf@gnu.org> <83blaj37yi.fsf@gnu.org> <83a6q33753.fsf@gnu.org> <23ea6bd4-8d2d-51cc-b1f7-58eb7316d5d3@daniel-mendler.de> X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > Cc: 47712@debbugs.gnu.org > From: Daniel Mendler > Date: Mon, 12 Apr 2021 16:38:08 +0200 > > On 4/12/21 4:32 PM, Eli Zaretskii wrote: > > My benchmarking indicates that reusing the buffer makes > > string-pixel-width only 10 times slower than string-width, i.e. 50 > > about microseconds per call. > > Can you please paste the exact code you used? As I wrote in my previous > mail, I tried without buffer switching, but it was still 50 times > slower. (defun string-pixel-width (string) (with-current-buffer (get-buffer-create "foo") (erase-buffer) (insert string) (window-text-pixel-size nil (point-min) (point-max)))) (defvar test-string (concat "some string with " (propertize "invisible substring" 'invisible t) " and " (propertize "a displayed substring" 'display "an overwritten substring"))) (benchmark-run 100000 (string-pixel-width test-string)) (benchmark-run 100000 (string-width test-string)) > 10 times slower is still not good, but given that number I may > stop arguing, since the factor will be even less in real code. You can still use your code in org-table, if it does the job, I just don't think we should have a semi-working API in core. (There's indeed something strange with the results, I think the with-current-buffer thing is not enough (because if I manually switch to buffer "foo" and run the function, it returns correct results). I will take a closer look when I have time, unless martin beats me to it.) From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Apr 2021 17:10:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Daniel Mendler Cc: 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.161824737418577 (code B ref 47712); Mon, 12 Apr 2021 17:10:02 +0000 Received: (at 47712) by debbugs.gnu.org; 12 Apr 2021 17:09:34 +0000 Received: from localhost ([127.0.0.1]:57938 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lW046-0004pY-2W for submit@debbugs.gnu.org; Mon, 12 Apr 2021 13:09:34 -0400 Received: from eggs.gnu.org ([209.51.188.92]:57034) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lW044-0004pC-9v for 47712@debbugs.gnu.org; Mon, 12 Apr 2021 13:09:32 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:58838) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lW03y-0000Vc-JB; Mon, 12 Apr 2021 13:09:26 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:4992 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lW03x-0000Xv-Tg; Mon, 12 Apr 2021 13:09:26 -0400 Date: Mon, 12 Apr 2021 20:09:08 +0300 Message-Id: <834kgb2zwr.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: (message from Daniel Mendler on Mon, 12 Apr 2021 16:36:05 +0200) References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <83lf9n3d7x.fsf@gnu.org> <1c8f7066-3da2-d960-11e7-a42f567432bd@daniel-mendler.de> <83im4r3agk.fsf@gnu.org> <83czuz39jw.fsf@gnu.org> <83blaj37yi.fsf@gnu.org> X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > Cc: 47712@debbugs.gnu.org > From: Daniel Mendler > Date: Mon, 12 Apr 2021 16:36:05 +0200 > > One may still discuss the implementation of a > `substring-width` API which generalizes `string-width`. > > (defun string-width (s) > (substring-width s 0 (length s))) > > (defun substring-width (s a b) > (string-width (substring s a b))) Why not simply extend string-width to accept 2 optional arguments? From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Daniel Mendler Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Apr 2021 17:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.161824764419007 (code B ref 47712); Mon, 12 Apr 2021 17:15:02 +0000 Received: (at 47712) by debbugs.gnu.org; 12 Apr 2021 17:14:04 +0000 Received: from localhost ([127.0.0.1]:57947 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lW08R-0004wV-Ri for submit@debbugs.gnu.org; Mon, 12 Apr 2021 13:14:04 -0400 Received: from server.qxqx.de ([178.63.65.180]:51401 helo=mail.qxqx.de) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lW08P-0004vt-Uh for 47712@debbugs.gnu.org; Mon, 12 Apr 2021 13:14:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=qxqx.de; s=mail1392553390; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=CSGANyrspr5vA5/q14pO/ovE484KWbQhn2N95v7xxjs=; b=GKXzBjYHybhSjqo+iF88L15zi3 YGvDtiCkyck7B1UHxhRW/QGcPmVJyl100zYQQ9A5vm0udXlHmyBGYcNroG3OGkBr7oqZBm/IAalK9 5G2Z3jQZ7DgPNh7a025ph8uDdpx5L10LQ7xGyhZppTBrav4RMfrrv/d57LDXhv+vsCQU=; References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <83lf9n3d7x.fsf@gnu.org> <1c8f7066-3da2-d960-11e7-a42f567432bd@daniel-mendler.de> <83im4r3agk.fsf@gnu.org> <83czuz39jw.fsf@gnu.org> <83blaj37yi.fsf@gnu.org> <834kgb2zwr.fsf@gnu.org> From: Daniel Mendler Message-ID: <31fdca47-38fa-e70a-cb45-d68d1a90bffb@daniel-mendler.de> Date: Mon, 12 Apr 2021 19:13:53 +0200 MIME-Version: 1.0 In-Reply-To: <834kgb2zwr.fsf@gnu.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) On 4/12/21 7:09 PM, Eli Zaretskii wrote: >> Cc: 47712@debbugs.gnu.org >> From: Daniel Mendler >> Date: Mon, 12 Apr 2021 16:36:05 +0200 >> >> One may still discuss the implementation of a >> `substring-width` API which generalizes `string-width`. >> >> (defun string-width (s) >> (substring-width s 0 (length s))) >> >> (defun substring-width (s a b) >> (string-width (substring s a b))) > > Why not simply extend string-width to accept 2 optional arguments? I agree, that is better. From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Daniel Mendler Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Apr 2021 17:19:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.161824790119448 (code B ref 47712); Mon, 12 Apr 2021 17:19:01 +0000 Received: (at 47712) by debbugs.gnu.org; 12 Apr 2021 17:18:21 +0000 Received: from localhost ([127.0.0.1]:57964 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lW0Cb-00053b-5x for submit@debbugs.gnu.org; Mon, 12 Apr 2021 13:18:21 -0400 Received: from server.qxqx.de ([178.63.65.180]:35349 helo=mail.qxqx.de) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lW0CZ-00053O-Je for 47712@debbugs.gnu.org; Mon, 12 Apr 2021 13:18:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=qxqx.de; s=mail1392553390; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=8NJNa7Sbq7M5e6oov+jOsGuH4r0utoKk4MmYHxGBV/c=; b=dXKJG8BfuMAUVrOrnWpY+dc85L FbMLPBqm7dEq8HFQ19m8c4PDznR5kaLdTc6ZymMSXN5DBNEj8CNJ90IXV38kaKTqdmlvLUoMK0Jsp m3Nmt0siwRnx1RdEzi6vMr22cBxgSJr/wKpZ9gk/zQoxLS07qznR8KDTZqKqSmBdpZpc=; References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <83lf9n3d7x.fsf@gnu.org> <1c8f7066-3da2-d960-11e7-a42f567432bd@daniel-mendler.de> <83im4r3agk.fsf@gnu.org> <83czuz39jw.fsf@gnu.org> <83blaj37yi.fsf@gnu.org> <83a6q33753.fsf@gnu.org> <23ea6bd4-8d2d-51cc-b1f7-58eb7316d5d3@daniel-mendler.de> <835z0r308u.fsf@gnu.org> From: Daniel Mendler Message-ID: <96bf403a-8158-cfe3-b353-68d5f523fc91@daniel-mendler.de> Date: Mon, 12 Apr 2021 19:18:11 +0200 MIME-Version: 1.0 In-Reply-To: <835z0r308u.fsf@gnu.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) On 4/12/21 7:01 PM, Eli Zaretskii wrote: > You can still use your code in org-table, if it does the job, I just > don't think we should have a semi-working API in core. This is a reasonable. Extending `string-width` with two optional begin/end arguments would still be a welcome addition. > (There's indeed something strange with the results, I think the > with-current-buffer thing is not enough (because if I manually switch > to buffer "foo" and run the function, it returns correct results). I > will take a closer look when I have time, unless martin beats me to > it.) Thank you, it would be great if you figure it out. Then the `window-text-pixel-size` becomes a good alternative to computing the string width manually from the display and invisible properties as I am doing as of now. From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: martin rudalics Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 13 Apr 2021 07:07:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii , Daniel Mendler Cc: 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.16182975972436 (code B ref 47712); Tue, 13 Apr 2021 07:07:02 +0000 Received: (at 47712) by debbugs.gnu.org; 13 Apr 2021 07:06:37 +0000 Received: from localhost ([127.0.0.1]:58848 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWD88-0000dE-VR for submit@debbugs.gnu.org; Tue, 13 Apr 2021 03:06:37 -0400 Received: from mout.gmx.net ([212.227.17.20]:36545) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWD87-0000d1-Fg for 47712@debbugs.gnu.org; Tue, 13 Apr 2021 03:06:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1618297570; bh=bE7DuXNgaBXgX0B15JSbwhLHyy2FTAMtifN7GHcCaTw=; h=X-UI-Sender-Class:Subject:To:Cc:References:From:Date:In-Reply-To; b=Q/VA8VT6KsdsWyrXQjqIZdyNaCOutjN9jWFyBmD0kcdTbp9yJaUcSfmDdXqGxPssD DFMx6S1i1ttqsV/OOgaTpXA/MK1r6cNkUybYRE6sKkkTBpCyTl453YPUSYmSB5R5Zy tngg/3VzSwE2ksTo1iaXcsI+urgh1IW8m95h+hIg= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.1.100] ([212.95.5.254]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1M1Ycl-1lYh210EO3-0037tC; Tue, 13 Apr 2021 09:06:10 +0200 References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <83lf9n3d7x.fsf@gnu.org> <1c8f7066-3da2-d960-11e7-a42f567432bd@daniel-mendler.de> <83im4r3agk.fsf@gnu.org> <83czuz39jw.fsf@gnu.org> <83blaj37yi.fsf@gnu.org> <83a6q33753.fsf@gnu.org> <23ea6bd4-8d2d-51cc-b1f7-58eb7316d5d3@daniel-mendler.de> <835z0r308u.fsf@gnu.org> From: martin rudalics Message-ID: Date: Tue, 13 Apr 2021 09:06:06 +0200 MIME-Version: 1.0 In-Reply-To: <835z0r308u.fsf@gnu.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K1:5dd3Zqiw2hdBTPpe1klpTmLVu3FniIjdtYJ6rs1WLvgKYxrbA/0 NAxqqSMrNA8UbgQCq0kUbyacDgfMiKdNQip5aNXmCw0FT69vlLBQGpdWXLTQwMiDI6Jqht8 Hv/8dlUx7iRuk1x96y74RoUeNtMk7Hr9lEVsL1YbChs1wN7rekPYIFThbFFcnOy7btBpkx+ dlkGsfJj+CT9ZMP2Po+bA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:vTzjwQSlgw0=:deb5E36rhJpNy3BSsyBK/2 GU4t5T8qO0Pqui07kgMJYaafwMkDNYhGm8t+Kgrh6UsQaY18Uwy9eeUR8DPdlGaQj66XGrb65 VU+LqB1LSJVBNATdNzYHA/B8aYkx+zKas6XFSgd0VnEYojVYeph0/WBe8Bhnyc+39VgjwC+xH pXNCsuAZLB9y6iGJk756Q2LnDbfUeRU72h2RkXeKeqsXpsruMawO1G+OHlGgVj7aXCN16fnBK WymWtatn7UQX2y75Q2OYxapRNAt3QIf97KUOd2Lekk6+U/saJehIxDJTfgaOjybZMXFAelmsP YVVlePxeur9fm6TlmTkxarLXxf+iBIaqn5vYhsXzDPjTXjrT01hO8wz7CqJVhQaRBKJnoXLma VHxUh5V0Y7ZIRZIpQb4hZ0ORaO11eSsQ87skHYP0WVNSZdBerYk5uFMUeOBQLBEDe+vh2bVAD mZ1O2Qvrwu89FdKfgZaiyAAOPdjdyRam6aZ+42IfjG0ThJDKcawLLpYQ1l+pwtOtKNveco5np XyJiNQBNFIFbsP5MUJxJFcyCCxFw0SeQmELWiV73pXCc4k7ESNpGLjjMLScumL1GR5VB2K04i lQB8aKbqsNfkje2KSPjhm8R7bmliG1sB073C5hchVN9ZgQp4fbL/h/NMK6pb3bERg+m+JwoHi /D8mxiBhu0K0DPKzsaGLaMQ17efx7lT0gOCZRJZlTIhCVELA4+qV/3722kVq0+7SvOJMukR9u dG6B78+uKgiT968RqEwrygBKkPbnSpd9oD2uZfBqJ6WQ/GE74aqtzQBdxYkRnFSA8C56S3aBv iIH7fCKUrCW3g+OAZIx9MJgGBWu+h/BJC2s0OQaY/n9cx6a+o7uEfSFd/89CAhfio+BsWRJ0J AeiUlUuKOfrsFGy63moSdGYqmZm8mCgOBKo+HX2X1KPE5wSIqJg+ZaN4w6ZofyBAtexMxWk7W clnv9a9BiVQExJKXnjZpSt9G7x4rR2bGAgYjDpjZIkoVYDHic8FdhVtDKIcHGA40gBBLLUPpn 7wzPR5Vlj4SLCcVp0FDjDwuDxGQo/a3gQje6RdUsVJSOeA/StpLpGmwz/CucaQMcnrXqLhluw AhWT0mF8x+Ps+DeIl/+U+/2sO63eX6jHwGeiuE1RMIINkoolGoirv/ecZFR8USURJx+2BjZKJ lEvM/I2/efyH6rQOKsJ9nJWnBx4/HisBdDjuQH5FxSoH4nLkhWlJPZGSL85lAzPEzcUik= X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > (defun string-pixel-width (string) > (with-current-buffer (get-buffer-create "foo") > (erase-buffer) > (insert string) > (window-text-pixel-size nil (point-min) (point-max)))) [...] > (There's indeed something strange with the results, I think the > with-current-buffer thing is not enough (because if I manually switch > to buffer "foo" and run the function, it returns correct results). I > will take a closer look when I have time, unless martin beats me to > it.) For `window-text-pixel-size' to work correctly, the buffer in question must be the buffer of the first argument of `window-text-pixel-size' (that's what the display engine expects). OTOH Elisp code doesn't have to care about whether that buffer is current (but it can't harm either). So one way to write `string-pixel-width' should be (defun string-pixel-width (string) (let ((buffer (get-buffer-create "*foo*")) (old-buffer (window-buffer))) (with-current-buffer buffer (erase-buffer) (insert string) (set-window-buffer (selected-window) buffer) (prog1 (window-text-pixel-size nil (point-min) (point-max)) (set-window-buffer (selected-window) old-buffer))))) martin From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 13 Apr 2021 08:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Daniel Mendler Cc: Eli Zaretskii , 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.16183008927561 (code B ref 47712); Tue, 13 Apr 2021 08:02:02 +0000 Received: (at 47712) by debbugs.gnu.org; 13 Apr 2021 08:01:32 +0000 Received: from localhost ([127.0.0.1]:58896 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWDzH-0001xt-OK for submit@debbugs.gnu.org; Tue, 13 Apr 2021 04:01:31 -0400 Received: from quimby.gnus.org ([95.216.78.240]:59350) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWDzE-0001xe-J9 for 47712@debbugs.gnu.org; Tue, 13 Apr 2021 04:01:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=CjDGCpIMsAMnDYi+os/1Hb9x2T4wOvTcDrJO1uV4mfU=; b=MFaL50lCVnMpJseCHBgHRHhtzg JUkpCkbb4LFDPT2ohiQX0mtldJdWmJwmzojWtPbbDyynnK+zcemhBc25bYHPRpMHu7IZMgL3wT54H 9SouQn+ev3EktuUFPWgIWU9bHusS07klRl1rv+QVY+ZsJEx1rvsGv18D419tq6dFdwhI=; Received: from cm-84.212.220.105.getinternet.no ([84.212.220.105] helo=xo) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lWDyy-0000wB-Mh; Tue, 13 Apr 2021 10:01:21 +0200 From: Lars Ingebrigtsen References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <87h7kbzxwh.fsf@gnus.org> <7c96d858-7947-0cca-60fc-1f6d027bb909@daniel-mendler.de> Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAABGdBTUEAALGPC/xhBQAAACBj SFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAD1BMVEXx6Oy8pMpvc6/d aJr///8sYALUAAAAAWJLR0QEj2jZUQAAAAd0SU1FB+UEDQceASu+R0AAAAF1SURBVDjLdZRbgoMw CEXDZAMhbKBkNiCy/70Nj2g1OqkfNofnhbYUP4itrGccpy8M7dg19vF5OAV8RjMH7H0Yud/3mYJX cib/F/C4pxkXEm74AJ3fASPfsoxLVW85mNcWT4fWXstlt28vobIasM8KwngF+8iuEQregI6sycxv APXorRUkFali78xcSPoJNM9W3LbqCZqlqULaSgRX4AwOOeUxAmBR7Jz1Ih8LEIAUsxP4yp5vauln KFANkNpVr9hcfhxsVy2ni61jWri3d+NZPL2DKf9WrR0AVPH0DkoJUyXvE0yKbpXaQ5LZUwGrLQRz RRrsnwOQEJJ1Zfcmh5kAJhAx49hiJRuOvz2A7rmVE2gIRF7Inks5ASXQCUbHK2g1vuR2z3IpZ57g d78AcRAieLxmg/x6FPcQV/rSuQQgDclTRJISQBp8QC+zoM0e3VAQuP/qd60hKUkrBmT5sdeNsJgH r/8C1bbAwXof62Hb2n3acxn+AE6tVO1qmSHXAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDIxLTA0LTEz VDA3OjMwOjAxKzAwOjAwHlQbjAAAACV0RVh0ZGF0ZTptb2RpZnkAMjAyMS0wNC0xM1QwNzozMDow MSswMDowMG8JozAAAAAASUVORK5CYII= X-Now-Playing: Marianne Faithfull's _A Child's Adventure_: "She's Got A Problem" Date: Tue, 13 Apr 2021 10:01:12 +0200 In-Reply-To: <7c96d858-7947-0cca-60fc-1f6d027bb909@daniel-mendler.de> (Daniel Mendler's message of "Mon, 12 Apr 2021 11:08:52 +0200") Message-ID: <87k0p6sjef.fsf@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: Daniel Mendler writes: > Note that I would like to have an implementation of > `substring-width`/`string-display-width`/`substring-display-width` > which does not allocate, since this reduces the GC pressure when > formatti [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Daniel Mendler writes: > Note that I would like to have an implementation of > `substring-width`/`string-display-width`/`substring-display-width` > which does not allocate, since this reduces the GC pressure when > formatting many items. How do you think about this? > > Regarding images, different fonts, maybe a > `string-property-pixel-width` would be useful too. But for the use > cases I have in mind (formatting monospaced text) computing columns is > sufficient. Sure; I think a non-allocating function to count monospaced string width would be useful. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 13 Apr 2021 12:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Lars Ingebrigtsen Cc: mail@daniel-mendler.de, 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.16183152717599 (code B ref 47712); Tue, 13 Apr 2021 12:02:02 +0000 Received: (at 47712) by debbugs.gnu.org; 13 Apr 2021 12:01:11 +0000 Received: from localhost ([127.0.0.1]:59125 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWHjC-0001yV-Vo for submit@debbugs.gnu.org; Tue, 13 Apr 2021 08:01:11 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33840) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWHjA-0001yF-M8 for 47712@debbugs.gnu.org; Tue, 13 Apr 2021 08:01:09 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:47893) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lWHj1-0000hS-DK; Tue, 13 Apr 2021 08:01:02 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:2988 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lWHis-0004MG-9a; Tue, 13 Apr 2021 08:00:52 -0400 Date: Tue, 13 Apr 2021 15:00:35 +0300 Message-Id: <83wnt61jj0.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <87k0p6sjef.fsf@gnus.org> (message from Lars Ingebrigtsen on Tue, 13 Apr 2021 10:01:12 +0200) References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <87h7kbzxwh.fsf@gnus.org> <7c96d858-7947-0cca-60fc-1f6d027bb909@daniel-mendler.de> <87k0p6sjef.fsf@gnus.org> X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > From: Lars Ingebrigtsen > Cc: Eli Zaretskii , 47712@debbugs.gnu.org > Date: Tue, 13 Apr 2021 10:01:12 +0200 > > Daniel Mendler writes: > > > Note that I would like to have an implementation of > > `substring-width`/`string-display-width`/`substring-display-width` > > which does not allocate, since this reduces the GC pressure when > > formatting many items. How do you think about this? > > > > Regarding images, different fonts, maybe a > > `string-property-pixel-width` would be useful too. But for the use > > cases I have in mind (formatting monospaced text) computing columns is > > sufficient. > > Sure; I think a non-allocating function to count monospaced string width > would be useful. I won't mount the barricades over this, but please keep in mind that even with fixed-pitch fonts this will not always produce correct results, because on GUI frames the "double-width" characters not always take exactly two columns (it depends on the font). So this function will only work reliably on text-mode (a.k.a. TTY) frames and for Latin characters on GUI frames. If you still think we should have such a semi-broken function, at least include some warning in its doc string, so that users wouldn't be unpleasantly surprised. From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 13 Apr 2021 12:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: martin rudalics Cc: mail@daniel-mendler.de, 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.16183166239734 (code B ref 47712); Tue, 13 Apr 2021 12:24:02 +0000 Received: (at 47712) by debbugs.gnu.org; 13 Apr 2021 12:23:43 +0000 Received: from localhost ([127.0.0.1]:59144 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWI50-0002Ww-PL for submit@debbugs.gnu.org; Tue, 13 Apr 2021 08:23:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39926) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWI4y-0002Wh-6Y for 47712@debbugs.gnu.org; Tue, 13 Apr 2021 08:23:40 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:48511) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lWI4s-0004lz-FZ; Tue, 13 Apr 2021 08:23:34 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:4397 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lWI4r-00069h-Qy; Tue, 13 Apr 2021 08:23:34 -0400 Date: Tue, 13 Apr 2021 15:23:22 +0300 Message-Id: <83r1je1ih1.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: (message from martin rudalics on Tue, 13 Apr 2021 09:06:06 +0200) References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <83lf9n3d7x.fsf@gnu.org> <1c8f7066-3da2-d960-11e7-a42f567432bd@daniel-mendler.de> <83im4r3agk.fsf@gnu.org> <83czuz39jw.fsf@gnu.org> <83blaj37yi.fsf@gnu.org> <83a6q33753.fsf@gnu.org> <23ea6bd4-8d2d-51cc-b1f7-58eb7316d5d3@daniel-mendler.de> <835z0r308u.fsf@gnu.org> X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > Cc: 47712@debbugs.gnu.org > From: martin rudalics > Date: Tue, 13 Apr 2021 09:06:06 +0200 > > (defun string-pixel-width (string) > (let ((buffer (get-buffer-create "*foo*")) > (old-buffer (window-buffer))) > (with-current-buffer buffer > (erase-buffer) > (insert string) > (set-window-buffer (selected-window) buffer) > (prog1 > (window-text-pixel-size nil (point-min) (point-max)) > (set-window-buffer (selected-window) old-buffer))))) Thanks. This produces correct results, and takes 35-37 usec per call here. From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Daniel Mendler Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 13 Apr 2021 12:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii , Lars Ingebrigtsen Cc: 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.16183167309932 (code B ref 47712); Tue, 13 Apr 2021 12:26:01 +0000 Received: (at 47712) by debbugs.gnu.org; 13 Apr 2021 12:25:30 +0000 Received: from localhost ([127.0.0.1]:59154 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWI6j-0002a8-RH for submit@debbugs.gnu.org; Tue, 13 Apr 2021 08:25:30 -0400 Received: from server.qxqx.de ([178.63.65.180]:48549 helo=mail.qxqx.de) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWI6g-0002Zt-ST for 47712@debbugs.gnu.org; Tue, 13 Apr 2021 08:25:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=qxqx.de; s=mail1392553390; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=e4egiQNdlRuuQgG/T7FPV90pvAtR8EnMasE1MQQfmZ0=; b=Eq0+0ZL6xUH1RETZ4Z+rDxXRTD U8F0+NGS+bo94pF89zOIRkkYYymjT/wJ/x6cp4vz491b5W9wY5Or/q0AvV9As5TznRrJfu3FfXW7n UMovtQkzjXzn2SWfPLAxlxj67o985TEWO4LslBgFafh98AgIpCDRfTIQ9Q6g5myBuerI=; References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <87h7kbzxwh.fsf@gnus.org> <7c96d858-7947-0cca-60fc-1f6d027bb909@daniel-mendler.de> <87k0p6sjef.fsf@gnus.org> <83wnt61jj0.fsf@gnu.org> From: Daniel Mendler Message-ID: Date: Tue, 13 Apr 2021 14:25:18 +0200 MIME-Version: 1.0 In-Reply-To: <83wnt61jj0.fsf@gnu.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) On 4/13/21 2:00 PM, Eli Zaretskii wrote: >> From: Lars Ingebrigtsen >>> Note that I would like to have an implementation of >>> `substring-width`/`string-display-width`/`substring-display-width` >>> which does not allocate, since this reduces the GC pressure when >>> formatting many items. How do you think about this? >> >> Sure; I think a non-allocating function to count monospaced string width >> would be useful. > > I won't mount the barricades over this, but please keep in mind that > even with fixed-pitch fonts this will not always produce correct > results, because on GUI frames the "double-width" characters not > always take exactly two columns (it depends on the font). So this > function will only work reliably on text-mode (a.k.a. TTY) frames and > for Latin characters on GUI frames. > > If you still think we should have such a semi-broken function, at > least include some warning in its doc string, so that users wouldn't > be unpleasantly surprised. Yes, `string-width` is broken for face-dependent purposes. However there are still these handful of use cases which will probably not go away (org-mode table, formatting monospaced text, ...). In those existing cases the `string-width` function is often used in combination with `substring`, i.e., `(string-width (substring str beg end)`. Therefore I would be happy with the following resolution: 1. Add two arguments begin and end to `string-width` to improve the current uses of `string-width`. 2. Document the caveats of `string-width` in the docstring (works only reliable in text mode for multi-width chars) and maybe mention `window-text-pixel-size` or the `string-pixel-width` function by Martin. ---- (defun string-pixel-width (string) (let ((buffer (get-buffer-create " *string-pixel-width*")) (old-buffer (window-buffer))) (unwind-protect (with-current-buffer buffer (erase-buffer) (insert string) (set-window-buffer (selected-window) buffer) (car (window-text-pixel-size nil (point-min) (point-max)))) (set-window-buffer (selected-window) old-buffer)))) (I don't think it is needed to add the `string-pixel-width` function to the core. The function or some variant of it is easy enough for packages to include and it cannot be used in this form since it leads to these temporary buffers lying around.) From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 14 Apr 2021 08:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Daniel Mendler Cc: larsi@gnus.org, 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.161839026125017 (code B ref 47712); Wed, 14 Apr 2021 08:52:01 +0000 Received: (at 47712) by debbugs.gnu.org; 14 Apr 2021 08:51:01 +0000 Received: from localhost ([127.0.0.1]:33350 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWbEj-0006VM-4r for submit@debbugs.gnu.org; Wed, 14 Apr 2021 04:51:01 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46452) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWbEh-0006VA-UA for 47712@debbugs.gnu.org; Wed, 14 Apr 2021 04:51:00 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:38963) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lWbEb-0006c0-ND; Wed, 14 Apr 2021 04:50:53 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:4513 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lWbEW-0001IT-58; Wed, 14 Apr 2021 04:50:52 -0400 Date: Wed, 14 Apr 2021 11:50:36 +0300 Message-Id: <831rbd1c83.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: (message from Daniel Mendler on Tue, 13 Apr 2021 14:25:18 +0200) References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <87h7kbzxwh.fsf@gnus.org> <7c96d858-7947-0cca-60fc-1f6d027bb909@daniel-mendler.de> <87k0p6sjef.fsf@gnus.org> <83wnt61jj0.fsf@gnu.org> X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > Cc: 47712@debbugs.gnu.org > From: Daniel Mendler > Date: Tue, 13 Apr 2021 14:25:18 +0200 > > Yes, `string-width` is broken for face-dependent purposes. However there > are still these handful of use cases which will probably not go away > (org-mode table, formatting monospaced text, ...). In those existing > cases the `string-width` function is often used in combination with > `substring`, i.e., `(string-width (substring str beg end)`. > > Therefore I would be happy with the following resolution: > > 1. Add two arguments begin and end to `string-width` to improve the > current uses of `string-width`. > > 2. Document the caveats of `string-width` in the docstring (works only > reliable in text mode for multi-width chars) and maybe mention > `window-text-pixel-size` or the `string-pixel-width` function by Martin. Your wishes have been granted, see the latest master branch. Is there anything else to do with this bug report, or can we close it? From unknown Thu Jun 19 12:38:41 2025 X-Loop: help-debbugs@gnu.org Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Resent-From: Daniel Mendler Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 14 Apr 2021 10:50:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47712 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: larsi@gnus.org, 47712@debbugs.gnu.org Received: via spool by 47712-submit@debbugs.gnu.org id=B47712.16183973665280 (code B ref 47712); Wed, 14 Apr 2021 10:50:01 +0000 Received: (at 47712) by debbugs.gnu.org; 14 Apr 2021 10:49:26 +0000 Received: from localhost ([127.0.0.1]:33683 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWd5K-0001N6-Mm for submit@debbugs.gnu.org; Wed, 14 Apr 2021 06:49:26 -0400 Received: from server.qxqx.de ([178.63.65.180]:58427 helo=mail.qxqx.de) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWd5I-0001Mr-GM for 47712@debbugs.gnu.org; Wed, 14 Apr 2021 06:49:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=qxqx.de; s=mail1392553390; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=9K0ZHzcZwYbLvjG5zm7N8LnEqam4hvWVZ468UUiIPVM=; b=f1AnBox/lzAq9K4X/FKgz9vQBB SBeemHbBav9+rhmN+X6bE+cboVzSHUVY4+hASQYK6x790Q3tcM4Oc7sndxJj2fjUPDco1HExBFKkG QJdgTIfqmgPh+u69yxprk2eyWlTKYxJjQslJffIxy3h21lmH7e/atf4G1EmsTAa/5Spk=; References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <87h7kbzxwh.fsf@gnus.org> <7c96d858-7947-0cca-60fc-1f6d027bb909@daniel-mendler.de> <87k0p6sjef.fsf@gnus.org> <83wnt61jj0.fsf@gnu.org> <831rbd1c83.fsf@gnu.org> From: Daniel Mendler Message-ID: Date: Wed, 14 Apr 2021 12:49:17 +0200 MIME-Version: 1.0 In-Reply-To: <831rbd1c83.fsf@gnu.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) On 4/14/21 10:50 AM, Eli Zaretskii wrote: > Your wishes have been granted, see the latest master branch. > > Is there anything else to do with this bug report, or can we close it? Thank you for the quick resolution, Eli! Please close this issue. From unknown Thu Jun 19 12:38:41 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Daniel Mendler Subject: bug#47712: closed (Re: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width`) Message-ID: References: <83tuo9yu2y.fsf@gnu.org> <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> X-Gnu-PR-Message: they-closed 47712 X-Gnu-PR-Package: emacs Reply-To: 47712@debbugs.gnu.org Date: Wed, 14 Apr 2021 11:39:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1618400342-18358-1" This is a multi-part message in MIME format... ------------=_1618400342-18358-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #47712: 27.1; Provide `string-display-width` function, which takes properti= es into account, `substring-width` which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 47712@debbugs.gnu.org. --=20 47712: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D47712 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1618400342-18358-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 47712-done) by debbugs.gnu.org; 14 Apr 2021 11:38:48 +0000 Received: from localhost ([127.0.0.1]:33750 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWdr6-0004lf-Fd for submit@debbugs.gnu.org; Wed, 14 Apr 2021 07:38:48 -0400 Received: from eggs.gnu.org ([209.51.188.92]:32956) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lWdr4-0004lR-BK for 47712-done@debbugs.gnu.org; Wed, 14 Apr 2021 07:38:46 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:40660) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lWdqy-00032p-5V; Wed, 14 Apr 2021 07:38:40 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:2945 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lWdqw-00069E-Ar; Wed, 14 Apr 2021 07:38:39 -0400 Date: Wed, 14 Apr 2021 14:38:29 +0300 Message-Id: <83tuo9yu2y.fsf@gnu.org> From: Eli Zaretskii To: Daniel Mendler In-Reply-To: (message from Daniel Mendler on Wed, 14 Apr 2021 12:49:17 +0200) Subject: Re: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` References: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> <83r1jg2q72.fsf@gnu.org> <87h7kbzxwh.fsf@gnus.org> <7c96d858-7947-0cca-60fc-1f6d027bb909@daniel-mendler.de> <87k0p6sjef.fsf@gnus.org> <83wnt61jj0.fsf@gnu.org> <831rbd1c83.fsf@gnu.org> X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 47712-done Cc: larsi@gnus.org, 47712-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) > Cc: larsi@gnus.org, 47712@debbugs.gnu.org > From: Daniel Mendler > Date: Wed, 14 Apr 2021 12:49:17 +0200 > > On 4/14/21 10:50 AM, Eli Zaretskii wrote: > > Your wishes have been granted, see the latest master branch. > > > > Is there anything else to do with this bug report, or can we close it? > > Thank you for the quick resolution, Eli! Please close this issue. Done, thanks. ------------=_1618400342-18358-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 11 Apr 2021 21:16:35 +0000 Received: from localhost ([127.0.0.1]:55948 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVhRb-0001Nd-6V for submit@debbugs.gnu.org; Sun, 11 Apr 2021 17:16:35 -0400 Received: from lists.gnu.org ([209.51.188.17]:36724) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lVhRZ-0001NV-28 for submit@debbugs.gnu.org; Sun, 11 Apr 2021 17:16:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVhRT-0006Vr-Ce for bug-gnu-emacs@gnu.org; Sun, 11 Apr 2021 17:16:32 -0400 Received: from server.qxqx.de ([2a01:4f8:121:346::180]:52291 helo=mail.qxqx.de) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVhRP-0007JX-5Q for bug-gnu-emacs@gnu.org; Sun, 11 Apr 2021 17:16:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=qxqx.de; s=mail1392553390; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Date: Message-ID:Subject:From:To:Sender:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=RCU83ztfaG9K95VfGgkpI6x3M0cQ3yT54yt6RlVZPv0=; b=uculD7Jx+kyPamAaUGOFcmPiXF MfrZ6MyTE94nRmFJcMBkFiDS412qxh1tVN9CJT1r7lLPLnB37PZTkH4ksExhvk2oOU6AgF4LctGpK qULVzDK4kPtWTghhg7DJGZbIMzDO6p9bUYVO/n2kD7O/uF7Wcl5gWDZr2BKW5Z/umvEU=; To: bug-gnu-emacs@gnu.org From: Daniel Mendler Subject: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width` Message-ID: <642c8a37-31c7-2723-12af-06cd7f120c2f@daniel-mendler.de> Date: Sun, 11 Apr 2021 23:16:13 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=2a01:4f8:121:346::180; envelope-from=mail@daniel-mendler.de; helo=mail.qxqx.de X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) Provide a `string-display-width' function, which computes the `string-width', but takes invisible display properties into account. This function is often needed by packages. For example my Consult package (https://github.com/minad/consult) has a crude (non-recursive) version of that function. Then the Embark package has (https://github.com/oantolin/embark) has a similar function. Last but not least, the function already exists in Org under the name `org-string-width'. It is reasonable to implement this function in Elisp. But all the implementations have to use `string-width' for measuring the parts which make up the actual string. Unfortunately this requires allocations for the substrings. A possible solution to this problem is to implement a primitive function `substring-width' and implement `string-width' in terms of that function. (defun consult--display-width (string) "Compute width of STRING taking display and invisible properties into account." (let ((pos 0) (width 0) (end (length string))) (while (< pos end) (let ((nextd (next-single-property-change pos 'display string end)) (display (get-text-property pos 'display string))) (if (stringp display) (setq width (+ width (string-width display)) pos nextd) (while (< pos nextd) (let ((nexti (next-single-property-change pos 'invisible string nextd))) (unless (get-text-property pos 'invisible string) (setq width (+ width (string-width ;; Avoid allocation for the full string. ;; There should be a `substring-width' ;; provided by Emacs. TODO: Propose ;; upstream? Alternatively propose this ;; whole `display-width' function to ;; upstream. (if (and (= pos 0) (= nexti end)) string (substring-no-properties string pos nexti)))))) (setq pos nexti)))))) width)) ------------=_1618400342-18358-1--