Created
January 28, 2022 03:21
-
-
Save thyeem/ea495ff1380b4d5fcd18b7038f1939ff to your computer and use it in GitHub Desktop.
Less annoying way to switch input method when using evil-mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; prerequisites: im-select (https://github.com/daipeihust/im-select) | |
;; | |
;; install it! | |
;; $ curl -Ls https://raw.githubusercontent.com/daipeihust/im-select/master/install_mac.sh | sh | |
;; | |
;; make sure that Emacs can execute 'im-select'. (Is it on the right $PATH?) | |
(setq english-im "com.apple.keylayout.ABC") | |
(setq previous-im "com.apple.keylayout.ABC") | |
(defun use-english-im () | |
"use english input method" | |
(interactive) | |
(call-process-shell-command (concat "im-select " english-im))) | |
(defun set-previous-im () | |
"set input method to the previously saved one" | |
(interactive) | |
(setq previous-im | |
(substring (shell-command-to-string "im-select") 0 -1))) | |
(defun use-previous-im () | |
"use the previous input method" | |
(interactive) | |
(call-process-shell-command (concat "im-select " previous-im))) | |
(add-hook 'evil-normal-state-entry-hook 'use-english-im) | |
(add-hook 'evil-insert-state-entry-hook 'use-previous-im) | |
(add-hook 'evil-insert-state-exit-hook 'set-previous-im) | |
(add-hook 'evil-replace-state-entry-hook 'use-previous-im) | |
(add-hook 'evil-replace-state-exit-hook 'set-previous-im) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment