<2023-03-06 周一>
为什么(windows
平台)在doomemacs
中粘贴外部进程的中文会显示乱码(二)
在上一篇“为什么(windows
平台)在doomemacs
中粘贴外部进程的中文会显示乱码(一)”讲过,但是没讲清楚,今天得空又研究了一下。
通过C-h f
查看函数帮助,函数set-clipboard-coding-system
其实就是函数set-selection-coding-system
的别名,所以查看set-selection-coding-system
源码:
(defun set-selection-coding-system (coding-system)
"Make CODING-SYSTEM used for communicating with other X clients.
When sending or receiving text via cut_buffer, selection, and clipboard,
the text is encoded or decoded by CODING-SYSTEM."
(interactive "zCoding system for X selection: ")
(check-coding-system coding-system)
(setq selection-coding-system coding-system))
发现它最终会设置selection-coding-system
变量,当然你也可以通过C-h v
查看变量的帮助,这里就不看了。
因为我跟我的prelude
对比,发现在prelude
上粘贴复制的外部进程的中文是可以正常显示的,那到底是doomemacs
还是prelude
做了什么特殊操作?在doomemacs
整个目录中搜索字符串selection-coding-system
发现了这里有设置的操作:
;; doomemacs/lisp/doom-start.el
;; ...And the clipboard on Windows could be in a wider encoding (UTF-16), so
;; leave Emacs to its own devices.
(eval-when! IS-WINDOWS
(setq selection-coding-system 'utf-8))
而prelude
里没有设置这个变量的值,所以是doomemacs
里做了这么一个操作导致windows
下粘贴出乱码。