views:

113

answers:

2

As you probably know if you write text in multiple languages and use Emacs, Emacs has its own input method system independent of Windows (or other operating systems). Input methods can be toggled with toggle-input-method command. When Windows language changes, Emacs receives a <language-change> keypress. I would like then to bind <language-change> to toggle-input-method. Unfortunately, if I do just

(global-set-key (kbd "<language-change>") 'toggle-input-method)

both Windows language and input method will be toggled. So I need something like

(defvar safe-language-change-flag nil)
(defun safe-language-change ()
  (interactive)
  (setq safe-language-change-flag (not safe-language-change-flag))
  (when safe-language-change-flag
    (toggle-input-method)
    (send-key (kbd "<language-change>"))))

(global-set-key (kbd "<language-change>") 'safe-language-change)

What I can't seem to find is a function call which would send a key to the operating system (or change the system language in another way).

+1  A: 

Just to make sure, you want this to happen: You change the language in the OS. Emacs gets this event, sends a keypress back to the OS, and then un-changes the language.

You may be able to call an external utility to do this.

I'm not sure why you want to do this, though.

If you've changed the OS's language, then let the OS handle the input method. If you don't want to use your OS's input method, then do toggle-input-method inside emacs, and don't bother worrying about the OS's state.

Am I missing something?

jrockway
A: 

If you don't want to use your OS's input method, then do toggle-input-method inside emacs, and don't bother worrying about the OS's state.

This is precisely the result I want to get. The difficulty is that I find myself switching the OS input method instead all the time because "press Shift to switch language" is a part of my finger memory by now.

Alexey Romanov