org文件粘贴和日期出现部分乱码

*** 日期乱码**

C c C x . 出现日期星期部分为乱码 image

** 粘贴乱码**

复制外部文字粘贴出现乱码 image

在 emacs 里 M-x eshell, 在里面运行 locale 命令看看,如果没看到 UTF-8 字样,在 emacs 配置文件里加上:

(setenv "LANG" "zh_CN.UTF-8")

如果没解决,再来个更大力的:

(setenv "LC_ALL" "zh_CN.UTF-8")

话说你啥操作系统,啥 Emacs 版本,啥 Emacs 十全大补包,啥字体全都没讲😄️

1赞

:laughing:win系统找不到命令

Welcome to the Emacs shell

e:/org λ locale locale: command not found

等用 windows 的同学帮忙了。 你提供下具体的 Emacs 版本,装了啥插件,配置里有啥具体的编码、字体相关设置, Windows 系统语言是啥?

话说 Emacs 居然在 Windows 上连基本的字体不乱码都没搞定???

这种情况是编码没设置好,论坛有解决方案。

我是操作系统直接用英文格式日期,少折腾

我之前碰到过在其他程序复制,emacs粘贴会乱码(windows下),因为 windows 是 gbk,而我当时设置了

(set-selection-coding-system 'utf-8)

这样会按照utf-8的编码去解码gbk的,就会乱码,然后我现在的配置是:

(set-selection-coding-system
   (if (eq system-type 'windows-nt)
       'gbk
     'utf-8))

如果你配置和上面的一样,你可以试着改成下面得配置

应该啥也不用设置它就工作,如果不工作,应该去向 emacs 官方报 bug。

btw,据说 win下默认是 utf-16-le,不要用gbk了,至少也用我朝的unicode 编码标准gb18030。

上虚拟机简体中文 win 10 + emacs 官网下载的 27.1 installer 验证,默认啥也没改,从 emacs 和记事本之间复制文本,包括表情符号都工作,没有乱码,只是 emacs 默认字体配置有问题,有的显示成麻将符了。

windows 记事本保存文件默认用 UTF-8 编码。

简体中文 windows 下 emacs,默认语言环境为 Chinese-GBK,默认字体 Courier New。

C-h C:

Coding system for saving this buffer:
  Not set locally, use the default.
Default coding system (for new files):
  c -- chinese-gbk-dos (alias: gbk-dos cp936-dos windows-936-dos)

Coding system for keyboard input:
  c -- chinese-gbk-unix (alias: gbk-unix cp936-unix windows-936-unix)

Coding system for terminal output:
  c -- cp936 (alias of chinese-gbk)

Coding system for inter-client cut and paste:
  U -- utf-16le-dos

Defaults for subprocess I/O:
  decoding: - -- undecided-dos (alias: dos)

  encoding: - -- undecided-unix (alias: unix)


Priority order for recognizing coding systems when reading files:
  1. chinese-gbk (alias: gbk cp936 windows-936)
  2. iso-2022-cn (alias: chinese-iso-7bit)
  3. chinese-big5 (alias: big5 cn-big5 cp950)
  4. chinese-iso-8bit (alias: cn-gb-2312 euc-china euc-cn cn-gb gb2312)
  5. utf-8 (alias: mule-utf-8 cp65001)
  6. iso-2022-7bit 
  7. iso-2022-8bit-ss2 
  8. emacs-mule 
  9. raw-text 
  10. iso-2022-jp (alias: junet)
  11. in-is13194-devanagari (alias: devanagari)
  12. utf-8-auto 
  13. utf-8-with-signature 
  14. utf-16 
  15. utf-16be-with-signature (alias: utf-16-be)
  16. utf-16le-with-signature (alias: utf-16-le)
  17. utf-16be 
  18. utf-16le 
  19. japanese-shift-jis (alias: shift_jis sjis)
  20. undecided

Emacs 大概是为了向后兼容,没有默认用语言环境 Chinese-GB18030。

Coding system for saving this buffer:
  Not set locally, use the default.
Default coding system (for new files):
  c -- chinese-gb18030-dos (alias: gb18030-dos)

Coding system for keyboard input:
  c -- chinese-gbk-unix (alias: gbk-unix cp936-unix windows-936-unix)

Coding system for terminal output:
  c -- cp936 (alias of chinese-gbk)

Coding system for inter-client cut and paste:
  U -- utf-16le-dos

Defaults for subprocess I/O:
  decoding: c -- chinese-gb18030-dos (alias: gb18030-dos)

  encoding: c -- chinese-gb18030-unix (alias: gb18030-unix)


Priority order for recognizing coding systems when reading files:
  1. chinese-gb18030 (alias: gb18030)
  2. iso-2022-cn (alias: chinese-iso-7bit)
  3. chinese-big5 (alias: big5 cn-big5 cp950)
  4. chinese-iso-8bit (alias: cn-gb-2312 euc-china euc-cn cn-gb gb2312)
  5. utf-8 (alias: mule-utf-8 cp65001)
  6. iso-2022-7bit 
  7. iso-2022-8bit-ss2 
  8. emacs-mule 
  9. raw-text 
  10. iso-2022-jp (alias: junet)
  11. in-is13194-devanagari (alias: devanagari)
  12. utf-8-auto 
  13. utf-8-with-signature 
  14. utf-16 
  15. utf-16be-with-signature (alias: utf-16-be)
  16. utf-16le-with-signature (alias: utf-16-le)
  17. utf-16be 
  18. utf-16le 
  19. japanese-shift-jis (alias: shift_jis sjis)
  20. undecided

切换到语言环境 UTF-8,可以看到 Emacs 在简体中文 windows 上对 keyboard 和 terminal 总是使用 GBK,对剪贴板总是使用 UTF-16LE,而且总是开箱即用的,不需要额外配置什么。

Coding system for saving this buffer:
  Not set locally, use the default.
Default coding system (for new files):
  U -- utf-8-dos (alias: mule-utf-8-dos cp65001-dos)

Coding system for keyboard input:
  c -- chinese-gbk-unix (alias: gbk-unix cp936-unix windows-936-unix)

Coding system for terminal output:
  c -- cp936 (alias of chinese-gbk)

Coding system for inter-client cut and paste:
  U -- utf-16le-dos

Defaults for subprocess I/O:
  decoding: U -- utf-8-dos (alias: mule-utf-8-dos cp65001-dos)

  encoding: U -- utf-8-unix (alias: mule-utf-8-unix cp65001-unix)


Priority order for recognizing coding systems when reading files:
  1. utf-8 (alias: mule-utf-8 cp65001)
  2. iso-2022-7bit 
  3. iso-latin-1 (alias: iso-8859-1 latin-1)
  4. iso-2022-7bit-lock (alias: iso-2022-int-1)
  5. iso-2022-8bit-ss2 
  6. emacs-mule 
  7. raw-text 
  8. chinese-big5 (alias: big5 cn-big5 cp950)
  9. chinese-iso-8bit (alias: cn-gb-2312 euc-china euc-cn cn-gb gb2312)
  10. iso-2022-jp (alias: junet)
  11. in-is13194-devanagari (alias: devanagari)
  12. utf-8-auto 
  13. utf-8-with-signature 
  14. utf-16 
  15. utf-16be-with-signature (alias: utf-16-be)
  16. utf-16le-with-signature (alias: utf-16-le)
  17. utf-16be 
  18. utf-16le 
  19. japanese-shift-jis (alias: shift_jis sjis)
  20. undecided

我之前也有类似的问题,从坛友手里抄了这个配置然后自己又修改了一些设置就好了。原贴在这,根原帖不一样的地方你可以两种都试下。

;;use unicode everywhere
(when (fboundp 'set-charset-priority)
  (set-charset-priority 'unicode))
(prefer-coding-system 'utf-8-unix)
(modify-coding-system-alist 'process "*" 'utf-8-unix)
(set-buffer-file-coding-system 'utf-8-unix)
(set-file-name-coding-system 'utf-8-unix)
(set-default-coding-systems 'utf-8-unix)
(set-keyboard-coding-system 'utf-8-unix)
(set-terminal-coding-system 'utf-8-unix)
(set-language-environment "UTF-8")
(setq locale-coding-system 'utf-8-unix)
(setq default-process-coding-system '(utf-8-unix . utf-8-unix))

;;windows没有启用unicode时,中文语言是gbk编码gb18030会导致有些中文字符找不到字体
(when (eq system-type 'windows-nt)
  (setq locale-coding-system 'chinese-gbk))

;;The clipboard on windows dose not play well with utf8
(unless (eq system-type 'windows-nt)
  (set-clipboard-coding-system 'utf-8)
  (set-selection-coding-system 'utf-8))

;; 英文日期,会影响日期格式
(setq system-time-locale "C")
1赞