Subject: 29.0.50; `string-pixel-width' depends on the current window width

From: Brahimi Saifullah <[email-masked]>
Date: Sat, 20 Nov 2021 02:04:14 -0300

emacs -Q
(string-pixel-width "foo")
=> 24
(string-pixel-width "foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo")
=> 744
C-x 3 (or reduce the size of the current window some other way)
(string-pixel-width "foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo")
=> 481
C-x 3
(string-pixel-width "foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo")
=> 225
And so on.  The exact values might vary per system.

The problem is that, when the string's width is larger than the windows' width,
the windows' width is returned, and not the string's.
This can be traced back to `window-text-pixel-size', specifically:

| The optional argument X-LIMIT, if non-nil, specifies the maximum X
| coordinate beyond which the text should be ignored.  It is therefore
| also the maximum width that the function can return.  X-LIMIT nil or
| omitted means to use the pixel-width of WINDOW’s body.  This default
| means text of truncated lines wider than the window will be ignored;
| specify a large value for X-LIMIT if lines are truncated and you need
| to account for the truncated text.  Use nil for X-LIMIT if you want to
| know how high WINDOW should become in order to fit all of its buffer’s
| text with the width of WINDOW unaltered.  Use the maximum width WINDOW
| may assume if you intend to change WINDOW’s width.  Since calculating
| the width of long lines can take some time, it’s always a good idea to
| make this argument as small as possible; in particular, if the buffer
| contains long lines that shall be truncated anyway.

In `string-pixel-width', X-LIMIT is nil.

I think the best solution is to modify `window-text-pixel-size' so that
X-LIMIT may be specified as having "no limit".  Y-LIMIT already offers
this possibility: when it is nil, the entirety of the buffer is considered
(in reality, it seems to be simply set to INT_MAX, and that does the job).

--------------------------------------------------------------------------------

I'm experience some different problems with this function, and I'm pretty sure
it don't stem from this same issue, but from WINDOW being buffer.
Should I open a new bug report? Or expand upon the issue on this same thread?

In GNU Emacs 29.0.50 (build 1, x86_64-w64-mingw32)
 of 2021-11-19 built on COMPUTADOR
Repository revision: 956f21b6b916f8d87a7b872e02f668883c17b8ba
Repository branch: master
Windowing system distributor 'Microsoft Corp.', version 10.0.19041
System Description: Microsoft Windows 10 Enterprise (v10.0.2004.19041.1348)

Configured using:
 'configure --with-native-compilation --with-json --with-imagemagick
 --without-pop'

Configured features:
ACL DBUS GIF GMP GNUTLS HARFBUZZ IMAGEMAGICK JPEG JSON LCMS2 LIBXML2
MODULES NATIVE_COMP NOTIFY W32NOTIFY PDUMPER PNG RSVG SOUND THREADS TIFF
TOOLKIT_SCROLL_BARS WEBP XPM ZLIB

Important settings:
  value of $LC_CTYPE: pt_BR.UTF-8
  value of $LANG: PTB
  locale-coding-system: cp1252

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media rmc puny
dired dired-loaddefs rfc822 mml mml-sec epa derived epg rfc6068
epg-config gnus-util rmail rmail-loaddefs auth-source cl-seq eieio
eieio-core cl-macs eieio-loaddefs password-cache json map
text-property-search seq byte-opt bytecomp byte-compile cconv mm-decode
mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader
sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils gv
time-date subr-x help-mode cl-loaddefs cl-lib iso-transl tooltip eldoc
paren electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode
mwheel dos-w32 ls-lisp disp-table term/w32-win w32-win w32-vars
term/common-win tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer cl-generic cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932
hebrew greek romanian slovak czech european ethiopic indian cyrillic
chinese composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice button
loaddefs faces cus-face macroexp files window text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads w32notify dbusbind w32 lcms2
multi-tty make-network-process native-compile emacs)

Memory information:
((conses 16 72646 4855)
 (symbols 48 6899 0)
 (strings 32 21630 1558)
 (string-bytes 1 703288)
 (vectors 16 14099)
 (vector-slots 8 298463 13452)
 (floats 8 26 261)
 (intervals 56 234 3)
 (buffers 992 10))