Subject: Re: bug#55207: 29.0.50; tab-bar-format-align-right only works correctly with monospace characters

From: Juri Linkov <[email-masked]>
Date: Tue, 03 May 2022 20:52:17 +0300

> Hopefully this information proves useful, thank you for looking into
> this.

Thanks, this helped to realize that the pixel width should be calculated
with the same face that is really used on the tab bar.  Could you please
try a new patch.  At least, I see that it works with your test cases.

diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 03b49e9657..4d5ec4098c 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -915,8 +915,8 @@ tab-bar-format-align-right
   (let* ((rest (cdr (memq 'tab-bar-format-align-right tab-bar-format)))
          (rest (tab-bar-format-list rest))
          (rest (mapconcat (lambda (item) (nth 2 item)) rest ""))
-         (hpos (length rest))
-         (str (propertize " " 'display `(space :align-to (- right ,hpos)))))
+         (hpos (string-pixel-width (propertize rest 'face 'tab-bar)))
+         (str (propertize " " 'display `(space :align-to (- right (,hpos))))))
     `((align-right menu-item ,str ignore))))