Subject: bug#74817: 31.0.50; mode-line-format-right-align doesn't work well on header-line

From: Ship Mints <[email-masked]>
Date: Sun, 15 Dec 2024 15:25:19 -0500

To emulate the desired behavior, I lifted this from tab-bar's
implementation for a proof-of-concept.

(defun header-line-format-align-right ()
  "Align the rest of `header-line' items to the right."
  (let* ((rest (cdr (member '(:eval (header-line-format-align-right))
header-line-format)))
         (rest (tab-bar-format-list rest)) ; replace tab-bar-format-list
with your own beyond this POC
         (rest (mapconcat (lambda (item) (nth 2 item)) rest ""))
         (hpos (progn
                 (add-face-text-property 0 (length rest) 'header-line t
rest)
                 (string-pixel-width rest)))
         (str (propertize " " 'display
                          ;; The `right' spec doesn't work on TTY frames
                          ;; when windows are split horizontally (bug#59620)
                          (if (window-system)
                              `(space :align-to (- right (,hpos)))
                            `(space :align-to (,(- (frame-inner-width)
hpos)))))))
    `((align-right menu-item ,str ignore))))

(setq header-line-format '("TEST HEADER LINE" (:eval
(header-line-format-align-right)) (lambda () "FOO BAR BAZ")))

One gotcha is that tab-bar-format-list relies on "rest" being a list of
functions, hence the lambda at the end.

Adapt as you see fit.

-Stephane

On Sat, Dec 14, 2024 at 5:56 AM Eli Zaretskii <[email-masked]> wrote:

> tags 74817 notabug wontfix
> thanks
>
> > From: Eval Exec <[email-masked]>
> > Date: Thu, 12 Dec 2024 18:35:07 +0800
> >
> >
> > for example:
> > I create a scratch init.el:
> > ```elisp
> >
> >
> > (defun header0()
> >   "header_line_head")
> > (defun header1()
> >   "header_line_tail")
> >
> > (add-to-list 'header-line-format '(:eval (header0)) t)
> > (add-to-list 'header-line-format mode-line-format-right-align t)
> > (add-to-list 'header-line-format '(:eval (header1)) t)
> > ```
> >
> > Then start emacs, I got: https://imgur.com/a/PHGxRyf
> >
> > You can see, in the right side of header-line, it's wrong, not right
> align well.
>
> This feature doesn't work in header-line, only in mode-line.  It
> specifically looks at mode-line-format.
>
>
>
>