Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to smart switch Rus/Eng mode when use Emacs and Evil mode (or Spasemacs)
;; Mac OS Edition
;; This code helps us to work with Spacemacs (Emacs + Evil mode) in multilanguage mode
;; You need to install https://github.com/vovkasm/input-source-switcher
;; It's a console utilite to switch input language.
;; Pavel Pavlov (c) 2015
;; In other OS you'll have to change name of langages layers and name of Switcher like issw
;; In thу Terminal # issw show you namу of the current layout
(setq lang_source "com.apple.keylayout.US") ;set default var lang_source for issw arg
(add-hook 'evil-insert-state-entry-hook ;what we do when enter insert mode
(lambda ()
(shell-command (concat "issw " lang_source)))) ;
;
(add-hook 'evil-insert-state-exit-hook ;what we do when enter normal mode
(lambda ()
(setq lang_source (shell-command-to-string "issw"))
(shell-command "issw com.apple.keylayout.US")))
(setq lang_source "com.apple.keylayout.US") ;set default var lang_source for issw arg
(add-hook 'evil-replace-state-entry-hook ;what we do when enter insert mode
(lambda ()
(shell-command (concat "issw " lang_source)))) ;
;
(add-hook 'evil-replace-state-exit-hook ;what we do when enter normal mode
(lambda ()
(setq lang_source (shell-command-to-string "issw"))
(shell-command "issw com.apple.keylayout.US")))
@jiahut

This comment has been minimized.

Copy link

@jiahut jiahut commented Jan 17, 2019

Unfortunately, it does not work in spacemacs which I still don't understand

@bebound

This comment has been minimized.

Copy link

@bebound bebound commented May 9, 2019

Thank you, it works.

However enter/leave evil mode become really laggy (takes 1 second), is there anyway to reduce the lag?
Will emacs start new shell when run shell-command? I do have lots of config in my default shell zsh.

Solved by adding (setq shell-file-name "/bin/bash")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.