reddit / emacs

Using different input methods for different `evil` modes

Ok-Look6156 · 2022-12-15 00:39
Hi guys! I want to use different input methods for different evil modes in emacs. To be more specific, I use colemak for English input (and basically everything else inside emacs), but qwerty for Chinese input. As I've been exploring, I found several possible ways of implementing this: letting fcitx handle the input methods and interface with it using \`fcitx.el\`, or let emacs handle everything and use \`pyim\` for Chinese input. I feel like both methods are bad. For fcitx, I'm not sure if the package could change fcitx state as buffers, major/minor modes change. Even it is possible, I suspect that it will be a huge hacking work (I'm a noob with elisp). For the native input methods, I'm not sure how to make the system input methods ignore emacs. Also, letting emacs handle its own inputs seems... inelegant. Do you have any good solutions for inputting Chinese in emacs, with colemak as the default English input? Any help would be appreciated! ​ PS. I fixed it (kind of)! I messed around a little with rime, fcitx and automatic input method changing magically worked. I didn't install rime for emacs tho, just \`librime\`. I also configured the environment variables according to the archwiki. Maybe it's meant to work out of the box? Now the behavior is exactly what I wanted: fcitx automatically swiches between chinese pinyin and colemak accordingly. tbh I'm not entirely sure why that works...
Fastest_draw · 2022-12-15 04:37
Vim solves this using the option `langmap`. Maybe there is something out there that you can find using this keyword?
iwaka · 2022-12-15 09:40
I use fcitx5 with Emacs to input English (Dvorak) and Chinese (qwerty Cangjie layout). I configure everything system-wide, Emacs does not control my inputs. I do not use fcitx.el or any input methods in Emacs. You can configure this setup inside fcitx (I'm assuming you know how). The trick is to make Emacs let you switch fcitx layouts. This used to be a huge pain in the ass, but is fixed in the pure GTK Emacs port, at least for me. If you want to try Emacs 29, chances are everything will work out of the box. (Otherwise you may need to start Emacs with additional environment variables set, which I always found bothersome.)
Ok-Look6156 · 2022-12-15 10:18
Do you mean that you don't manually change the input method in and out of insert mode and the input method in fcitx change automatically? Or is it that you press \`shift\` every time you press \`esc\` and \`i\`?
Ok-Look6156 · 2022-12-15 10:19
Cool! I'll look into it, thx!
iwaka · 2022-12-15 13:13
Oh, I still change the input manually. I haven't tried to have it change automatically on switching between evil modes. I suppose you could add an advice to `evil-normal-mode`, but then you'd need it to call fcitx, and I haven't tried doing that programmatically.
redguardtoo · 2022-12-16 00:17
pyim plus this setup https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-chinese.el#L8 (see `my-toggle-input-method`). This is easiest setup and works in all environments. For more advanced setup, you can search articles on https://emacs-china.org/ . I think right now emacs-rime is hot topic.
Ok-Look6156 · 2022-12-17 03:55
Thx for the help! I've been neglecting emacs-china as a source of information, where I should definitely frequent more. I read your Zhihu posts when I started learning emacs btw, and it was quite helpful! Just wanna say thanks for those.