Subject: bug#47712: 27.1; Provide `string-display-width` function, which takes properties into account, `substring-width`

From: Daniel Mendler <[email-masked]>
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. 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.