I am trying to write a function that can be used to make a keybinding "remember" the key sequence that led up to the function being called.

(defun modal-function (func)
  (funcall func)
  (set-transient-map (somehow-get-map-that-called-this-function)))

(global-set-key (kbd "C-x m h") (lambda () (interactive) (modal-function 'move-left)))
(global-set-key (kbd "C-x m j") (lambda () (interactive) (modal-function 'move-down)))
(global-set-key (kbd "C-x m k") (lambda () (interactive) (modal-function 'move-up)))
(global-set-key (kbd "C-x m l") (lambda () (interactive) (modal-function 'move-right)))

So running C-x m h j k l would result in (move-left) (move-down) (move-up) (move-right).

I've read the posts about making one command repeatable as well as smartrep.el but it is not really what I'm looking for.

  • 3
    Any reason why you don't want to use the hydra package for that? – Stefan Oct 7 '18 at 13:30

Your Answer

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

Browse other questions tagged or ask your own question.