Skip to content

Instantly share code, notes, and snippets.

@ghost355
Last active May 22, 2022 02:22
Show Gist options
  • Save ghost355/a967417bb7e826e833d4 to your computer and use it in GitHub Desktop.
Save ghost355/a967417bb7e826e833d4 to your computer and use it in GitHub Desktop.
How to smart switch Russian /English keyboard layout mode when use Emacs and Evil mode (or Spacemacs)
;; 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 shell-file-name "/bin/bash")
(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
Copy link

jiahut commented Jan 17, 2019

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

@bebound
Copy link

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")

@ghost355
Copy link
Author

I had a problem too - my script didn't work properly. Just try to use another version of Emacs
https://emacsformacosx.com
27-1-1 is working

@yeonsh
Copy link

yeonsh commented May 22, 2022

I tried this and it works perfectly.

https://github.com/laishulu/emacs-smart-input-source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment