Is it possible to write an execute-next-command function that calls the command that would have been called if the current binding was not active?

For example, RET is bound to newline by default. Let's say that I bind RET to my-command. In some cases, my-command should execute whatever would have been executed for RET if I hadn't bound it to my-command. I could save the old binding before rebinding RET, but I would rather avoid that.

EDIT: There is the key-binding function, but it doesn't let you find the next binding.


It's doable with minor modes. Suppose you have my-minor-mode active in an org-mode buffer. And you have:

(define-key my-minor-mode-map (kbd "M-RET") #'save-buffer)

You could call the old RET binding in org-mode with:

 (lookup-key org-mode-map (kbd "M-RET")))
  • This requires you figure out what other mode was the last to make a binding for that key.
    – Omar
    Jun 30 '15 at 14:09
  • You could let-bind my-minor-mode to nil and use key-binding instead, which checks all active maps, not just the one you pass in.
    – npostavs
    Jun 30 '15 at 14:38

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.