Search code examples
user-interfaceemacsscriptingelispcommand

Emacs M-x commands for invoking "GUI-style" menus


Question: How could I find out the M-x equivalent commands for doing GUI-based operations in Emacs, in those cases where my Emacs-variant uses OS-specific desktop functionality?

Background: Conventional understanding states that everything in Emacs is a command, and that commands can be invoked via M-x, as long as you know the name of the command. Assuming this statement is correct, what is the way to find the name of the commands used to trigger the "GUI-style" menus in a "desktop" based Emacs variant?

For example, if I were to mouse-select the File menu to open a file, the OS-specific "GUI" style file-open dialog pops up, waiting for my input.

How could I find out the M-x equivalent command for doing the exact same thing?

I thought that describe-key would tell me what I needed to know, but it's indication to use:

M-x menu-find-file-existing

doesn't invoke the "GUI" style file-open dialog. Instead, it uses the Emacs internal non-GUI-OS-neutral variant.


Solution

  • You need to trick Emacs into thinking that the keyboard was not being used, which is not as intuitive as tricking it into thinking that the mouse was used. :)

    (defadvice find-file-read-args (around find-file-read-args-always-use-dialog-box act)
      "Simulate invoking menu item as if by the mouse; see `use-dialog-box'."
      (let ((last-nonmenu-event nil))
        ad-do-it))
    

    Tested on Emacs 22.2.1 on WinXP. I believe the paradigm has been around for a while, though, so it should work on older Emacs. No clue if XEmacs works similarly or not.