Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2015
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. (translate-keystrokes-ru->en)
  2. (add-hook 'evil-insert-state-minor-mode
  3. (lambda () (literal-insert-mode 1)))
  4.  
  5. ;; Only buffers with literal-insert-mode active will be sensitive to the
  6. ;; environment language. Prefixed keybindings will still be usable.
  7.  
  8. (defun translate-keystrokes-ru->en ()
  9. "Make emacs output english characters, regardless whether
  10. the OS keyboard is english or russian"
  11. (flet ((make-key-stroke (prefix char)
  12. (eval `(kbd ,(if (and (string-match "^C-" prefix)
  13. (string-match "[A-Z]" (string char)))
  14. (concat "S-" prefix (string (downcase char)))
  15. (concat prefix (string char)))))))
  16. (let ((case-fold-search nil)
  17. (keys-pairs (mapcar* 'cons
  18. "йцукенгшщзхъфывапролджэячсмитьбюЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖ\ЭЯЧСМИТЬБЮ№"
  19. "qwertyuiop[]asdfghjkl;'zxcvbnm,.QWERTYUIOP{}ASDFGHJKL:\"ZXCVBNM<>#"))
  20. (prefixes '("" "s-" "M-" "M-s-"
  21. "C-" "C-s-" "C-M-" "C-M-s-")))
  22. (mapc (lambda (prefix)
  23. (mapc (lambda (pair)
  24. (define-key key-translation-map
  25. (make-key-stroke prefix (car pair))
  26. (make-key-stroke prefix (cdr pair))))
  27. keys-pairs))
  28. prefixes))))
  29.  
  30. (defun literal-insert ()
  31. (interactive)
  32. (insert-char last-input-event 1))
  33.  
  34. (define-minor-mode literal-insert-mode
  35. "Make emacs output characters corresponging to the OS keyboard,
  36. ignoring the key-translation-map"
  37. :keymap (let ((new-map (make-sparse-keymap))
  38. (english-chars "qwertyuiop[]asdfghjkl;'zxcvbnm,.QWERTYUIOP{}ASDFGHJKL:\"ZXCVBNM<>#"))
  39. (mapc (lambda (char)
  40. (define-key new-map (string char)
  41. 'literal-insert))
  42. english-chars)
  43. new-map))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement