0

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.

  • 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
1

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)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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