Subject: bug#73734: [PATCH] Fix tmm menu layout

From: Eli Zaretskii <[email-masked]>
Date: Fri, 11 Oct 2024 12:26:12 +0300

> From: Manuel Giraud <[email-masked]>
> Cc: [email-masked],  [email-masked]
> Date: Fri, 11 Oct 2024 10:10:25 +0200
> 
> With the following patch:
> 
> diff --git a/lisp/tmm.el b/lisp/tmm.el
> index 1e3942761a1..8d1f9b15e82 100644
> --- a/lisp/tmm.el
> +++ b/lisp/tmm.el
> @@ -484,13 +484,12 @@ tmm-get-keymap
>              (when binding
>                (setq binding (key-description binding))
>                ;; Try to align the keybindings.
> -              (let ((colwidth (- (/ (frame-width) 3) 15)))
> +              (let* ((colwidth (min 30 (- (/ (window-width) 2) 10)))
> +                     (spaces (max 2 (- colwidth (string-width str)
> +                                       (string-width binding)))))
>                  (setq str
>                        (concat str
> -                              (make-string (max 2 (- colwidth
> -                                                     (string-width str)
> -                                                     (string-width binding)))
> -                                           ?\s)
> +                              (propertize " " 'display `(space . (:width ,spaces)))
>                                binding)))))))
>        (and km (stringp km) (setq str km))
>        ;; Verify that the command is enabled;
> 
> The result is even worse because now there is wrapping involved:

This is not what I suggested.  I suggested to leave the spaces in the
string intact and just put on each of them a display property whose
value is '(space . (:width 1)).  This cannot possibly cause wrapping,
unless the original string already does, because we don't change how
many SPC characters are used, we just force each one of them to take
exactly one canonical column.

Now, I don't know what is wrong with the code you used that it caused
wrapping, but your code is more complex because it attempts to
calculate the number of spaces required to show the menu, whereas the
method I suggested doesn't.