![emacs 文本模式 UTF-8 字符](https://linux22.com/image/6102/emacs%20%E6%96%87%E6%9C%AC%E6%A8%A1%E5%BC%8F%20UTF-8%20%E5%AD%97%E7%AC%A6.png)
我无法让 emacs(版本 24.4.1)在文本模式(-nw
启动选项)下直接显示 Unicode 字符。它以转义形式输出它们,例如ä
变为\344
。当我保存文件时,它被编码为ISO-8859
,即使我的系统区域设置是en_US.UTF-8
.
终端本身可以显示Unicode字符外部emacs 的;例如,在 bash 中,ä
变成ä
.它也适用于 emacs X 应用程序(不带-nw
)。
我正在 Arch Linux 3.19.3-3 上使用 gnome-shell 3.16.0-2运行xterm -u8
(使用相同的结果)。uxterm
localectl
输出:
System Locale: LANG=en_US.UTF-8
VC Keymap: sv-latin1
X11 Layout: se
X11 Model: pc104
locale
输出:
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_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_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=
由于唯一的问题区域是终端模式下的 emacs,我猜这就是问题所在。有任何想法吗?
更新:
~/.emacs
:
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ansi-color-names-vector
["#2d3743" "#ff4242" "#74af68" "#dbdb95" "#34cae2" "#008b8b" "#00ede1" "#e1e1e0"])
'(current-language-environment "UTF-8")
'(custom-enabled-themes (quote (manoj-dark)))
'(font-use-system-font t)
'(inhibit-startup-screen t)
'(tool-bar-mode nil))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
我尝试注释掉文件中的每一行,但之后的结果是一样的。
答案1
经过一番摆弄,我发现它与系统相关,而不是与 emacs 相关。显然我的区域设置不知何故搞砸了,正如我们在OP中看到的:
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_ALL to default locale: No such file or directory
我做了什么来解决它:
在 中/etc/locale.gen
,取消注释/添加表示 的行en_US.UTF-8 UTF-8
。确保它是唯一未注释的行。UTF-8
如果您想使用其中之一,它应该可以与任何其他设置一起使用。暴力方法是:
$ sudo bash -c 'echo en_US.UTF-8 UTF-8 > /etc/locale.gen'
之后,我们生成区域设置并将其存储在系统配置中:
$ sudo locale-gen
$ sudo bash -c 'locale > /etc/locale.conf'
您也许可以在不重新启动的情况下更新设置,但我没有找到方法。