Emacs hot-keys in non-English keyboard layout

Posted on Sat, 10 Jun 2017 in Editors & IDE

You are lucky if you need to use standard English keyboard layout only. I use Russian layout as often as English one. Everywhere hot-keys work OK, except Emacs. Maybe because it has an ASCII-is-enough-for-everybody legacy or other reasons, Emacs uses own weird way to switch layouts (or Input Method in Emacs terms): C-\. Instead of using that "standard" way I found another option.

This snippet is taken from the post written by Vladimir "Горячие клавиши Emacs в русской раскладке".

To use it just add this code to your Emacs config file:

(defun reverse-input-method (input-method)
  "Build the reverse mapping of single letters from INPUT-METHOD."
   (list (read-input-method-name "Use input method (default current): ")))
  (if (and input-method (symbolp input-method))
      (setq input-method (symbol-name input-method)))
  (let ((current current-input-method)
        (modifiers '(nil (control) (meta) (control meta))))
    (when input-method
      (activate-input-method input-method))
    (when (and current-input-method quail-keyboard-layout)
      (dolist (map (cdr (quail-map)))
        (let* ((to (car map))
               (from (quail-get-translation
                      (cadr map) (char-to-string to) 1)))
          (when (and (characterp from) (characterp to))
            (dolist (mod modifiers)
              (define-key local-function-key-map
                (vector (append mod (list from)))
                (vector (append mod (list to)))))))))
    (when input-method
      (activate-input-method current))))

(reverse-input-method 'russian-computer)

If you are a Spacemacs user, add this code into dotspacemacs-configuration-layers in your .spacemacs.

      :location (recipe
                 :fetcher github
                 :repo "avkorablev/reverse-input-method-layer"))

and this code into the body of dotspacemacs/user-config function

(reverse-input-method 'russian-computer)

It works perfectly. The only issue I know is that recalculation of OrgTable formulas isn't working in Russian layout because it is mapped to C-c-* and * change its location.