Emacs, Linux and International Keyboard Layouts

Emacs, Linux and international keyboard layouts

You can set input method (kudos go to kindahero) by typing

M-x set-input-method RET cyrillic-yawerty RET

or

M-x set-input-method RET cyrillic-jcuken RET

To store it permanently, add

(setq default-input-method "cyrillic-yawerty")

to ~/.emacs config (and use C-\ to switch between keyboard layouts).

different keyboard layout key bindings in emacs

If the two layouts use completely different characters, then you can simply let Emacs try "the other character". E.g. if one key is b in US layout but и in the other layout, you can use:

(define-key function-key-map [?и]       [?b])
(define-key function-key-map [?\C-и] [?\C-b])
(define-key function-key-map [?\M-и] [?\M-b])
(define-key function-key-map [?\M-\C-и] [?\M-\C-b])

OTOH if the two layout end up swapping some characters, Emacs would really need to know which layout is active in order to know whether or not to remap the key. I don't know enough about keyboard handling to know how to let Emacs tell you which layout is in use currently.

How to make emacs default keys works in non english keyboard layout

When working with Emacs, always use the English layout on the system level, but switch to any Emacs' input-method you like. That way, all the keyboard shortcuts still work, but when typing, you insert characters of a different layout.

Make Emacs ignore system keyboard layout

Can you tell what keyboard layouts you use in your OS and what input methods you use in Emacs? Currently there's not enough information in your post. My problem was, for example, that i used Colemak and Russian-typewriter as OS layouts and Russian-typewriter as a secondary Emacs input method. Combination Colemak(OS)-Russian(Emacs) messed up my input, because Emacs' input method is the mapping of English character, received from OS, to some Russian character, and all input methods in Emacs are based on mapping from QWERTY. For example, what should have been "йцукен" was printed as "йцазпо". I solved it by running the following code:

(require 'quail)

(quail-define-package
"colemak-russian" "Russian" "ru" nil
"Russian-typewriter keyboard layout assuming that your default
keyboard layout is Colemak"
nil t t t t nil nil nil nil nil t)

(quail-define-rules
("1" ?№) ("2" ?-) ("3" ?/) ("4" ?\") ("5" ?:) ("6" ?,) ("7" ?.) ("8" ?_) ("9" ??)
("0" ?%) ("-" ?!) ("=" ?\;) ("q" ?й) ("w" ?ц) ("f" ?у) ("p" ?к) ("g" ?е) ("j" ?н)("l" ?г)
("u" ?ш) ("y" ?щ) (";" ?з) ("[" ?х) ("]" ?ъ) ("\\" ?\)) ("a" ?ф) ("r" ?ы) ("s" ?в)
("t" ?а) ("d" ?п) ("h" ?р) ("n" ?о) ("e" ?л) ("i" ?д) ("o" ?ж) ("'" ?э) ("z" ?я) ("x" ?ч)
("c" ?с) ("v" ?м) ("b" ?и) ("k" ?т) ("m" ?ь) ("," ?б) ("." ?ю) ("/" ?ё) ("~" ?+) ("!" ?1)
("@" ?2) ("#" ?3) ("$" ?4) ("%" ?5) ("^" ?6) ("&" ?7) ("*" ?8) ("\(" ?9) ("\)" ?0) ("_" ?=)
("+" ?\\) ("Q" ?Й) ("W" ?Ц) ("F" ?У) ("P" ?К) ("G" ?Е) ("J" ?Н) ("L" ?Г) ("U" ?Ш) ("Y" ?Щ)
(":" ?З) ("{" ?Х) ("}" ?Ъ) ("|"?\() ("A" ?Ф) ("R" ?Ы) ("S" ?В) ("T" ?А) ("D" ?П) ("H" ?Р)
("N" ?О) ("E" ?Л) ("I" ?Д) ("O" ?Ж) ("\"" ?Э) ("Z" ?Я) ("V" ?Ч) ("X" ?С) ("C" ?М) ("B" ?И)
("K" ?Т) ("M"?Ь) ("<" ?Б) (">" ?Ю) ("?" ?Ё))

and then used colemak-russian instead of russian-typewriter. You can change associated pairs with the corresponding to your layouts.

EDIT: Of course, this is not the most correct solution. As Maksim noted, characters common to both languages are translated even when shouldn't. For example, i set system layout to Colemak and Emacs input method to "colemak-russian" - then i can't use commas, which become "б".

To make Emacs ignore system layout, you can integrate it with third-party software like xxkb, SCIM or IBus. As you speak Russian, you may try this tutorial.

I personally use a hacky workaround to translate Russian characters inside key combos and ignore Emacs input methods altogether.

Arch Linux installation keyboard layout de-latin1 in /etc/vconsole.conf

You can list all available layouts via localectl list-keymaps. If you wish to have a standard QWERTY layout, you might want to use KEYMAP=us

Have a look at this Wiki page for more information.



Related Topics



Leave a reply



Submit