GNU bug report logs - #55207
29.0.50; tab-bar-format-align-right only works correctly with monospace characters

Previous Next

Package: emacs;

Reported by: Daniel Semyonov <daniel <at> dsemy.com>

Date: Sun, 1 May 2022 15:51:02 UTC

Severity: normal

Found in version 29.0.50

Done: Daniel Semyonov <daniel <at> dsemy.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 55207 in the body.
You can then email your comments to 55207 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#55207; Package emacs. (Sun, 01 May 2022 15:51:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Daniel Semyonov <daniel <at> dsemy.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 01 May 2022 15:51:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Daniel Semyonov <daniel <at> dsemy.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.50; tab-bar-format-align-right only works correctly with
 monospace characters
Date: Sun, 01 May 2022 18:50:18 +0300
When a character using a variable pitch font or an image (I've only
tested this with XBM images) is displayed on the tab bar after
'tab-bar-format-align-right', the resulting text ends before the end of
the tab bar.

Exact recipe (assuming the default font for the tab bar is variable pitch):

1. $ emacs -Q
2. M-: (setq tab-bar-format '(tab-bar-format-align-right tab-bar-format-tabs tab-bar-separator))
3. M-x tab-bar-mode

After following these steps, the initial tab ends before the end
of the tab bar, and the gap grows with each additional tab.


In GNU Emacs 29.0.50 (build 10, x86_64-pc-linux-gnu, GTK+ Version 3.24.33, cairo version 1.16.0)
 of 2022-05-01 built on coldharbour
Repository revision: 5f220d9555a908dd9957afa27d168d74adf6c7df
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101003
System Description: Debian GNU/Linux bookworm/sid

Configured using:
 'configure --with-x-toolkit=gtk3 --with-xinput2
 --with-native-compilation --with-xwidgets --prefix=/opt/Emacs'

Configured features:
CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON
LCMS2 LIBSELINUX LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG
RSVG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS WEBP X11
XDBE XIM XINPUT2 XPM XWIDGETS GTK3 ZLIB

Important settings:
  value of $LC_CTYPE: en_US.UTF-8
  value of $LANG: en_IL
  locale-coding-system: utf-8-unix

Major mode: Fundamental

Minor modes in effect:
  emms-mode-line-mode: t
  emms-playing-time-display-mode: t
  emms-playing-time-mode: t
  electric-pair-mode: t
  delete-selection-mode: t
  pixel-scroll-precision-mode: t
  repeat-mode: t
  vcomplete-mode: t
  swsw-mode: t
  global-auto-revert-mode: t
  display-time-mode: t
  minibuffer-electric-default-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tab-bar-mode: t
  file-name-shadow-mode: t
  context-menu-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
/home/daniel/etc/emacs/elpa/transient-0.3.7/transient hides /opt/Emacs/share/emacs/29.0.50/lisp/transient

Features:
(shadow emacsbug vc vc-git diff-mode vc-dispatcher dired-aux sort smiley
gnus-cite mail-extr textsec uni-scripts idna-mapping ucs-normalize
uni-confusable textsec-check gnus-bcklg gnus-async gnus-dup gnus-ml
disp-table nnml gnus-topic nndraft nnmh timezone mm-archive url-http
url-gw url-cache url-auth utf-7 nnrss mm-url epa-file cl-extra
network-stream nsm gnus-agent gnus-srvr gnus-score score-mode nnvirtual
gnus-msg gnus-art mm-uu mml2015 mm-view mml-smime smime gnutls dig
gnus-cache gnus-sum shr pixel-fill kinsoku url-file url-dired svg dom
init-gnus gnus-demon nntp gnus-group gnus-undo easy-mmode cus-start
gnus-start gnus-dbus gnus-cloud nnimap nnmail mail-source utf7 netrc
nnoo parse-time iso8601 gnus-spec gnus-int gnus-range message sendmail
yank-media rmc puny rfc822 mml mml-sec epa derived epg rfc6068
epg-config mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047
rfc2045 ietf-drums mailabbrev gmm-utils mailheader gnus-win gnus
nnheader gnus-util mail-utils range mm-util mail-prsvr time-date
checkdoc lisp-mnt help-mode flymake-proc flymake project compile
text-property-search comint ansi-color warnings thingatpt flyspell
ispell display-line-numbers modus-operandi-theme cal-julian modus-themes
solar cal-dst cal-menu calendar cal-loaddefs init-interfaces init-web
init-volume init-emms emms-mode-line emms-player-mpv emms-playing-time
emms-player-simple emms-info-opusinfo emms-info emms-later-do emms
emms-compat init-battery battery dbus xml init-programs dired
dired-loaddefs init-shell init-pass auth-source-pass init-programming
elec-pair init-ui delsel pixel-scroll cua-base ring format-spec repeat
vcomplete swsw autorevert filenotify time minibuf-eldef init-personal
pcase init-base server finder-inf package browse-url url url-proxy
url-privacy url-expand url-methods url-history url-cookie url-domsuf
url-util mailcap url-handlers url-parse auth-source cl-seq eieio
eieio-core cl-macs eieio-loaddefs password-cache json map url-vars seq
gv subr-x byte-opt bytecomp byte-compile cconv info cus-edit pp cus-load
wid-edit cl-loaddefs cl-lib iso-transl tooltip eldoc paren electric
uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel
term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice simple cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite emoji-zwj charscript charprop
case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs faces cus-face macroexp files window
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget keymap hashtable-print-readable backquote threads
xwidget-internal dbusbind inotify lcms2 dynamic-setting
system-font-setting font-render-setting cairo move-toolbar gtk x-toolkit
xinput2 x multi-tty make-network-process native-compile emacs)

Memory information:
((conses 16 542700 52961)
 (symbols 48 24357 0)
 (strings 32 93082 3762)
 (string-bytes 1 2788588)
 (vectors 16 58794)
 (vector-slots 8 1024008 47173)
 (floats 8 684 500)
 (intervals 56 610 223)
 (buffers 992 26))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55207; Package emacs. (Sun, 01 May 2022 17:57:01 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Daniel Semyonov via "Bug reports for GNU Emacs, the Swiss army knife of
 text editors" <bug-gnu-emacs <at> gnu.org>
Cc: 55207 <at> debbugs.gnu.org, Daniel Semyonov <daniel <at> dsemy.com>
Subject: Re: bug#55207: 29.0.50; tab-bar-format-align-right only works
 correctly with monospace characters
Date: Sun, 01 May 2022 20:55:43 +0300
> When a character using a variable pitch font or an image (I've only
> tested this with XBM images) is displayed on the tab bar after
> 'tab-bar-format-align-right', the resulting text ends before the end of
> the tab bar.
>
> Exact recipe (assuming the default font for the tab bar is variable pitch):
>
> 1. $ emacs -Q
> 2. M-: (setq tab-bar-format '(tab-bar-format-align-right tab-bar-format-tabs tab-bar-separator))
> 3. M-x tab-bar-mode
>
> After following these steps, the initial tab ends before the end
> of the tab bar, and the gap grows with each additional tab.

Thanks for the bug report.  Indeed the property :align-to
in tab-bar-format-align-right fails to align to the proper width
when using a variable pitch font.  Unfortunately, I have no idea
how to fix this.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55207; Package emacs. (Sun, 01 May 2022 17:57:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55207; Package emacs. (Sun, 01 May 2022 18:03:01 GMT) Full text and rfc822 format available.

Message #14 received at 55207 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Juri Linkov <juri <at> linkov.net>
Cc: 55207 <at> debbugs.gnu.org, daniel <at> dsemy.com
Subject: Re: bug#55207: 29.0.50; tab-bar-format-align-right only works
 correctly with monospace characters
Date: Sun, 01 May 2022 20:01:59 +0200
Juri Linkov <juri <at> linkov.net> writes:

> Thanks for the bug report.  Indeed the property :align-to
> in tab-bar-format-align-right fails to align to the proper width
> when using a variable pitch font.  Unfortunately, I have no idea
> how to fix this.

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?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55207; Package emacs. (Sun, 01 May 2022 18:23:02 GMT) Full text and rfc822 format available.

Message #17 received at 55207 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 55207 <at> debbugs.gnu.org, daniel <at> dsemy.com
Subject: Re: bug#55207: 29.0.50; tab-bar-format-align-right only works
 correctly with monospace characters
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))))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55207; Package emacs. (Mon, 02 May 2022 15:26:02 GMT) Full text and rfc822 format available.

