Subject: bug#62606: [PATCH] function to align mode-line elements to right

From: Juri Linkov <[email-masked]>
Date: Fri, 14 Jul 2023 19:37:10 +0300

>> Hope that's all good.
>
> Thanks, installed on the master branch, and closing the bug.

I customized the mode-line to use variable-pitch fonts with

  (set-face-attribute 'mode-line nil :inherit '(variable-pitch))

that produces wrong right-alignment.  This problem was already fixed
in `tab-bar-format-align-right' by using `add-face-text-property'.
This patch does the same for the mode-line:

diff --git a/lisp/bindings.el b/lisp/bindings.el
index f1a75b080be..047492e82d4 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -338,7 +338,10 @@ mode--line-format-right-align
   (let* ((rest (cdr (memq 'mode-line-format-right-align
 			  mode-line-format)))
 	 (rest-str (format-mode-line `("" ,@rest)))
-	 (rest-width (string-pixel-width rest-str)))
+	 (rest-width (progn
+                       (add-face-text-property
+                        0 (length rest-str) 'mode-line t rest-str)
+                       (string-pixel-width rest-str))))
     (propertize " " 'display
 		;; The `right' spec doesn't work on TTY frames
 		;; when windows are split horizontally (bug#59620)