Subject: bug#75500: closed (Re: bug#75500: [PATCH] Fix keybinding alignment in `tmm-menubar')

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 19 Jan 2025 12:55:02 +0000

Your bug report

#75500: [PATCH] Fix keybinding alignment in `tmm-menubar'

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
75500: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=75500
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#75500: [PATCH] Fix keybinding alignment in `tmm-menubar'
From: Eli Zaretskii <[email-masked]>
To: Manuel Giraud <[email-masked]>
Cc: [email-masked]
Date: Sun, 19 Jan 2025 14:54:36 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: Manuel Giraud <[email-masked]>
> Cc: [email-masked]
> Date: Sat, 18 Jan 2025 17:30:29 +0100
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> >>       - emacs -Q
> >>       - M-: (setopt tmm-shortcut-inside-entry t) <RET>
> >>       - M-x eww <RET>
> >>       - gnu.org <RET>
> >>       - M-x tmm-menubar <RET> E
> >
> > OK, I see it now, thanks.
> >
> > Coming back to the patch: please make sure the doc string of the
> > function you are adding is according to our conventions (first line is
> > a single complete sentence), and please explain in the comments _why_
> > this shortening is needed and why exactly 2 spaces.
> 
> Do you meant like this?

Yes, exactly.  Now installed on the master branch, and closing the
bug.

Thanks.

Subject: [PATCH] Fix keybinding alignment in `tmm-menubar'
From: Manuel Giraud <[email-masked]>
To: [email-masked]
Date: Sat, 11 Jan 2025 18:42:54 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Tags: patch

Hi,

In tmm-menubar, for entries prepended by a numerical shortcut, the
associated keybinding ends up being misaligned.  For instance, you can
see that in the eww menu for the entry "List bookmarks".  This patch
fixes this misalignment.

In GNU Emacs 31.0.50 (build 21, x86_64-unknown-openbsd7.6, X toolkit) of
 2025-01-08 built on computer
Repository revision: 631f43d2bbe403e48d63d963281f1d948dee5263
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101015
System Description: OpenBSD computer 7.6 GENERIC.MP#494 amd64

Configured using:
 'configure CC=egcc CPPFLAGS=-I/usr/local/include
 LDFLAGS=-L/usr/local/lib MAKEINFO=gmakeinfo --prefix=/home/manuel/emacs
 --bindir=/home/manuel/bin --with-x-toolkit=lucid
 --with-toolkit-scroll-bars=no --without-cairo
 --without-compress-install'

>From eca3e6a46b71ad016b47e03ddf4c7c8fb6a6748d Mon Sep 17 00:00:00 2001
From: Manuel Giraud <[email-masked]>
Date: Sat, 11 Jan 2025 18:34:49 +0100
Subject: [PATCH] Fix keybinding alignment in `tmm-menubar'

* lisp/tmm.el (tmm--shorten-space-width): New function that
reduces the space between the text menu entry and its
keybinding.
(tmm-add-one-shortcut): Use it.
---
 lisp/tmm.el | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/lisp/tmm.el b/lisp/tmm.el
index c46c477010f..63053f7c13c 100644
--- a/lisp/tmm.el
+++ b/lisp/tmm.el
@@ -282,6 +282,18 @@ tmm-add-shortcuts
   (let ((tmm-next-shortcut-digit ?0))
     (mapcar #'tmm-add-one-shortcut (reverse list))))
 
+(defun tmm--shorten-space-width (str)
+  "Shorten the width between the text of the menu entry and the
+keybinding by 2 spaces."
+  (let* ((start (next-single-property-change 0 'display str))
+         (n (length str))
+         (end (previous-single-property-change n 'display str))
+         (curr-width (and start
+                          (plist-get (get-display-property start 'space str) :width))))
+    (when curr-width
+      (put-text-property start end 'display (cons 'space (list :width (- curr-width 2))) str))
+    str))
+
 (defsubst tmm-add-one-shortcut (elt)
   ;; uses the free vars tmm-next-shortcut-digit and tmm-short-cuts
   (cond
@@ -328,8 +340,9 @@ tmm-add-one-shortcut
                      res)
                  ;; A fallback digit character: place it in front of the
                  ;; menu entry.
-                 (concat (propertize (char-to-string char) 'face 'highlight)
-                         " " str))
+                 (tmm--shorten-space-width
+                  (concat (propertize (char-to-string char) 'face 'highlight)
+                          " " str)))
              (make-string 2 ?\s))
          (concat (if char (concat (char-to-string char) tmm-mid-prompt)
                    ;; Keep them lined up in columns.
-- 
2.47.1

-- 
Manuel Giraud