Message #20 received at 55207 <at> debbugs.gnu.org (full text, mbox):

From: Daniel Semyonov <daniel <at> dsemy.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 55207 <at> debbugs.gnu.org
Subject: Re: bug#55207: 29.0.50; tab-bar-format-align-right only works
 correctly with monospace characters
Date: Mon, 02 May 2022 18:25:48 +0300
[Message part 1 (text/plain, inline)]
>>>>> Juri Linkov writes:

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

Hi Juri and Lars,

This patch seems to almost completely remove the issue in the simple
case I reported.

However, in the more complicated configuration I actually use it doesn't
make much of a difference:

Before
[before.png (image/png, inline)]
[Message part 3 (text/plain, inline)]
After
[after.png (image/png, inline)]
[Message part 5 (text/plain, inline)]
(Both screen shots extend to the right end of the tab bar)

The icons on the mode line are small XBM images, the theme is Modus
Operandi.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55207; Package emacs. (Mon, 02 May 2022 19:24:02 GMT) Full text and rfc822 format available.

Message #23 received at 55207 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Daniel Semyonov <daniel <at> dsemy.com>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 55207 <at> debbugs.gnu.org
Subject: Re: bug#55207: 29.0.50; tab-bar-format-align-right only works
 correctly with monospace characters
Date: Mon, 02 May 2022 22:06:24 +0300
> However, in the more complicated configuration I actually use it doesn't
> make much of a difference:
> ...
> The icons on the mode line are small XBM images, the theme is Modus
> Operandi.

