On Wed, Oct 23, 2024 at 9:01 AM Eli Zaretskii wrote: > I know next to nothing about Corfu, so I have hard time understanding > what you are trying to do and why. Basically, the Emacs display > engine already truncates stuff it displays, so it is completely > unclear to me why you'd need to do that in Lisp. > Corfu is like Company, it's a completion frontend that formats a list of completion candidates to fit inside a confined pop up box. > In particular, "truncate strings in pixel precision" makes no sense to > me, since strings on display are made of characters (more accurately, > "grapheme clusters"), so any reasonable truncation will always work at > the grapheme-cluster granularity, not at pixel granularity. > As described, `truncate-string-to-width` doesn't even truncate at grapheme cluster granularity correctly. A `truncate-string-to-pixel-width` function is needed because propertized strings may consist of display space text properties, images, emojis in a different font, and faces in variable fonts, which all affect glyph widths, you can't simply assume every glyph will take up 1 column. As a result, when you calculate some `end-column` and whether it has reached the width constraint in pixels, one would necessarily need to know the exact width in pixels for each glyph. Converting the width constraint in pixels to columns in order to supply it as the second parameter to a correctly implemented `truncate-string-to-width` amounts to the exact same procedure. Therefore, either a `truncate-string-to-pixel-width` or `glyph-pixel-width` function is needed, because `string-pixel-width` is very expensive.