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

From: Juri Linkov <[email-masked]>
Date: Sun, 01 May 2022 21:21:14 +0300

> I am completely unfamiliar with how the tar bar works, but -- can't you
> just measure the widths of the elements with string-pixel-width or the
> like and use that to compute the alignments?

Thanks for the suggestion.  This works quite nicely.
Only a very small amount of pixels are still misaligned.

diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 03b49e9657..7896e051ab 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 rest))
+         (str (propertize " " 'display `(space :align-to (- right (,hpos))))))
     `((align-right menu-item ,str ignore))))