Subject: bug#43756: Fix for TTY menus mouse interaction

From: Jared Finder <[email-masked]>
Date: Thu, 01 Oct 2020 22:56:34 -0700

Attached is a simple bugfix for tmm.el in Emacs. Currently when the top
level menu is displayed (like when pressing F10), the menu entries are
not in the same order as they are displayed in the menu bar.
Additionally, clicking on any menu entry other than "Help" jumps
straight into the menu clicked on, but clicking on "Help" displays the
root menu. 

Let me know if you need more details to reproduce the issues. In this
case, I think the issues fixed are straightforward. 

  -- MJF

From 836ae1b4e2529cba5af52e270be7dff764abbc9e Mon Sep 17 00:00:00 2001
From: Jared Finder <[email-masked]>
Date: Thu, 17 Sep 2020 22:37:00 -0700
Subject: [PATCH] Fixing small bugs in tmm.el.

* `tmm-menubar-keymap' now properly sorts final items.
* `tmm-menubar' allows clicks on the final menu item.
---
 lisp/tmm.el | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lisp/tmm.el b/lisp/tmm.el
index e9f3f5b038..1e18c8b4ae 100644
--- a/lisp/tmm.el
+++ b/lisp/tmm.el
@@ -57,7 +57,7 @@ tmm-menubar-keymap
                  menu-end
                menu-bar)))
      (tmm-get-keybind [menu-bar]))
-    `(keymap ,@(nreverse menu-bar) ,@(nreverse menu-end))))
+    `(keymap ,@(nreverse menu-bar) ,@menu-end)))
 
 ;;;###autoload (define-key global-map "\M-`" 'tmm-menubar)
 ;;;###autoload (define-key global-map [menu-bar mouse-1] 'tmm-menubar-mouse)
@@ -96,7 +96,10 @@ tmm-menubar
                                          (or (null visible)
                                              (eval visible)))))))
                   (setq column (+ column (length name) 1)))))
-             menu-bar))))
+             menu-bar)
+            ;; Check the last menu item.
+            (when (> column x-position)
+              (setq menu-bar-item prev-key)))))
     (tmm-prompt menu-bar nil menu-bar-item)))
 
 ;;;###autoload
-- 
2.20.1