看了代码实现,确实也加了 encoding 的转换,但是还是乱码:
(defun counsel-locate-cmd-es (input)
"Return a shell command based on INPUT."
(counsel-require-program "es.exe")
(let ((raw-string (format "es.exe -i -p -r %s"
(counsel--elisp-to-pcre
(ivy--regex input t)))))
;; W32 don't use Unicode by default, so we encode search command
;; to local codepage to support searching filename contains non-ASCII
;; characters.
(if (and (eq system-type 'windows-nt)
(boundp 'w32-ansi-code-page))
(encode-coding-string raw-string
(intern (format "cp%d" w32-ansi-code-page)))
raw-string)))
有人遇到类似问题了么?改了几次都不行。
1 个赞
我遇到过,目前解决方法这样(DOOM下)
;; 不需要counsel处理编码,因编码特殊(utf-8-dos . gbk-dos)
(defun counsel-locate-cmd-es (input)
"Return a shell command based on INPUT."
(counsel-require-program "es.exe")
(let ((raw-string (format "es.exe -i -p -r %s"
(counsel--elisp-to-pcre
(ivy--regex input t)))))
raw-string))
;; es.exe编码特殊,需要临时将编码转为gbk-dos
(defadvice! +change-coding-gbk-a (orig-fun symbol)
"Bound conding to gbk"
:around #'counsel-locate-function
(let (tmp)
(set (make-local-variable 'process-coding-system-alist)
'(("[cC][mM][dD][pP][rR][oO][xX][yY]" gbk-dos . gbk-dos)))
(funcall orig-fun symbol))))
不过我的编码设置也比较怪异,windows下比较折腾,好多要单独处理编码:
(setenv "LANG" "zh_CN.UTF-8")
;; eshell 输入乱码问题
(set-language-environment 'Chinese-gbk)
(set-default 'process-coding-system-alist
'(("[pP][lL][iI][nN][kK]" utf-8-dos . gbk-dos)
("[cC][mM][dD][pP][rR][oO][xX][yY]" utf-8-dos . gbk-dos)
("grep" utf-8-dos . gbk-dos)
("cmd" gbk-dos . gbk-dos)
;; 特别注意 这样后续命令才能接收参数
("xargs" utf-8-unix . utf-8-unix)
("ag" utf-8-dos . gbk-dos)
("rg" utf-8-dos . gbk-dos)
("diff" utf-8-dos . gbk-dos)
;; python 在windows下编码特殊
("python" gbk-dos . gbk-dos)
;; 命令行乱码用以下:
("sdcv" utf-8-dos . gbk-dos)
))
;; 需要在 set-language-environment 后面,不然会乱码
;; 涉及magit注释乱码、文件乱码、ESHELL FIND、GREP乱码等
(prefer-coding-system 'utf-8)
windows下用utf-8的确问题多。我现在折腾得magit,eshell,find,sdcv都正常了。counsel那个我记得是因为重复编码了。
windows 10 添加 unicode support 就好了。
感谢 @cireu
1 个赞