Fcitx to input Chinese in Emacs
This should only be used in some case, including emacs and java. Emacs has ahistorical bug, that under en_US.UTF-8 or similar locale, it will never use XIM (Though emacs is a gtk app, it use XIM). The only way to walkaround this is to use LC_CTYPE to fix this.
This was one of most obnoxious problems. With installation of my favorite Sougou(搜狗) IME, I can input Chinese in any application (even in Terminal) with Sougou but emacs. After banging my head on this issue for a long time, following is what I have figured out, and yes, it is working fine now.
Following are some notes while I was doing the debugging. Hope it will help some souls out there.
-
First, testing Emacs without any customization.
12Emacs -Q &works fine with C-~ to switch and input with Fcitx, which means it works fine without any customization of Emacs.
- However,when Emacs started with -q –no-site-file –no-init-file –no-splash any combination, Fctix stops working.
- After some research, what I figured out is that the ‘ -Q’ argument automatically sets inhibit-x-resources to t, in addition to prevent the initialization of site and init files. link1 link2
-
To my surprise, after disable ~./Xresoures, and restart Arch Linux, Fcitx works fine with Emacs. Please note that the Emacs built-in IME still could be evoked with C-\.
I have following code in ./Xresources
12emacs*useXIM: falseIn script file .xprofile, add following lines to support GTK+ and Qt modules Fcitx in Arch Linux.
1234export GTK_IM_MODULE=fcitxexport QT_IM_MODULE=fcitxexport XMODIFIERS=@im=fcitx -
Following are related setting about locale in Arch Linux.
12345678910111213141516171819202122232425262728[taurus /etc] $ cd profile.d/[taurus /etc/profile.d] $ cat locale.sh #this is where Arch generate locale#!/bin/shif [ -z "$LANG" ]; thenif [ -n "$XDG_CONFIG_HOME" ] && [ -r "$XDG_CONFIG_HOME/locale.conf" ]; then. "$XDG_CONFIG_HOME/locale.conf"elif [ -n $HOME ] && [ -r $HOME/.config/locale.conf ]; then. "$HOME/.config/locale.conf"elif [ -r /etc/locale.conf ]; then. /etc/locale.conffifiLANG=en_US.UTF-8#LANG=${LANG:-C}export LANG[ -n "$LC_CTYPE" ] && export LC_CTYPE="zh_CN.UTF-8"[ -n "$LC_NUMERIC" ] && export LC_NUMERIC="en_US.UTF-8"[ -n "$LC_TIME" ] && export LC_TIME="en_US.UTF-8"[ -n "$LC_COLLATE" ] && export LC_COLLATE="en_US.UTF-8"[ -n "$LC_MONETARY" ] && export LC_MONETARY="en_US.UTF-8"[ -n "$LC_MESSAGES" ] && export LC_MESSAGES="en_US.UTF-8"[ -n "$LC_PAPER" ] && export LC_PAPER="en_US.UTF-8"[ -n "$LC_NAME" ] && export LC_NAME="en_US.UTF-8"[ -n "$LC_ADDRESS" ] && export LC_ADDRESS="en_US.UTF-8"[ -n "$LC_TELEPHONE" ] && export LC_TELEPHONE="en_US.UTF-8"[ -n "$LC_MEASUREMENT" ] && export LC_MEASUREMENT="en_US.UTF-8"[ -n "$LC_IDENTIFICATION" ] && export LC_IDENTIFICATION="en_US.UTF-8"
12345678910111213141516taurus /etc/profile.d] $ localeLANG=en_US.UTF-8LC_CTYPE=zh_CN.UTF-8LC_NUMERIC="en_US.UTF-8"LC_TIME="en_US.UTF-8"LC_COLLATE="en_US.UTF-8"LC_MONETARY="en_US.UTF-8"LC_MESSAGES="en_US.UTF-8"LC_PAPER="en_US.UTF-8"LC_NAME="en_US.UTF-8"LC_ADDRESS="en_US.UTF-8"LC_TELEPHONE="en_US.UTF-8"LC_MEASUREMENT="en_US.UTF-8"LC_IDENTIFICATION="en_US.UTF-8"LC_ALL=
123456[taurus /etc/profile.d] $ locale -aCen_US.utf8POSIXzh_CN.utf8
1234~/.config] $ cat locale.confLANG=en_US.UTF-8LC_TYPE=zh.CN.UTF-8 - Hope this will be of help to someone.
Never ending…
fcitx stops working after recent update 09/14/2019. It is refuse to work even when I update to Emacs 26.
- use fcitx-diagnose to check fcitx setting manually removed /usr/lib/gtk-2.0/lib32, fixed error in fcitx-diagnose.
-
fcitx-diagnosis
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336# System Info:1. `uname -a`:Linux sagittarius 5.3.1-arch1-1-ARCH #1 SMP PREEMPT Sat Sep 21 11:33:49 UTC 2019 x86_64 GNU/Linux2. `lsb_release -a`:LSB Version: 1.4Distributor ID: ArchDescription: Arch LinuxRelease: rollingCodename: n/a3. `lsb_release -d`:Description: Arch Linux4. `/etc/lsb-release`:LSB_VERSION=1.4DISTRIB_ID=ArchDISTRIB_RELEASE=rollingDISTRIB_DESCRIPTION="Arch Linux"5. `/etc/os-release`:NAME="Arch Linux"PRETTY_NAME="Arch Linux"ID=archBUILD_ID=rollingANSI_COLOR="0;36"HOME_URL="https://www.archlinux.org/"DOCUMENTATION_URL="https://wiki.archlinux.org/"SUPPORT_URL="https://bbs.archlinux.org/"BUG_REPORT_URL="https://bugs.archlinux.org/"LOGO=archlinux6. Desktop Environment:Desktop environment is `xfce`.7. Bash Version:BASH_VERSION='5.0.9(1)-release'# Environment:1. DISPLAY:DISPLAY=':0.0'2. Keyboard Layout:1. `setxkbmap`:xkb_keymap {xkb_keycodes { include "evdev+aliases(qwerty)" };xkb_types { include "complete" };xkb_compat { include "complete" };xkb_symbols { include "pc+us+inet(evdev)" };xkb_geometry { include "pc(pc105)" };};2. `xprop`:_XKB_RULES_NAMES(STRING) = "evdev", "pc105", "us", "", ""3. Locale:1. All locale:Cen_US.utf8POSIXzh_CN.utf82. Current locale:LANG=en_US.UTF-8LC_CTYPE=zh_CN.UTF-8LC_NUMERIC="en_US.UTF-8"LC_TIME="en_US.UTF-8"LC_COLLATE=en_US.UTF-8LC_MONETARY="en_US.UTF-8"LC_MESSAGES="en_US.UTF-8"LC_PAPER="en_US.UTF-8"LC_NAME="en_US.UTF-8"LC_ADDRESS="en_US.UTF-8"LC_TELEPHONE="en_US.UTF-8"LC_MEASUREMENT="en_US.UTF-8"LC_IDENTIFICATION="en_US.UTF-8"LC_ALL=4. Directories:1. Home:/home/tan2. `${XDG_CONFIG_HOME}`:Environment variable `XDG_CONFIG_HOME` is set to `/home/tan/.config`.Current value of `XDG_CONFIG_HOME` is `~/.config` (`/home/tan/.config`).3. Fcitx Settings Directory:Current fcitx settings directory is `~/.config/fcitx` (`/home/tan/.config/fcitx`).5. Current user:The script is run as tan (1001).# Fcitx State:1. executable:Found fcitx at `/usr/bin/fcitx`.2. version:Fcitx version: `4.2.9.5`3. process:Found 2 fcitx processes:16470 fcitx16479 fcitx-dbus-watc4. `fcitx-remote`:`fcitx-remote` works properly.5. DBus interface:Using `dbus-send` to check dbus.Owner of DBus name `org.fcitx.Fcitx` is `:1.58`.PID of DBus name `org.fcitx.Fcitx` owner is `16470`.# Fcitx Configure UI:1. Config Tool Wrapper:Found fcitx-configtool at `/usr/bin/fcitx-configtool`.2. Config GUI for gtk2:**Config GUI for gtk2 not found.**3. Config GUI for gtk3:Found `fcitx-config-gtk3` at `/usr/bin/fcitx-config-gtk3`.4. Config GUI for kde:# Frontends setup:## Xim:1. `${XMODIFIERS}`:Environment variable XMODIFIERS is set to "@im=fcitx" correctly.Xim Server Name from Environment variable is fcitx.2. XIM_SERVERS on root window:Xim server name is the same with that set in the environment variable.## Qt:1. qt4 - `${QT4_IM_MODULE}`:Environment variable QT_IM_MODULE is set to "fcitx" correctly.2. qt5 - `${QT_IM_MODULE}`:Environment variable QT_IM_MODULE is set to "fcitx" correctly.3. Qt IM module files:Found fcitx im module for Qt5: `/usr/lib/qt/plugins/platforminputcontexts/libfcitxplatforminputcontextplugin.so`.Found fcitx qt module: `/usr/lib/fcitx/qt/libfcitx-quickphrase-editor5.so`.Found fcitx im module for Qt4: `/usr/lib/qt4/plugins/inputmethods/qtim-fcitx.so`.## Gtk:1. gtk - `${GTK_IM_MODULE}`:Environment variable GTK_IM_MODULE is set to "fcitx" correctly.2. `gtk-query-immodules`:1. gtk 2:Found `gtk-query-immodules` for gtk `2.24.32` at `/usr/bin/gtk-query-immodules-2.0`.Version Line:# Created by /usr/bin/gtk-query-immodules-2.0 from gtk+-2.24.32Found fcitx im modules for gtk `2.24.32`."/usr/lib/gtk-2.0/2.10.0/immodules/im-fcitx.so""fcitx" "Fcitx (Flexible Input Method Framework)" "fcitx" "/usr/share/locale" "ja:ko:zh:*"2. gtk 3:Found `gtk-query-immodules` for gtk `3.24.10` at `/usr/bin/gtk-query-immodules-3.0`.Version Line:# Created by /usr/bin/gtk-query-immodules-3.0 from gtk+-3.24.10Found fcitx im modules for gtk `3.24.10`."/usr/lib/gtk-3.0/3.0.0/immodules/im-fcitx.so""fcitx" "Fcitx (Flexible Input Method Framework)" "fcitx" "/usr/share/locale" "ja:ko:zh:*"3. Gtk IM module cache:1. gtk 2:Found immodules cache for gtk `2.24.32` at `/usr/lib/gtk-2.0/2.10.0/immodules.cache`.Version Line:# Created by /usr/bin/gtk-query-immodules-2.0 from gtk+-2.24.32Found fcitx im modules for gtk `2.24.32`."/usr/lib/gtk-2.0/2.10.0/immodules/im-fcitx.so""fcitx" "Fcitx (Flexible Input Method Framework)" "fcitx" "/usr/share/locale" "ja:ko:zh:*"2. gtk 3:Found immodules cache for gtk `3.24.10` at `/usr/lib/gtk-3.0/3.0.0/immodules.cache`.Version Line:# Created by /usr/bin/gtk-query-immodules-3.0 from gtk+-3.24.10Found fcitx im modules for gtk `3.24.10`."/usr/lib/gtk-3.0/3.0.0/immodules/im-fcitx.so""fcitx" "Fcitx (Flexible Input Method Framework)" "fcitx" "/usr/share/locale" "ja:ko:zh:*"4. Gtk IM module files:1. gtk 2:All found Gtk 2 immodule files exist.2. gtk 3:All found Gtk 3 immodule files exist.# Configuration:## Fcitx Addons:1. Addon Config Dir:Found fcitx addon config directory: `/usr/share/fcitx/addon`.2. Addon List:1. Found 32 enabled addons:fcitx-autoengfcitx-autoeng-ngfcitx-chttransfcitx-classic-uifcitx-clipboardfcitx-dbusfcitx-freedesktop-notifyfcitx-fullwidth-charfcitx-fullwidth-char-enhancefcitx-googlepinyinfcitx-imselectorfcitx-ipcfcitx-ipcportalfcitx-keyboardfcitx-kimpanel-uifcitx-notificationitemfcitx-pinyinfcitx-pinyin-enhancefcitx-puncfcitx-punc-ngfcitx-quickphrasefcitx-remotefcitx-sogoucloudpinyinfcitx-sogoupinyinfcitx-spellfcitx-tablefcitx-unicodefcitx-vkfcitx-x11fcitx-ximfcitx-xkbfcitx-xkbdbus2. Found 1 disabled addons:fcitx-qw3. Addon Libraries:All libraries for all addons are found.4. User Interface:Found 2 enabled user interface addons:fcitx-classic-uifcitx-kimpanel-uiKimpanel process:16301 sogou-qimpanel -session 250992e7d-317d-4153-a51a-acb704b5ea6d_1569716362_135860## Input Methods:1. Found 4 enabled input methods:fcitx-keyboard-uspinyingooglepinyinsogoupinyin2. Default input methods:You have a keyboard input method "fcitx-keyboard-us" correctly added as your default input method.# Log:1. `date`:Sat 28 Sep 2019 06:51:07 PM PDT2. `~/.config/fcitx/log/`:total 4-rw-r--r-- 1 tan users 44 Sep 27 20:20 crash.log3. `~/.config/fcitx/log/crash.log`:fcitx: BadWindow (invalid Window parameter) - xlsfonts |grep r-normal–14 check fonts
-
start Emacs with presetting
12LC_CTYPE=zh_CN.UTF-8 XMODIFIERS=@im=xim emacs - played with ./xprofile and .pam_environment
- daemon and client mode with Emacs 26 added Environment variables. Arch and Arch
- regenerate the locale
- fontconfig see Arch Fonts
- http://t.hengwei.me/post/Fcitx-and-Fonts-setting.html
-
font-path in xorg Emacs 24.3 with FCITX input methods{Resolved in 14.2} – Page 2 – Salix OS Emacs GUI下不能输入中文 – Emacs-general – Emacs China
新建 /etc/X11/xorg.conf.d/fonts.conf 写入
12345Section "Files"FontPath "/usr/share/fonts/misc"FontPath "你的/字体/路径""EndSection记得在你的字体目录下
1234mkfontdirmkfontscalefc-cache -v - How to install Chinese fonts and input method in Arch Linux
MAR
About the Author:
Beyond 8 hours - Computer, Sports, Family...