News for hackers. Stuff that matters.
Re:Mastering Key Bindings in Emacs by funptr on Wednesday February 09, 2011 @10:16AM (#2197629)
It's not part of emacs, I just wrote it as an example.
Re:Mastering Key Bindings in Emacs by silentbicycle on Wednesday February 09, 2011 @10:29AM (#2197676)
Oh, right. Sorry, hadn't had my coffee yet.

I tried doing exactly that, but used (interactive "kKey: "), with lowercase k, and it didn't work.

Re:Mastering Key Bindings in Emacs by funptr on Wednesday February 09, 2011 @10:35AM (#2197714)
That seems to work also, what's the problem?
Re:Mastering Key Bindings in Emacs by silentbicycle on Wednesday February 09, 2011 @10:40AM (#2197745)
Didn't work correctly with a few slightly-more elaborate key combinations I tried. IIRC C-x M-. was one of them.

I much prefer formatting the keybindings like kbd uses, anyway - do you know offhand how to convert a keypress to that format w/out using C-h k?

Re:Mastering Key Bindings in Emacs by funptr on Wednesday February 09, 2011 @10:54AM (#2197825)
Not offhand, but I looked it up and I think what you want is `key-description'. It prints key sequences, so e.g. (key-description "\370") evals to "M-x".
Re:Mastering Key Bindings in Emacs by silentbicycle on Wednesday February 09, 2011 @11:24AM (#2197974)
Bingo. Thanks.

This should do what the original commenter wanted:

    (defun insert-keybinding (k)
      "Insert code for a keybinding."
      (interactive "kKey sequence: ")
      (insert (concat "(global-set-key (kbd \""
    		  (key-description k)
    		  "\") 'function-name)")))