So, you just executed a complex, wonderful emacs command using the minibuffer and you’re so excited that need to immediately write it down, lest you forget. As you may already know, you don’t need pen and paper for that. Emacs will do it for you: just press C-x ESC ESC
(that is, repeat-complex-command
) and you’ll see an Elisp form in your minibuffer that reproduces your last command (C-h w C-x ESC ESC
for more details). Now C-a C-k
and you got it in the kill-ring, ready to be yanked in one of your configuration files.
I don’t use this trick that much because over the years more and more emacs automatisms are recorded either in my nervous system or my config files. Except for one thing: defining keybindings. There’re a bunch of ways to define a keybinding in emacs, and i’m never sure what’s the right one when there’re special keys involved. The solution is to define the key interactively with M-x global-set-key
. Once i’m done, i play C-x ESC ESC
and presto: an elisp snippet to yank in my .emacs appears in the minibuffer.
Happy binding!
July 16, 2007 at 1:01 pm
Thanks for the interactive global-set-key trick,
I finally found out how to bind M-space! (“\240” !!)
July 16, 2007 at 11:58 pm
[…] Quick keybindings So, you just executed a complex, wonderful emacs command using the minibuffer and you’re so excited that need to […] […]
August 22, 2007 at 10:37 pm
An easier way to figure out the key you need to specify for global/local-set-key is to use the kbd macro.
C-h c M-space –> M-SPC runs the command just-one-space
or
C-h c C-F3 –> is undefined
then simply use the key that it told you and wrap it with kbd.
(global-set-key (kbd “M-SPC”) ‘my-func)
(local-set-key (kbd “”) ‘another-func)