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

From: Daniel Mendler <[email-masked]>
Date: Wed, 09 Jul 2025 09:14:59 +0200

Juri Linkov <[email-masked]> writes:

> close 78953 31.0.50
> thanks
>
>>>> 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.
>
> Now `tab-bar-format-list' and `tab-bar-format-align-right' are fixed
> to not call `tab-bar-format-global' twice.
>
>> Also another problem I've observed is that `string-pixel-width' is slow,
>> which is a problem with frequent updates/redisplays, for example when
>> scrolling a lot with `pixel-scroll-precision-mode'.
>>
>> I suggest to update `:align-to' in `tab-bar-format-list' and also cache
>> the computed width and the formatted tab bar string. Then the cached
>> string can be compared with `equal-including-properties` and only if the
>> string changes, the pixel width needs to be recomputed.
>
> Now the formatted tab bar string is cached as well.

Thanks. I think the code should be simplified - in fact it is
problematic like this since it will leak memory, if the string changes,
for example for a timer which counts up, where the same string will only
needed for a short while. A hash table is not needed to memoize a single
pair. It suffices to only store the current string to optimize
redisplay. You could store the string in the car of a cons, and the
width in the cdr.

Daniel