Is it possible to alternate two input methods in Emacs?

Viewed 1437

I know that there is "C-\" to switch input methods, but that allows only one additional input method - for example, by default I have english qwerty layout, and I can alternate between it and dvorak.

But is there some way to do alternation between two other languages with the same ease? For example, if I want to alternate english-dvorak and my native language layout?

3 Answers
(setq my/input-methods '(nil "some-input-method" "japanese" ))
(defvar my/input-method-switch-counts 0 "a count; more than index")
(make-variable-buffer-local 'my/input-method-switch-counts)
(put 'my/input-method-switch-counts 'permanent-local t)
(defun my/switch-input-method () 
  (interactive)
  (setq my/input-method-switch-counts
        (1+ my/input-method-switch-counts))
  (let ((i (nth (% my/input-method-switch-counts
                   (length my/input-methods)
                   )
                my/input-methods
                )))
    (set-input-method i)  ;;interactive use may set any needed
    )
  ;;(message "IME %s on" current-input-method)
  )

(global-set-key (kbd "C-<SPC>") 'my/switch-input-method)
;;also make sure mode-line-mule-info in mode-line-format to show current input-method in mode-line
Related