C-h v menu-bar-final-items
:
menu-bar-final-items
is a variable defined in C source code
.
Its value is (help-menu)
Documentation:
List of menu bar items to move to the end of the menu bar.
The elements of the list are event types that may have menu bar bindings.
Create a "menu" that acts like a button to do what you want, and add that menu after help-menu
in the list value of menu-bar-final-items
.
For example, supposing your command to close the window is close-the-gui-window
:
(define-key global-map [menu-bar close-gui-window]
'(menu-item
"Close Window" close-the-gui-window
:help "Close GUI window"))
(defun close-the-gui-window (&rest _args) ; Just an example.
"Delete selected frame by clicking a menu item bound to this command."
(interactive)
(delete-frame))
(add-to-list 'menu-bar-final-items 'close-gui-window 'append)
I use this approach, for example, in library ToolBar+ (tool-bar+.el
.
Whenever tool-bar-pop-up-mode
is enabled and the tool bar is not shown (tool-bar-mode
is not active) the menu-bar shows a "menu" named Buttons, which has no menu items.
Clicking Buttons pops up the tool bar, and removes Buttons, for the duration of one command (either a tool-bar use or any other action). Then Buttons is shown again.