我应该在Emacs中使用哪种编码系统?当我将中文单词复制到emacs时,框架会出现无序代码。

时间:2013-12-09 15:42:27

标签: emacs character-encoding coding-style chinese-locale

我使用的是中文Ubuntu,而emacs的版本是23.当我将中文单词复制到Emacs时,会出现无序代码和数字编号。当我使用C-c C-s保存文件时,emacs会提醒我选择一个编码系统如下:

These default coding systems were tried to encode text
in the buffer `12-07.org':
  (chinese-iso-8bit-unix (229 . 4194279) (230 . 4194203) (236
  . 4194281) (237 . 4194179) (239 . 4194238) (240 . 4194184) (241
  . 4194279) (242 . 4194182) (243 . 4194207) (244 . 4194278) (245
  . 4194178))
However, each of them encountered characters it couldn't encode:
  chinese-iso-8bit-unix cannot encode these: ç  é  ¾  ç   æ ...

Click on a character (or switch to this window by `C-x o'
and select the characters by RET) to jump to the place it appears,
where `C-u C-x =' will give information about it.

Select one of the safe coding systems listed below,
or cancel the writing with C-g and edit the buffer
   to remove or modify the problematic characters,
or specify any other coding system (and risk losing
   the problematic characters).

  raw-text emacs-mule no-conversion

如何设置.emacs文件来解决问题?现在我的.emacs文件设置如下:

;; Font setting
;; 设置两个字体变量,一个中文的一个英文的
;; 之所以两个字体大小是因为有的中文和英文相同字号的显示大小不一样,需要手动调整一下。
(setq cjk-font-size 18)
(setq ansi-font-size 18)

(prefer-coding-system 'utf-16-le)

;; EXPERIMENTAL: Set language environment
;;(setq current-language-environment 'latin-1)
;;(setenv 'latin-1)
;;(setenv LANG en_US.8859-1)

(set-language-environment "Latin-1")
(set-keyboard-coding-system 'latin-1)
(set-terminal-coding-system 'latin-1) 

(set-fontset-font "fontset-default" 'gb18030' ("STHeiti" . "unicode-bmp"))
;;(set-language-environment "Chinese-GB")
;;(set-keyboard-coding-system 'chinese-iso-8bit)

(global-set-key [?\S- ] 'set-mark-command)

;;设置默认字体
;;(set-default-font " 'gb18030')
;;(setq default-frame-alist "STHeiti")
;;(setq default-frame-alist (font . "微软雅黑Monaco 12"))

;; 恢复成默认大小17号
(defun default-font-size()
  "default font size"
  (interactive)
  (setq cjk-font-size 17)
  (setq ansi-font-size 17)
  (message "cjk-size:%d pt, ansi-size:%d pt" cjk-font-size ansi-font-size)
  (set-font)
  (sit-for .5))

1 个答案:

答案 0 :(得分:0)

问题是由(set-language-environment "Latin-1")

引起的

您应该单独保留语言环境,以便与系统的语言环境保持同步。 此外,只有在绝对必要的情况下才能设置键盘和终端编码系统,如果您主要从具有不同于本地语言环境的系统远程使用Emacs,则可能是这种情况,但如果您仅在本地使用Emacs,则可能不需要