2

Emacs defines a fair variety of objects that can be bound to keys, with e.g. global-set-key. (The canonical list can be found here).

I would like to simulate the invocation of a keymap entry. For example, I would expect:

  1. If the object is a command, the command is run,
  2. If the object is a keyboard macro, it is replayed,
  3. etc.

What is the simplest way to do this?

2

For a command or a symbol whose symbol-function is a command (which includes the case where it is a keyboard macro), use command-execute.

That's about all there is. The other possibilities for key bindings are to keymaps, to help with looking up key sequences to get the associated commands.

Your question is not too clear about what you expect as input. Are you expecting the function you seek to do key-sequence lookup, so you will pass it menu items and such? If not, it all boils down to commands and command-execute in the end.

  • I would like it to execute menu-item bindings as well, if possible. – PythonNut Jun 24 '18 at 3:32
  • Then, as I suggested, you need to examine the currently active keymaps and do some key-sequence lookup first, to get the command(s) that you apply command-execute to. There are multiple possible forms for menu items, and they can appear on multiple keymaps. You can take a look at the code in lacarte.el to get an idea. See, e.g., function lacarte-add-if-menu-item. – Drew Jun 24 '18 at 16:00

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.