Subject: 31.0.50; tab-bar-format-align-right alignment breaks if field widths change

From: Daniel Mendler <[email-masked]>
Date: Fri, 04 Jul 2025 08:39:24 +0200

When fields in `tab-bar-format' after `tab-bar-format-align-right'
change their width between two calls, then the alignment breaks - the
right aligned tab field jumps around. Example configuration which uses a
`global-mode-string' with a random width:

(setq tab-bar-format
  '( tab-bar-format-tabs
     tab-bar-format-align-right
     tab-bar-format-global))

(setq global-mode-string
      '("|" (:eval (make-string (random 10) ?#)) "|"))

(run-at-time 1 1 #'force-mode-line-update t)

A more realistic configuration with a timer (and a variable pitch face)
also shows the problem. A possible solution could be to handle
`tab-bar-format-align-right' in `tab-bar-format-list', such that the
functions in the `tab-bar-format' list after
`tab-bar-format-align-right' are not called twice, such that the
computed field width matches the displayed field.

In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.49, cairo version 1.18.4) of 2025-06-20
Windowing system distributor 'The X.Org Foundation', version 11.0.12101016
System Description: Debian GNU/Linux 13 (trixie)

Configured using:
 'configure --prefix=$HOME/.local/share/emacs
 --without-compress-install --with-tree-sitter --with-native-compilation
 --with-dbus --without-selinux --without-threads --disable-gc-mark-trace
 --without-gsettings --without-gpm --with-cairo --with-cairo-xcb
 --with-xinput2 --with-x-toolkit=gtk3 --without-toolkit-scroll-bars'

Configured features:
CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS HARFBUZZ JPEG LIBOTF LIBSYSTEMD
LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP
SOUND SQLITE3 TIFF TREE_SITTER WEBP X11 XDBE XIM XINERAMA XINPUT2 XPM
XRANDR GTK3 ZLIB