入力メソッドを切り替えるための「C-\」があることは知っていますが、追加の入力メソッドは1つしか許可されていません。たとえば、デフォルトでは英語のqwertyレイアウトがあり、dvorakと切り替えることができます。
しかし、同じように簡単に他の2つの言語を切り替える方法はありますか?たとえば、english-dvorakと母国語のレイアウトを交互に使用したい場合はどうすればよいですか?
入力メソッドを切り替えるための「C-\」があることは知っていますが、追加の入力メソッドは1つしか許可されていません。たとえば、デフォルトでは英語のqwertyレイアウトがあり、dvorakと切り替えることができます。
しかし、同じように簡単に他の2つの言語を切り替える方法はありますか?たとえば、english-dvorakと母国語のレイアウトを交互に使用したい場合はどうすればよいですか?
2つ以上の代替入力方法をすばやく切り替えるために、次のコードを追加しましたinit.el
。
;; Input method and key binding configuration.
(setq alternative-input-methods
'(("russian-computer" . [?\C-\\])
("chinese-py-punct" . [?\C-|])
("german-postfix" . [?\C-\M-|])))
(setq default-input-method
(caar alternative-input-methods))
(defun toggle-alternative-input-method (method &optional arg interactive)
(if arg
(toggle-input-method arg interactive)
(let ((previous-input-method current-input-method))
(when current-input-method
(deactivate-input-method))
(unless (and previous-input-method
(string= previous-input-method method))
(activate-input-method method)))))
(defun reload-alternative-input-methods ()
(dolist (config alternative-input-methods)
(let ((method (car config)))
(global-set-key (cdr config)
`(lambda (&optional arg interactive)
,(concat "Behaves similar to `toggle-input-method', but uses \""
method "\" instead of `default-input-method'")
(interactive "P\np")
(toggle-alternative-input-method ,method arg interactive))))))
(reload-alternative-input-methods)
したがって、ロシア語、中国語、またはドイツ語のIMEに切り替えるにはC-\、を使用C-|しますC-M-|。また、英語に戻すには、現在のIMEと同じキーを使用します(つまり、中国語のIMEをアクティブにしている場合は、を使用して元に戻しますC-|)。
使用alternative-input-methods
変数を構成します。これは、入力メソッド名とキーバインディングの結果のリストです。
ノート!M-x toggle-input-method
呼び出しまたはによってIMEをアクティブ化する場合C-u C-\、を押すと、変数C-\に応じて入力メソッドに切り替わりalternative-input-methods
ます(デフォルトの構成では、Emacsは新しいIMEを記憶し、それをに使用しますC-\)。
1C-u C-\
つの入力メソッドを選択するように入力し、もう一度別の入力メソッドを選択すると、後続のすべての呼び出しで前の入力メソッドがデフォルトの入力として使用されることがわかります。したがって、他の入力メソッドに切り替えると、になりC-u C-\ RET
ます。
(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