Emacs

emacs 文本模式 UTF-8 字元

  • April 22, 2015

我無法在文本模式(-nw啟動選項)下讓 emacs(版本 24.4.1)直接顯示 Unicode 字元。它以轉義形式輸出它們,例如ä變成\344. 當我保存文件時,它被編碼為ISO-8859,即使我的系統語言環境是en_US.UTF-8.

終端本身可以在emacs*之外顯示Unicode字元;*例如,在 bash 中,ä變為ä. 它也適用於 emacs X 應用程序(沒有-nw)。

我正在使用gnome-shell 3.16.0-2 在 Arch Linux 3.19.3-3 上執行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.
)

我嘗試註釋掉文件中的每一行,但之後的結果是一樣的。

經過一番擺弄,我發現它是系統相關的,而不是 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'

您也許可以在不重新啟動的情況下更新設置,但我沒有找到辦法。

引用自:https://unix.stackexchange.com/questions/195887