9

For typing german text with an english keyboard layout the binding C-x 8 " is very valuable. After typing it I can insert umlauts easily. Here is what which-key shows me after typing C-x 8 "

characters are maped to Umlauts

I use this so often that I would like to use C-x 9 as an "alias" for this binding.

Unfortunatelly I can't figure out how. C-x 8 " is only a partial binding if I see it correctly. describe-key C-x 8 " doesn't show me anything and just waits for further input. It also doesn't seem to be

Ideally I would like something like

(set-global-key-alias-or-so "C-x 9" "C-x 8 \"") 

or

(global-set-key (kbd "C-x 9") 'whatever-is-behind-C-x-8-\") 

1 Answer 1

8

I can think of a couple of ways to do this. The main practical difference is whether you see C-x 8 " or C-x 9 in the minibuffer while waiting to read the next key.

Option 1 is to simulate the user actually typing C-x8":

(global-set-key (kbd "C-x 9") #'my-ctl-x-8-double-quote) (defun my-ctl-x-8-double-quote () "Simulate typing: C-x 8 \"" (interactive) (dolist (event (nreverse (list ?\C-x ?8 ?\"))) (push (cons t event) unread-command-events))) 

Option 2 is to bind C-x9 to the same keymap used by C-x8" (which is defined in key-translation-map):

(define-key key-translation-map (kbd "C-x 9") (lookup-key key-translation-map (kbd "C-x 8 \""))) 

Note that option 2 requires you to figure out where that prefix keymap lives (C-hb helps with that), while option 1 can be used even if you don't know that information.

See also: C-hig (elisp)Translation Keymaps

1
  • Very cool indeed. I went for option 2 which looks much cleaner to me and works flawlessly. Thank you. Commented Jul 10, 2021 at 16:32

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.