emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-25 ce0d8c7: Make tmm-menubar work in correct order a


From: Eli Zaretskii
Subject: [Emacs-diffs] emacs-25 ce0d8c7: Make tmm-menubar work in correct order again
Date: Tue, 19 Apr 2016 15:07:36 +0000

branch: emacs-25
commit ce0d8c7f2d8187942a8b45c3a71c22c5f30fa37d
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Make tmm-menubar work in correct order again
    
    * lisp/tmm.el (tmm-prompt): Don't reverse 'tmm-km-list' right at the
    beginning; instead, pass a reversed copy to 'tmm--completion-table'.
    (Bug#23309)
    (tmm-menubar): Fix an off-by-one error in determining the menu
    item when the function is called with a non-nil 'x-position'
    argument.
---
 lisp/tmm.el |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/lisp/tmm.el b/lisp/tmm.el
index 714de92..d1a08ab 100644
--- a/lisp/tmm.el
+++ b/lisp/tmm.el
@@ -72,13 +72,15 @@ to invoke `tmm-menubar' instead, customize the variable
      (tmm-get-keybind [menu-bar]))
     (setq menu-bar `(keymap ,@(nreverse menu-bar) ,@(nreverse menu-end)))
     (if x-position
-       (let ((column 0))
+       (let ((column 0)
+              prev-key)
           (catch 'done
             (map-keymap
              (lambda (key binding)
                (when (> column x-position)
-                 (setq menu-bar-item key)
+                 (setq menu-bar-item prev-key)
                  (throw 'done nil))
+               (setq prev-key key)
                (pcase binding
                  ((or `(,(and (pred stringp) name) . ,_) ;Simple menu item.
                       `(menu-item ,name ,_cmd            ;Extended menu item.
@@ -187,7 +189,6 @@ Its value should be an event that has a binding in MENU."
          ((vectorp elt)
           (dotimes (i (length elt))
             (tmm-get-keymap (cons i (aref elt i)) not-menu))))))
-    (setq tmm-km-list (nreverse tmm-km-list))
     ;; Choose an element of tmm-km-list; put it in choice.
     (if (and not-menu (= 1 (length tmm-km-list)))
        ;; If this is the top-level of an x-popup-menu menu,
@@ -239,10 +240,17 @@ Its value should be an event that has a binding in MENU."
                    (if default-item
                        (car (nth index-of-default tmm-km-list))
                      (minibuffer-with-setup-hook #'tmm-add-prompt
+                       ;; tmm-km-list is reversed, because history
+                       ;; needs it in LIFO order.  But completion
+                       ;; needs it in non-reverse order, so that the
+                       ;; menu items are displayed as completion
+                       ;; candidates in the order they are shown on
+                       ;; the menu bar.  So pass completing-read the
+                       ;; reversed copy of the list.
                        (completing-read
                         (concat gl-str
                                 " (up/down to change, PgUp to menu): ")
-                        (tmm--completion-table tmm-km-list) nil t nil
+                        (tmm--completion-table (reverse tmm-km-list)) nil t nil
                         (cons 'tmm--history
                               (- (* 2 history-len) index-of-default))))))))
       (setq choice (cdr (assoc out tmm-km-list)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]