Hacker News new | past | comments | ask | show | jobs | submit login

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?




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".


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)")))




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: