Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

中文修复 #6

Closed
Liu233w opened this issue Oct 12, 2016 · 12 comments
Closed

中文修复 #6

Liu233w opened this issue Oct 12, 2016 · 12 comments
Labels

Comments

@Liu233w
Copy link
Owner

Liu233w commented Oct 12, 2016

分支 fix-chinese 中的 1af937f 尝试基本成功,代码很精简,cmd、python repl、yapf(org-babel和python-mode中的)都没有乱码,但是org-babel中运行python有问题(python3)

SyntaxError: Non-UTF-8 code starting with '\xd6' in file <stdin> on line 3, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

其它解释执行的程序没有问题(如ccl)

原来的代码已经修复了此问题,但是 yapfifly 产生的代码缩进与直接在命令行中通过 yapf name.py -i 产生的不同(只在有中文的行中有)。

新代码可以解决缩进问题。

@Liu233w
Copy link
Owner Author

Liu233w commented Oct 12, 2016

ob会把python代码写入到临时文件中,然后执行临时文件。
如果指定运行的session的话,不会写入到临时文件,运行时不会报错。
↑临时解决办法,指定 :session name

@Liu233w Liu233w added the bug label Oct 12, 2016
@Liu233w
Copy link
Owner Author

Liu233w commented Oct 12, 2016

问题已定位:
org-babel--shell-command-on-region 函数中,文件第 106 行,写入的文件默认为 ANSI 编码,这个函数是通过 make-temp-file 来创建临时文件的,无法指定临时文件的编码,在单步运行中手动把生成的文件改成 utf-8 编码之后可以正常生成结果。

函数使用了 write-region 写入文件,可以通过 coding-system-for-write 来指定编码。

@Liu233w Liu233w closed this as completed Oct 12, 2016
Liu233w added a commit that referenced this issue Oct 12, 2016
@Liu233w
Copy link
Owner Author

Liu233w commented Oct 20, 2016

目测还是不行,不光 web-beautify magit 有乱码,而且包也没法正常安装了(编码问题,存储包信息的buffer后面有一个 ^M 的符号)

@Liu233w Liu233w reopened this Oct 20, 2016
@Liu233w
Copy link
Owner Author

Liu233w commented Oct 21, 2016

包安装的编码问题已在 daf8288 中解决

@Liu233w
Copy link
Owner Author

Liu233w commented Oct 26, 2016

刚刚发现org-babel 还有问题,输出的编码是 ansi ,不是utf-8

@Liu233w
Copy link
Owner Author

Liu233w commented Oct 27, 2016

指定 :session 的时候又会出问题了_(:зゝ∠)_,是emacs25的原因?

@Liu233w
Copy link
Owner Author

Liu233w commented Nov 16, 2016

org输出session的函数定位:
process-send-string
comint-send-string
comint-send-input
org-babel-python-evaluate-session
org-babel-python-evaluate
org-babel-execute:python

process-send-string没说使用什么编码_(:зゝ∠)_

@Liu233w
Copy link
Owner Author

Liu233w commented Dec 5, 2016

a5ea507 修复了session问题,但Python交互执行的部分send的中文会变成乱码,直接在repl中输入中文会导致repl抛出异常。

在HTML和js中使用 , = 仍然会使中文乱码

@Liu233w
Copy link
Owner Author

Liu233w commented Dec 5, 2016

注释掉

    ;; (set-default 'process-coding-system-alist
    ;;              '(("[pP][lL][iI][nN][kK]" gbk-dos . gbk-dos)
    ;;                ("[cC][mM][dD][pP][rR][oO][xX][yY]" gbk-dos . gbk-dos)))

之后HTML的乱码问题解决,但是org->python->session就会报错

#+begin_src python :results output :session a
  print(' 中文')
#+end_src

#+RESULTS:
: File "<stdin>", line 0
:     
:     ^
: SyntaxError: 'gbk' codec can't decode byte 0xad in position 10: illegal multibyte sequence

其他的问题依旧

@Liu233w
Copy link
Owner Author

Liu233w commented Dec 5, 2016

将那个注释的代码替换成

    (set-terminal-coding-system 'gbk)
    (modify-coding-system-alist 'process "*" 'gbk)
    (defun liu233w/windows-shell-mode-coding ()
      (set-buffer-file-coding-system 'gbk)
      (set-buffer-process-coding-system 'gbk 'gbk))
    (add-hook 'shell-mode-hook #'liu233w/windows-shell-mode-coding)
    (add-hook 'inferior-python-mode-hook #'liu233w/windows-shell-mode-coding)

之后就都修复了"(ºДº*)

等待确认:

  • org中不使用session
  • 使用session
  • 命令行里ipython中文
  • Python repl 中 send 中文
  • 直接输入中文
  • Python使用 , = 美化
  • HTML , = 美化
  • js 。。。
  • magit magit 的乱码问题 #8

@Liu233w
Copy link
Owner Author

Liu233w commented Dec 5, 2016

skewer 不会自动把网页的编码设为 utf-8,在浏览器的log中显示的中文是乱码

nodejs-repl 可以正常显示中文

@Liu233w
Copy link
Owner Author

Liu233w commented Dec 5, 2016

skewer 的log又不会乱码了,目前还没有定位原因


log是没有乱码的,但是每次send-buffer 的时候都会在日志中留下一段乱码,原因不明:
default


使用skewer-eval-last-expression发送的log没有乱码,但是skewer-load-buffer发送的log有乱码。
中文网页同样,load-buffer创建的有乱码,直接eval没有

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant