Emacs: Xah Fly Keys for Russian Layout

By Xah Lee. Date: .

Russian keyboard users usually need to switch between Russian layout and English layout.

Here's some useful Russian layout addon for xah-fly-keys.

Put it after loading xah-fly-keys.

(defun xah-fly-keys-russian-on ()
  "Add Russian layout keys.
Hook function for `xah-fly-command-mode-activate-hook'
 2018-10-26 Thanks to TechiBech
Version 2018-10-27"
  (interactive)
  (progn
    (define-key xah-fly-key-map (kbd "й") 'xah-reformat-lines)
    (define-key xah-fly-key-map (kbd "ц") 'xah-shrink-whitespaces)
    (define-key xah-fly-key-map (kbd "э") 'xah-cycle-hyphen-underscore-space)
    (define-key xah-fly-key-map (kbd "у") 'xah-backward-kill-word)
    (define-key xah-fly-key-map (kbd "я") 'xah-comment-dwim)
    (define-key xah-fly-key-map (kbd "х") 'hippie-expand)
    (define-key xah-fly-key-map (kbd "ф") 'execute-extended-command)
    (define-key xah-fly-key-map (kbd "т") 'isearch-forward)
    (define-key xah-fly-key-map (kbd "ш") 'previous-line)
    (define-key xah-fly-key-map (kbd "р") 'xah-beginning-of-line-or-block)
    (define-key xah-fly-key-map (kbd "в") 'xah-delete-backward-char-or-bracket-text)
    (define-key xah-fly-key-map (kbd "н") 'undo)
    (define-key xah-fly-key-map (kbd "г") 'backward-word)
    (define-key xah-fly-key-map (kbd "о") 'backward-char)
    (define-key xah-fly-key-map (kbd "п") 'xah-delete-current-text-block)
    (define-key xah-fly-key-map (kbd "с") 'xah-copy-line-or-region)
    (define-key xah-fly-key-map (kbd "м") 'xah-paste-or-paste-previous)
    (define-key xah-fly-key-map (kbd "з") 'xah-insert-space-before)
    (define-key xah-fly-key-map (kbd "ь") 'xah-backward-left-bracket)
    (define-key xah-fly-key-map (kbd "д") 'forward-char)
    (define-key xah-fly-key-map (kbd "ы") 'open-line)
    (define-key xah-fly-key-map (kbd "к") 'xah-kill-word)
    (define-key xah-fly-key-map (kbd "ч") 'xah-cut-line-or-region)
    (define-key xah-fly-key-map (kbd "щ") 'forward-word)
    (define-key xah-fly-key-map (kbd "ж") 'xah-end-of-line-or-block)
    (define-key xah-fly-key-map (kbd "л") 'next-line)
    (define-key xah-fly-key-map (kbd "а") 'xah-fly-insert-mode-activate)
    (define-key xah-fly-key-map (kbd "б") 'xah-next-window-or-frame)
    (define-key xah-fly-key-map (kbd "и") 'xah-toggle-letter-case)
    (define-key xah-fly-key-map (kbd "е") 'set-mark-command)))

(defun xah-fly-keys-russian-off ()
  "Remove Russian layout keys.
Hook function for `xah-fly-insert-mode-activate-hook'
 2018-10-26 Thanks to TechiBech
Version 2018-10-27"
  (interactive)
  (progn
    (define-key xah-fly-key-map (kbd "й") 'nil)
    (define-key xah-fly-key-map (kbd "ц") 'nil)
    (define-key xah-fly-key-map (kbd "э") 'nil)
    (define-key xah-fly-key-map (kbd "у") 'nil)
    (define-key xah-fly-key-map (kbd "я") 'nil)
    (define-key xah-fly-key-map (kbd "х") 'nil)
    (define-key xah-fly-key-map (kbd "ф") 'nil)
    (define-key xah-fly-key-map (kbd "т") 'nil)
    (define-key xah-fly-key-map (kbd "ш") 'nil)
    (define-key xah-fly-key-map (kbd "р") 'nil)
    (define-key xah-fly-key-map (kbd "в") 'nil)
    (define-key xah-fly-key-map (kbd "н") 'nil)
    (define-key xah-fly-key-map (kbd "г") 'nil)
    (define-key xah-fly-key-map (kbd "о") 'nil)
    (define-key xah-fly-key-map (kbd "п") 'nil)
    (define-key xah-fly-key-map (kbd "с") 'nil)
    (define-key xah-fly-key-map (kbd "м") 'nil)
    (define-key xah-fly-key-map (kbd "з") 'nil)
    (define-key xah-fly-key-map (kbd "ь") 'nil)
    (define-key xah-fly-key-map (kbd "д") 'nil)
    (define-key xah-fly-key-map (kbd "ы") 'nil)
    (define-key xah-fly-key-map (kbd "к") 'nil)
    (define-key xah-fly-key-map (kbd "ч") 'nil)
    (define-key xah-fly-key-map (kbd "щ") 'nil)
    (define-key xah-fly-key-map (kbd "ж") 'nil)
    (define-key xah-fly-key-map (kbd "л") 'nil)
    (define-key xah-fly-key-map (kbd "а") 'nil)
    (define-key xah-fly-key-map (kbd "б") 'nil)
    (define-key xah-fly-key-map (kbd "и") 'nil)
    (define-key xah-fly-key-map (kbd "е") 'nil)))

(add-hook 'xah-fly-command-mode-activate-hook 'xah-fly-keys-russian-on )

(add-hook 'xah-fly-insert-mode-activate-hook 'xah-fly-keys-russian-off )

and here's a useful add on for Russians.

(defun reverse-input-method (input-method)
  "Build the reverse mapping of single letters from INPUT-METHOD.

A VERY usefull function to use Russian key with modifier keys Ctrl, Alt,
etc and for leader key sequence also. For example Ctrl+ц → Ctrl+w

 2018-10-27 from URL `https://www.alexkorablev.ru/2017/06/10/emacs-got-keys/'"
  (interactive
   (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)

back to Emacs: Xah Fly Keys

Patreon me $5 patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

If you have a question, put $5 at patreon and message me.