manjaro下spacemacs中无法使用ibus输入中文 该怎么办.



桌面: KDE.

目前已知neovim/chrome/chromium等环境下都能使用ibus-rime输入中文, emacs中能跳出输入的候选栏(更新: 现在候选栏也没有了, 不知道是不是因为改了哪里的locale了), 但是按下SPC满怀期待的希望看到汉字出现在emacs, 始终不能如愿, 光标依旧停留在原处, . 终端的话只有neovim下能输入中文, 其他情景下不能, 包括non-neovimvim下.

这篇帖子(Emacs GUI下不能输入中文)是将fcitx的, 目前spacemacs有chinese这个layer里面对fcitx做了适配, ibus的话这里有一个, 我把它做成了layer后, 状况依然没有变化.

具体做法我是将.spacemacs改名为init.el, 并且放置在.spacemacs.d这个新建的文件夹中, 并且在这个文件夹中新建 ibus 这个文件夹, 如图所示:


(defun dotspacemacs/user-config ()
  "Configuration function for user code.
This function is called at the very end of Spacemacs initialization after
layers configuration.
This is the place where most of your configurations should be done. Unless it is
explicitly specified that a variable should be set before a package is loaded,
you should place your code here."
  (require 'ibus)
  (add-hook 'after-init-hook 'ibus-mode-on)


(load-file "~/.spacemacs.d/layers/ibus/local/ibus.el")
(load-file "~/.spacemacs.d/layers/ibus/local/ibus-el-agent")

packages.el全文如下(我没有作改动, 是自动生成的):

;;; packages.el --- ibus layer packages file for Spacemacs.
;; Copyright (c) 2012-2017 Sylvain Benner & Contributors
;; Author: czxyl <czxyl@archlinux>
;; URL:
;; This file is not part of GNU Emacs.
;;; License: GPLv3

;;; Commentary:

;; See the Spacemacs documentation and FAQs for instructions on how to implement
;; a new layer:
;;   SPC h SPC layers RET
;; Briefly, each package to be installed or configured by this layer should be
;; added to `ibus-packages'. Then, for each package PACKAGE:
;; - If PACKAGE is not referenced by any other Spacemacs layer, define a
;;   function `ibus/init-PACKAGE' to load and initialize the package.

;; - Otherwise, PACKAGE is already referenced by another Spacemacs layer, so
;;   define the functions `ibus/pre-init-PACKAGE' and/or
;;   `ibus/post-init-PACKAGE' to customize the package as it is loaded.

;;; Code:

(defconst ibus-packages
  "The list of Lisp packages required by the ibus layer.

Each entry is either:

1. A symbol, which is interpreted as a package to be installed, or

2. A list of the form (PACKAGE KEYS...), where PACKAGE is the
    name of the package to be installed or loaded, and KEYS are
    any number of keyword-value-pairs.

    The following keys are accepted:

    - :excluded (t or nil): Prevent the package from being loaded
      if value is non-nil

    - :location: Specify a custom installation location.
      The following values are legal:

      - The symbol `elpa' (default) means PACKAGE will be
        installed using the Emacs package manager.

      - The symbol `local' directs Spacemacs to load the file at

      - A list beginning with the symbol `recipe' is a melpa
        recipe.  See:")

;;; packages.el ends here

我知道上述做法是错的, 因为spacemacs启动出错了:

emacs --debug-init信息如下:


➜  ~ localectl  
   System Locale: LANG=en_US.UTF-8
       VC Keymap: n/a
      X11 Layout: cn
       X11 Model: pc101
➜  ~ locale -a
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_COLLATE to default locale: No such file or directory
➜  ~ python2 -c "import sys; print sys.getfilesystemencoding()"
➜  ~ grep -v '#' /etc/locale.gen
en_US.UTF-8 UTF-8
de_DE ISO-8859-1
en_US.UTF-8 UTF-8  
➜  ~ env | grep LANG
➜  ~ 

不知道该该如何解决了, 希望大家点拨下,

更新: Emacs GUI下不能输入中文 这一楼能解决我的问题


特地安装了ibus试了下,可以输入中文,不需要改emacs相关文件。其根本原因就是你环境变量设置不对。 把这六行写到.xinitrc或.xprofile:

export GTK_IM_MODULE=ibus

export QT_IM_MODULE=ibus

export XMODIFIERS=@im=ibus

export LANG=zh_CN.UTF-8

export LANGUAGE=zh_CN:en_US

export LC_CTYPE=en_US.UTF-8



我个人觉得也不一定非要用 emacs 外的中文输入法来解决问题吧。也可以用 emacs 的内置中文输入法啊。如果觉得 emacs 的内置输入法不够给力的话,推荐一个这个。 pyim 其实已经集成在 spacemacs 的 chinese layer 里面了。


谢谢:drooling_face: 这个方法好呀, 可以解决, 不过每次开机要等个几分钟才能在emacs中输入中文.


可能是我遇到的稍有好感的几个 Linux 发行版,用的全都是 fcitx。

我自己折腾 manjaro 时,完全没想起来 ibus。