Subject: Re: bug#50067: Context menus

From: Juri Linkov <[email-masked]>
Date: Thu, 18 Nov 2021 20:38:53 +0200

>> Currently the option context-menu-global of context-menu-functions
>> doesn't take into account the variable menu-bar-final-items
>> to properly order the menu items.  This patch makes it possible
>> to order the items of global-map instead of menu-bar-current-active-maps
>> used in menu-bar-keymap by default:
>
> Actually, here is a better patch that will also allow sorting items on
> context-menu-local as well.  The same KEYMAP arg of menu-bar-keymap
> could be used also in mouse-menu-bar-map to sort items of [C-down-mouse-3]
> in the right order (they were unsorted for a long time):

Only part of the patch that fixes the new feature was pushed to emacs-28.
But the following part that fixes the old function could pushed to master later:

> diff --git a/lisp/mouse.el b/lisp/mouse.el
> index d6912892ef..5b9ae121d7 100644
> --- a/lisp/mouse.el
> +++ b/lisp/mouse.el
> @@ -271,10 +271,10 @@ mouse-menu-bar-map
>      ;; FIXME: We have a problem here: we have to use the global/local/minor
>      ;; so they're displayed in the expected order, but later on in the command
>      ;; loop, they're actually looked up in the opposite order.
> -    (apply 'append
> -           global-menu
> -           local-menu
> -           minor-mode-menus)))
> +    (menu-bar-keymap (apply 'append
> +                            global-menu
> +                            local-menu
> +                            minor-mode-menus))))