Some keys are invalid on emacs when using German keyboard

emacskdekeyboard

When I am using emacs 23.3 on KDE, I can not input ^, ´ and ~ from my German keyboard. If I press these keys, then emacs says that <dead-circumflex>, <dead-acute> and <dead-tilde> are undefined.

I can input ^, ´ and ~ on other applications (e.g. Konsole, Kwrite and firefox), and I can also paste these letters on emacs.

I have tried to type C-x ret C-\ latin-1-postfix, but there is no change.

Could anyone tell me how to solve this problem?

Best Answer

I don't know what's causing this problem or how to fix this, but I can offer a workaround for most purposes.

Normally, dead keys are processed at a very low input layer, not even visible from Lisp. But you can do the processing in Lisp.

If you want the keys to act as dead keys:

There is already a limited mechanism for dead keys in Lisp, designed for 8-bit character sets on machines that don't have any way to input non-ASCII characters. If you type C-x 8 followed by an accent and a letter, the corresponding accented letter is inserted, thanks to the iso-transl library. We can copy this mechanism. Put this in your .emacs:

(define-key key-translation-map [dead-grave] (lookup-key key-translation-map "\C-x8`"))
(define-key key-translation-map [dead-acute] (lookup-key key-translation-map "\C-x8'"))
(define-key key-translation-map [dead-circumflex] (lookup-key key-translation-map "\C-x8^"))
(define-key key-translation-map [dead-diaeresis] (lookup-key key-translation-map "\C-x8\""))
(define-key key-translation-map [dead-tilde] (lookup-key key-translation-map "\C-x8~"))
(define-key isearch-mode-map [dead-grave] nil)
(define-key isearch-mode-map [dead-acute] nil)
(define-key isearch-mode-map [dead-circumflex] nil)
(define-key isearch-mode-map [dead-diaeresis] nil)
(define-key isearch-mode-map [dead-tilde] nil)

The map key-translation-map rewrites key sequences as they are entered, so this will make dead ` a equivalent to à for most purposes. Explicitly setting entries in isearch-mode-map to nil is necessary because otherwise pressing a dead key would exit isearch before the translation could kick in.

If you want the accent characters to be inserted immediately

(define-key key-translation-map [dead-grave] "`")
(define-key key-translation-map [dead-acute] "'")
(define-key key-translation-map [dead-circumflex] "^")
(define-key key-translation-map [dead-diaeresis] "\"")
(define-key key-translation-map [dead-tilde] "~")
Related Question