2

I want to be able to automatically insert pre-defined strings when pressing a certain keybinding. Currently this is being done with the following code snippet:

;;;;; Personal keybindings                                                
(global-set-key [f6] "\autocite[--]{}")

The problem is, that this does not work (the one in the example). Instead, Emacs will tell me "After 0 kbd macro iterations: Quit" which does not show up, when just doing the string without the "\". So how could I fix this and enter pre-defined strings which include special character such as "\"?

3

You need to double backslashes within strings:

(global-set-key [f6] "\\autocite[--]{}")

A more reliable binding uses the insert function explicitly:

(global-set-key [f6] #'(lambda ()
                         (interactive)
                         (insert "\\autocite[--]{}")))

and you'll probably want to move point within the braces:

(global-set-key [f6] #'(lambda ()
                         (interactive)
                         (insert "\\autocite[--]{}")
                         (forward-char -1)))
  • @jch I would prefer defining the interactive function first and then binding a key to that function name. – Kaushal Modi Nov 1 '15 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.