Last active
March 7, 2016 05:24
-
-
Save mikeonly/3d405493aabc7ce8aa47 to your computer and use it in GitHub Desktop.
Code from SO for international layout support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Commentary: | |
;; Code from SO for international layout support. Defines key-translation map automatically. | |
;; Source: http://stackoverflow.com/a/10872534/3885799 | |
(loop | |
for from across "йцукенгшщзхъфывапролджэячсмитьбюЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖ\ЭЯЧСМИТЬБЮ№" | |
for to across "qwertyuiop[]asdfghjkl;'zxcvbnm,.QWERTYUIOP{}ASDFGHJKL:\"ZXCVBNM<>#" | |
do | |
(eval `(define-key key-translation-map (kbd ,(concat "C-" (string from))) (kbd ,(concat "C-" (string to))))) | |
(eval `(define-key key-translation-map (kbd ,(concat "M-" (string from))) (kbd ,(concat "M-" (string to)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Commentary: | |
;; Code from SO for international layout support. Have no idea what it does. | |
;; Source: http://stackoverflow.com/a/10890752/3885799 | |
;; (translate-keystrokes-ru->en) | |
;; (add-hook 'text-mode-hook | |
;; (lambda () (literal-insert-mode 1))) | |
;; | |
;; Only buffers with literal-insert-mode active will be sensitive to the | |
;; environment language. Prefixed keybindings will still be usable. | |
(defun translate-keystrokes-ru->en () | |
"Make emacs output english characters, regardless whether | |
the OS keyboard is english or russian" | |
(flet ((make-key-stroke (prefix char) | |
(eval `(kbd ,(if (and (string-match "^C-" prefix) | |
(string-match "[A-Z]" (string char))) | |
(concat "S-" prefix (string (downcase char))) | |
(concat prefix (string char))))))) | |
(let ((case-fold-search nil) | |
(keys-pairs (mapcar* 'cons | |
"йцукенгшщзхъфывапролджэячсмитьбюЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖ\ЭЯЧСМИТЬБЮ№" | |
"qwertyuiop[]asdfghjkl;'zxcvbnm,.QWERTYUIOP{}ASDFGHJKL:\"ZXCVBNM<>#")) | |
(prefixes '("" "s-" "M-" "M-s-" | |
"C-" "C-s-" "C-M-" "C-M-s-"))) | |
(mapc (lambda (prefix) | |
(mapc (lambda (pair) | |
(define-key key-translation-map | |
(make-key-stroke prefix (car pair)) | |
(make-key-stroke prefix (cdr pair)))) | |
keys-pairs)) | |
prefixes)))) | |
(defun literal-insert () | |
(interactive) | |
(insert-char last-input-event 1)) | |
(define-minor-mode literal-insert-mode | |
"Make emacs output characters corresponging to the OS keyboard, | |
ignoring the key-translation-map" | |
:keymap (let ((new-map (make-sparse-keymap)) | |
(english-chars "qwertyuiop[]asdfghjkl;'zxcvbnm,.QWERTYUIOP{}ASDFGHJKL:\"ZXCVBNM<>#")) | |
(mapc (lambda (char) | |
(define-key new-map (string char) | |
'literal-insert)) | |
english-chars) | |
new-map)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment