Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I use English keyboard and need to type some German letters from time to time. So I defined

(global-set-key [?\C-\;] (make-sparse-keymap))
(global-set-key [?\C-\; ?A] [?\x08C4]) 
...

to insert "ä", etc. It used to work for years, but it doesn't work with my current GNU Emacs 23.1.1. I realize that using characters hardcoded as numbers is no good idea, but it helped me to work around encoding problems (only this worked fine on Sun, Linux, and Windows even with shared filesystems).

What is the best way to define keys for inserting special characters in Emacs?

share|improve this question
    
Is \x08C4 just a typo? It's \x00E4 for ä... Your elisp code works fine on my GNU Emacs 23.1.1 (Linux Ubuntu) –  Peter.O Apr 3 '12 at 6:13
    
No, this is for sure no typo, I copied it and now re-checked. It used to work this way... now it inserts U+08c4 while your \x00C4 works.... It's logical, I know, and I really can't recall why I was using \08C4; I might have written this 10 years ago or about. Maybe create an answer, so I can accept it if no better comes. –  maaartinus Apr 3 '12 at 6:29
    
Just a thought. I don't know enough about it, but as you set that up 10 years ago, perhaps you were using Mule then and not Unicode, which it appears to be using now... –  Peter.O Apr 3 '12 at 7:06
    
Yes, I remember there was something called Mule. –  maaartinus Apr 16 '12 at 13:17

1 Answer 1

up vote 1 down vote accepted

EDIT: Added possible easier way to enter your special chars.

Your elisp code works fine on my GNU Emacs 23.1.1 (Linux Ubuntu)

Both the following two methods of setting the shortcut key work (in my emacs), without any need for this first make-sparse-keymap line.
   (global-set-key [?\C-\;] (make-sparse-keymap))

(global-set-key [?\C-\; ?A] [?\x00E4])
(define-key key-translation-map (kbd "C-; a") (kbd "ä"))

An easier way to enter your special chars could be to use an input method which contains the characters you need. In the case of 'ä", latin-1-prefix is suitable.

Select a alternative input method via either

  • C-x RET C-\
  • M-x set-input-method

Choose latin-1-prefix

To enter the char ä, toggle into latin-1-prefix and type "a
Depending on what you generally type. you may not need to toggle back out of latin-1-prefix

To toggle the input method (enable or disable).

  • C-\

To describe the current input method, use either

  • C-h C-\
  • C-h I

For more details, see:

Also, there is some general info on Xah Lee's Emacs and Unicode Tips page.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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