Trivial example of what I would like to do:

(define-prefix-command 'my-prefix-map)

(defun populate-my-prefix ()
  (define-key my-prefix-map (kbd "a") #'move-beginning-of-line))

(define-key global-map (kbd "<f6>") #'my-prefix-map)

Upon pressing f6 I would like to run populate-my-prefix, before my-prefix-map is executed.

I think Hydra can do something like this (call another function upon entering the Hydra), but I'm writing my own package and would rather not depend on it.

  • does it work if you just bind populate-my-prefix to f6, but have it return the keymap? – Xah Lee Aug 17 '16 at 12:23
  • @XahLee Not sure, I somewhat solved it by binding it to poulate-my-prefix and at the end of that function I used (set-transient-map 'my-prefix-map). That works, but I feel that it doesn't really answer the actual question. I also tried using add-advice and add-function to my-prefix-map, but I couldn't get that to work. – Erik Sjöstrand Aug 17 '16 at 12:30
  • I believe this is a duplicate question, but I don't have time to look for it now... – Drew Aug 17 '16 at 14:52
  • Perhaps you can use a 'conditional key binding' such that it does something the first time and sets some state so that the condition no longer applies on subsequent calls? See emacs.stackexchange.com/questions/26295/…. – glucas Aug 17 '16 at 15:24

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.