This all works well when you want to write using a different locale temporarily, but it doesn’t work well when you want to have an input method enabled every time you’re in a mode. For instance, if I want to type text in Spanish every time I’m in org-mode , I would need to issue the M-x set-input-method command every time I open this mode. This is obviously an inconvenience, and the Emacs life is all about making the editor just the way you want it.

To permanently set an input method for a mode, we will need to add something like this to our init file.

;; Set latin-1-prefix as default locale ( setq default-input-method "latin-1-prefix" ) ( defun activate-default-input-method () ( interactive ) (activate-input-method default-input-method)) (add-hook 'org-mode-hook 'activate-default-input-method)

Here we are indicating that latin-1-prefix will be our new default-input-method and the function will enable this method for org-mode . This way, every time we open org-mode , I will be ready to type in Spanish. This is a white-listing approach, where we select the modes that will have an input method applied, but we can also take the opposite approach. A blacklist method approach will enable an input method for ALL modes except for the ones indicated. This was the first approach I took, but soon realized that I have too many key bindings that would be disabled by the special character keys. Here’s an example of the blacklist approach.

;; Set latin-1-prefix as default locale ( setq default-input-method "latin-1-prefix" ) ( defvar use-default-input-method t) (make-variable-buffer-local 'use-default-input-method) ( defun activate-default-input-method () ( interactive ) ( if use-default-input-method (activate-input-method default-input-method) (inactivate-input-method))) (add-hook 'after-change-major-mode-hook 'activate-default-input-method) (add-hook 'minibuffer-setup-hook 'activate-default-input-method) ( defun inactivate-default-input-method () ( setq use-default-input-method nil)) ;; Blacklisted modes (add-hook 'c-mode-hook 'inactivate-default-input-method) (add-hook 'go-mode-hook 'inactivate-default-input-method) (add-hook 'markdown-mode-hook 'inactivate-default-input-method) (add-hook 'sh-mode-hook 'inactivate-default-input-method)