1

I found EasyMenu and and I tried the example:

(easy-menu-define my-menu global-map "My own menu"
  '("My Stuff"
    ["One entry" my-function t]
    ("Sub Menu"
     ["My subentry" my-obscure-function t])))

But when I try to show the menu with M-x my-menu then it says:

my-menu must be bound to an event with parameters

So it apparently should be added to a keymap, so the user can activate it. But how can I show this menu from elisp? (like (my-menu) or something)

So how can I programmatically show a simple menu like the above? I prefer built in solutions, so without external packages like Hydra and similiar.

Tom
  • 1,190
  • 7
  • 16
  • What kind of menu? Which properties should it have? Do you want a mouse hover menu like you get with right click in most Desktop Environments? – clemera Dec 15 '19 at 11:20
  • Simple menus of keys and corresponding actions, like the one F10 brings up. So I'd define key/action pairs for the user and show this menu to a user from a lisp program to quickly choose an action with a single key. – Tom Dec 15 '19 at 11:34
  • Okay so mouse support is not needed? – clemera Dec 15 '19 at 12:13
  • No, but it's a plus if it has one. Basically what I'm asking is how can I use a menu like what F10 pops up from my own programs to offer quick selections for the user? Since the F10 triggered menu is built in I guess the actual menu pop up which it shows (keys + actions) can be triggered from a program too. – Tom Dec 15 '19 at 12:58
  • In the menu you get by F10 you can't use keys to trigger the actions. There are many ways you could create menus in Emacs, that's why I'm asking for a more specific description. If you simply want the user choose from several options via a single keystroke you could for example use `read-char-choice` but I don't know if that is what you are searching for. – clemera Dec 15 '19 at 14:13
  • I certainly can trigger the menu items by keys of the F10 menu. Every item has a letter in front of it (f=Files, t=Tools, etc.) so you can quickly select any item by pressing its letter (and you can also use the mouse, the arrow keys,etc.) So this kind of menu which F10 displays could be great for quick multiple user choices in Lisp programs too. I'll check out read-char-choice, thanks, though I'm kind of surprised the F10-kind of menu cannot be displayed trivially from elisp, since the code is already there, the only thing missing is a way to setup and show such menu from elisp. – Tom Dec 15 '19 at 14:26
  • I checked the code and apparently tmm-prompt is the function which does the text menu and it works with the menu in my question, so this is the answer. I added it as an answer for future reference. – Tom Dec 15 '19 at 14:39
  • I was assuming the regular menu by `menu-bar-open` not tmm. I did not knew you could use menus defined by `easy-define-menu` with tmm, nice! – clemera Dec 15 '19 at 16:22
  • Yeah, I realized after I found the answer that we didn't talk about the same thing. I have the menubar turned off, so F10 shows me the tmm text menu, and I assume you have the menubar on, so F10 just operates on the graphical menu, so we didn't see the same thing. – Tom Dec 15 '19 at 16:58
  • Actually I tried what F10 gives you in `emacs -Q` to check what menu you meant ;) Personally I have bound F10 to `frog-tmm` using my [frog-menu](https://github.com/clemera/frog-menu) package but that is not built-in as you asked for. – clemera Dec 15 '19 at 17:02

1 Answers1

3

A quick text menu can be shown with tmm-prompt:

(tmm-prompt my-menu)

A graphical menu can also be shown:

(x-popup-menu (list '(200 200) (selected-window)) my-menu)
Tom
  • 1,190
  • 7
  • 16