I hide the window title bar, so I can't use the close window button in the top right corner.

I want to add a menu item with no drop-down menu on the far right side of menu-bar, which can only be clicked as close window button.

A more detailed explanation of the problem added after Drew’s answer:

Close button should be close to the right edge of the window, There should be a space separator in the middle to isolate the close button from other menu items.


1 Answer 1


C-h v menu-bar-final-items:

menu-bar-final-items is a variable defined in C source code.

Its value is (help-menu)


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]
    "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."

(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.

  • Hi Drew, if it was that simple I would not have upvoted the question. At least it does not work with emacs-26.2 under WSL Ubuntu-linux. Meanwhile I think integrating command calling menu items into the menu-bar is not possible. The menu-bar only takes keymaps for other menus and the `#'undefined' function for hiding menu items from global-map. Please prove me wrong;-). (I did even dig into the C-sources to look what is going on but currently I do not have the time for a thorough analysis.)
    – Tobias
    Sep 24, 2019 at 14:41
  • @Drew, I want the close button to be in the top right corner of the screen (I also hide the gnome panel), which is the easiest position for the mouse to move to.
    – dongli si
    Sep 24, 2019 at 15:12
  • @Drew I added a definition for close-guid-window to make the example self-contained.
    – Tobias
    Sep 24, 2019 at 15:33
  • @donglisi I added a definition for close-guid-window. You can copy-paste the code now into your *scratch* buffer. It would be very nice if you could test whether the frame is deleted when you click on "Close Window" in the menu bar. It would be very interesting if that works for you.
    – Tobias
    Sep 24, 2019 at 15:40
  • @tobias: Yes, it should work fine. You used the wrong command name (missing -the). The menu item name need not be the same as the command name.
    – Drew
    Sep 24, 2019 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.