How to input Non-English character in evil-mode efficiently

  |   Source

to input Non-English character in evil-mode efficiently :en:emacs:evil:

You can M-x toggle-input-method or C-\ to input Non-English characters.

Analysis about evil-mode,

  • You only input Non-English characters in evil-insert-state. So you need go into evil-insert-state at first before toggle on input method
  • In evil-insert-state, you can toggle off input method to input English characters while staying in evil-insert state
  • When press ESC, you quit from evil-insert-state. But input method could be still activated. So when you re-enter evil-insert-state, you need notification of input method status

Here is the setup,

;; {{ make IME compatible with evil-mode
(defun evil-toggle-input-method ()
  "when toggle on input method, goto evil-insert-state. "
  (interactive)

  ;; load IME when needed, less memory footprint
  ;; (unless (featurep 'chinese-pyim)
  ;;   (require 'chinese-pyim))

  (cond
   ((and (boundp 'evil-mode) evil-mode)
    ;; evil-mode
    (cond
     ((eq evil-state 'insert)
      (toggle-input-method))
     (t
      (evil-insert-state)
      (unless current-input-method
        (toggle-input-method))
      ))
    (if current-input-method (message "IME on!")))
   (t
    ;; NOT evil-mode, some guy don't use evil-mode at all
    (toggle-input-method))))

(defadvice evil-insert-state (around evil-insert-state-hack activate)
  ad-do-it
  (if current-input-method (message "IME on!")))

(global-set-key (kbd "C-\\") 'evil-toggle-input-method)
;; }}

Chinese version:

在evil-mode中切换输入法有以下要点,

  • 输中文前须进入evil-insert-state
  • 在evil-insert-state中可能会切换输入法
  • 按ESC退出evil-insert-state时输入法可能还开着,所以再进入evil-insert-state时需提示输入法状态

代码见上.

Comments powered by Disqus