0

My goal Write code in my init.el file so that from now on, M-v will just print the BELL character (character number 27 in hexadecimal) instead of scrolling down as it does by default.

My failed attempts :

Attempt 1: (global-set-key (kbd "M-v") (quote ("'")))

This gives no error message but M-v just says command undefined and does not print the character.

Attempt 2 : (global-set-key (kbd "M-v") (insert-char("BELL")))

Produces the following error message :

Warning (initialization): An error occurred while loading ‘.emacs.d/init.el’: 
Invalid function: BELL

Attempt 3 : (global-set-key (kbd "M-v") (insert-char(#x27)))

Produces the following error message:

Warning (initialization): An error occurred while loading ‘.emacs.d/init.el’:
Invalid function: 39
  • 1
    #x27 is an apostrophe, I guess you mean 7 (the ASCII "bell" character). There is also #x1F514 for the "bell emoji" 🔔. Or if you actually want the sound, see (elisp) Beeping. – npostavs Sep 26 '18 at 11:46
3

Keybindings need to refer to commands, which means you need to wrap your code in a lambda form. Also this is Lisp, so you don't need to surround the arguments to a function in parentheses. That all adds up to:

(global-set-key (kbd "M-v") (lambda ()
                  (interactive)
                  (insert-char #x27)))
| improve this answer | |
  • Just checked that it works, thank you ! – Ewan Delanoy Sep 26 '18 at 10:42

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.