I guess you are using global-mode-string with XBM images.
Could you then try something like this to see what number it returns?

(string-pixel-width (string-trim-right (format-mode-line global-mode-string)))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55207; Package emacs. (Tue, 03 May 2022 07:41:02 GMT) Full text and rfc822 format available.

Message #26 received at 55207 <at> debbugs.gnu.org (full text, mbox):

From: Daniel Semyonov <daniel <at> dsemy.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 55207 <at> debbugs.gnu.org
Subject: Re: bug#55207: 29.0.50; tab-bar-format-align-right only works
 correctly with monospace characters
Date: Tue, 03 May 2022 10:40:35 +0300
[Message part 1 (text/plain, inline)]
>>>>> Juri Linkov writes:

    > I guess you are using global-mode-string with XBM images.

I should've added this to the last message, but this is my tab bar
configuration (just a little bit over engineered):

(init-base-customize display-time-format "%H:%M %d/%m/%y"
                     display-time-mail-function #'ignore)
(display-time-mode)

(setq global-mode-string
      '(:eval
        `(""
          ,(and (boundp 'init-gnus-unread-mail-string)
                init-gnus-unread-mail-string)
          ,(and (boundp 'init-gnus-unread-news-string)
                init-gnus-unread-news-string)
          ,(and (boundp 'init-volume-string)
                init-volume-string)
          ,(and (boundp 'emms-mode-line-string)
                emms-mode-line-string)
          ,(and (boundp 'emms-playing-time-string)
                emms-playing-time-string)
          " | " ,(string-trim-right display-time-string))))
(init-base-customize tab-bar-format
                     '( tab-bar-format-tabs tab-bar-format-align-right
                        tab-bar-format-global))
(tab-bar-mode)


('init-base-customize' is just a convenience macro which calls
'customize-set-variable' under the hood and the value of 'init-*-string' is
a string of the form "x: y " where 'x' is a letter and 'y' is a number or
percentage; 'x:' is replaced with an XBM image using the 'display'
property on GUI frames).

    > Could you then try something like this to see what number it
    > returns?

I did some further testing, first adding arbitrary text to the
'global-mode-string', then adding more images and finally adding both.
I've attached screen shots of my full Emacs frame with an example of
each test case, taken right after evaluating your provided expression
(so the number is shown in the echo area).  The buffer shown in the
images shows the exact changes I made to the 'global-mode-string' in
each test.

I've also attached the envelope and volume icons seen in the screen
shots, just in case they may be useful.

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

[control.png (image/png, attachment)]
[added_text.png (image/png, attachment)]
[added_image.png (image/png, attachment)]
[added_image_and_text.png (image/png, attachment)]
[volume-75.xbm (image/x-xbitmap, attachment)]
[mail.xbm (image/x-xbitmap, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#55207; Package emacs. (Tue, 03 May 2022 18:01:02 GMT) Full text and rfc822 format available.

Message #29 received at 55207 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Daniel Semyonov <daniel <at> dsemy.com>
Cc: Lars Ingebrigtsen <larsi <at> gnus.org>, 55207 <at> debbugs.gnu.org
Subject: Re: bug#55207: 29.0.50; tab-bar-format-align-right only works
 correctly with monospace characters
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))))




Reply sent to Daniel Semyonov <daniel <at> dsemy.com>:
You have taken responsibility. (Wed, 04 May 2022 11:01:01 GMT) Full text and rfc822 format available.

Notification sent to Daniel Semyonov <daniel <at> dsemy.com>:
bug acknowledged by developer. (Wed, 04 May 2022 11:01:01 GMT) Full text and rfc822 format available.

Message #34 received at 55207-done <at> debbugs.gnu.org (full text, mbox):

From: Daniel Semyonov <daniel <at> dsemy.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 55207-done <at> debbugs.gnu.org
Subject: Re: bug#55207: 29.0.50; tab-bar-format-align-right only works
 correctly with monospace characters
Date: Wed, 04 May 2022 14:00:40 +0300
>>>>> Juri Linkov writes:

    > Could you please try a new patch.  At least, I see that it works
    > with your test cases.

The new patch seems to completely fix the issue, thanks!




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 01 Jun 2022 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 301 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.