Skip to content

Instantly share code, notes, and snippets.

@takaxp
Last active September 25, 2016 16:32
Show Gist options
  • Save takaxp/6ee8cc165f5f71007d48d4e17639d1e7 to your computer and use it in GitHub Desktop.
Save takaxp/6ee8cc165f5f71007d48d4e17639d1e7 to your computer and use it in GitHub Desktop.
restore last IME setting even if mac-auto-ascii-mode is ON
(defvar mac-win-last-ime-status 'off) ;; {'off|'on}
(defun mac-win-save-last-ime-status ()
(setq mac-win-last-ime-status
(if (string-match "\\.Roman$" (mac-input-source))
'off 'on)))
(defun advice:mac-auto-ascii-setup-input-source (&optional _prompt)
"Extension to store IME status"
(mac-win-save-last-ime-status))
(advice-add 'mac-auto-ascii-setup-input-source :before
#'advice:mac-auto-ascii-setup-input-source)
(defun mac-win-restore-ime ()
(when (and mac-auto-ascii-mode (eq mac-win-last-ime-status 'on))
(mac-select-input-source
"com.google.inputmethod.Japanese.base")))
(add-hook 'minibuffer-setup-hook 'mac-win-save-last-ime-status)
(add-hook 'minibuffer-exit-hook 'mac-win-restore-ime)
(defvar mac-win-target-commands
'(list
find-file save-buffer other-window delete-window split-window))
(add-to-list 'mac-win-target-commands 'helm-buffers-list)
(defun mac-win-restore-ime-target-commands ()
(when (and mac-auto-ascii-mode
(eq mac-win-last-ime-status 'on))
(mapc (lambda (command)
(when (string-match
(format "^%s" command) (format "%s" this-command))
(mac-select-input-source
"com.google.inputmethod.Japanese.base")))
mac-win-target-commands)))
(add-hook 'pre-command-hook 'mac-win-restore-ime-target-commands)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment