Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For instance, I get to use C-c a a a lot, and would like to easily map this to f1.

I know I can search for what function the first binding finaly calls (this time it was org-agenda-list), but I'm after a more general solution. I don't think I can use (global-set-key KEY COMMAND), for I'm not sure if pressing keys is a COMMAND in itself (but maybe it can be?)

So how to bind "multiple successive keypresses" to another binding?

share|improve this question
up vote 2 down vote accepted

The code you are looking for is:

(define-key keymap-1 (kbd "new prefix")
 (lookup-key keymap-2 (kbd "old prefix")))

You don't usually need to know the names of the keymaps as the expressions (current-global-map) and (current-local-map) return the global and local maps in force. Although the emacs manual says you can re-map any of the function keys, I have found that strange things can happen if you try to re-map f1, f2, f3, f4 or f10. For this reason I usually re-map f5 or f6. As an example from my .emacs file, the code:

(add-hook 'planner-mode-hook
    #'(lambda ()
        (local-set-key (kbd "M-RET") 'muse-insert-list-item)
        (local-set-key (kbd "M-S-RET") 'pcomplete)
        (define-key (current-local-map) (kbd "<f5>")
          (lookup-key (current-local-map) (kbd "C-c C-j")))))

sets M-RET and M-S-RET in planner-mode and also makes the prefix f5 into an alias for C-c C-j in that mode.

Be aware, however, that it doesn't always work as lookup-key seem understand macros which, unfortunately, are legal in keymaps. In such cases you can usually find a way round it. Ask again if you have problems.

share|improve this answer
    
I'm not sure why you're mentionning prefixes, but this works, and the hook idea is interesting (even though i'm more familiar with knowing how keymaps are called). I donk know much about macros, the bright side being I therefore don't care (I mean, if that's the C-x ( / C-x ) thing, mapping constructs based on them to other bindings seems very deviant to me >_<). Are you running in problems with f1 to f4 and f10 because they're already bound, sometimes later defined than your own definition, by any chance ? – Nikana Reklawyks Nov 20 '12 at 7:08
    
Some major modes rebind them. For instance f1 is bound to help but some major modes have their own variant of help and re-bind the key. I find it easier not to use them. – Bernard Hurley Nov 20 '12 at 8:33

I think, but didn't try, that you should do something like this:

(defun org-execute-my-action ()
  (local-set-key (kbd "C-c q") 'org-name-of-function))

(add-hook 'org-mode-hook 'org-execute-my-action)

This post seems to be the place for further details.

share|improve this answer
    
Err, I don't see how that's adressing my question… That's merely binding a key locally in the org-mode-map, right? I'd like to bind a one key to "multiple keypresses". (For instance, there is no place for f1 in you example.) – Nikana Reklawyks Nov 4 '12 at 20:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .