输入汉字在ESS中没有得到正确的响应。

时间:2021-03-05 22:58:06

I had this weird encoding issue for my Emacs and R environment. Display of Chinese characters are all good with my .Rprofile setting Sys.setlocale("LC_ALL","zh_CN.utf-8"); except the echo of input ones.

我在Emacs和R环境中有这个奇怪的编码问题。在我的.Rprofile设置Sys.setlocale(“LC_ALL”,“zh_CN.utf-8”)中显示中文字符都很好。除了输入的回声。

    > linkTexts[5]
          font 
    "使用帮助" 
    > functionNotExist()
    错误: 没有"functionNotExist"这个函数
    > fire <- "你好"
    > fire
    [1] "  "

As we can see, Chinese characters contained in the vector linkTexts, Chinese error messages, and input Chinese characters all can be perfectly shown, yet the echo of input characters were only shown as blank placeholders.

正如我们所看到的,汉字中包含的矢量链接、中文错误信息和输入汉字都可以完美地显示出来,但输入字符的回波只显示为空白的占位符。

sessionInfo() is here, which is as expected given the Sys.setlocale("LC_ALL","zh_CN.utf-8"); setting:

sessionInfo()在这里,正如预期的那样,给定Sys.setlocale(“LC_ALL”,“zh_CN.utf-8”);设置:

    > sessionInfo()
    R version 2.15.2 (2012-10-26)
    Platform: i386-apple-darwin9.8.0/i386 (32-bit)

    locale:
    [1] zh_CN.utf-8/zh_CN.utf-8/zh_CN.utf-8/C/zh_CN.utf-8/C

    attached base packages:
    [1] stats     graphics  grDevices utils     datasets  methods   base     

    other attached packages:
    [1] XML_3.96-1.1

    loaded via a namespace (and not attached):
    [1] compiler_2.15.2 tools_2.15.2   

And I have no locale settings in the .Emacs file.

我在. emacs文件中没有设置区域设置。

To me, this seems to be an Emacs encoding issue, but I just don't know how to correct it. Any idea or suggestion? Thanks.

对我来说,这似乎是一个Emacs编码问题,但我只是不知道如何去纠正它。任何想法或建议吗?谢谢。

2 个解决方案

#1


1  

Your examples work for me out of the box. You can set emacs process decoding/encoding with M-x set-buffer-process-coding-system. Once you figure out what encoding works (if any) you can make the change permanent with:

你的例子对我很有用。您可以设置emacs进程解码/编码与M-x设置-缓冲-过程-编码系统。一旦你弄清楚了什么编码工作(如果有的话),你就可以使变更成为永久性的:

(add-hook 'ess-R-post-run-hook
          (lambda () (set-buffer-process-coding-system
                      'utf-8-unix 'utf-8-unix)))

Replace utf-8-unix with your chosen encoding.

用所选择的编码替换utf-8-unix。

I am not very convinced that the above will help. LinkText in your example displays well, but fire does not, doesn't look like an emacs/ESS issue.

我不太相信上面所说的会有帮助。在您的示例中,链接文本显示良好,但是fire不像emacs/ESS问题。

#2


1  

VitoshKa has made the perfectly correct suggestion. I just wanna add more of own findings here, as people may meet different but similar special character problems. Yet they can be solved in the same way.

VitoshKa提出了完全正确的建议。我只是想在这里添加更多的自己的发现,因为人们可能会遇到不同但相似的特殊性格问题。然而,它们可以用同样的方式得到解决。

The root cause is the input encoding setting to the current buffer process. As shown by the M-x describe-current-coding-system command, default buffer process encoding setting was good for output (utf-8-unix) but deteriorated for input:

根本原因是当前缓冲区进程的输入编码设置。正如M-x描述的电流编码系统命令所示,默认的缓冲过程编码设置对输出(utf-8-unix)很好,但是对于输入的性能却下降了:

    Coding systems for process I/O:
      encoding input to the process: 1 -- iso-latin-1-unix (alias: iso-8859-1-unix latin-1-unix)

      decoding output from the process: U -- utf-8-unix (alias: mule-utf-8-unix)

Changing the coding system for input into utf-8-unix, either by 'M-x set-buffer-process-coding-system' or adding the ess-post-run-hook into .emacs like suggested by VitoshKa, would suffice for solving the Chinese character display problem.

改变输入utf-8-unix的编码系统,通过“m x set-buffer-process-coding-system”或添加VitoshKa ess-post-run-hook成. emacs这样的建议,为解决汉字显示问题就足够了。

The other problem people may meet due to this setting is special character in ESS. When trying to input special characters, you may get the error message, 错误: 句法分析器%d行里不能有多字节字符 , or invalid multibyte character in parser at line %d in English.

由于这种背景,人们可能会遇到的另一个问题是ESS中的特殊角色。当尝试输入特殊字符,你可能得到错误消息,错误:句法分析器% d行里不能有多字节字符,或无效的多字节字符在第% 1行解析器在英语。

    > x <- data.frame(part = c("målløs", "ny"))
    错误: 句法分析器1行里不能有多字节字符

And with the correct utf-8-unix setting for input coding system of buffer process, the above error for special characters disappears.

对于缓冲过程的输入编码系统,使用正确的utf-8-unix设置,特殊字符的上述错误就消失了。

#1


1  

Your examples work for me out of the box. You can set emacs process decoding/encoding with M-x set-buffer-process-coding-system. Once you figure out what encoding works (if any) you can make the change permanent with:

你的例子对我很有用。您可以设置emacs进程解码/编码与M-x设置-缓冲-过程-编码系统。一旦你弄清楚了什么编码工作(如果有的话),你就可以使变更成为永久性的:

(add-hook 'ess-R-post-run-hook
          (lambda () (set-buffer-process-coding-system
                      'utf-8-unix 'utf-8-unix)))

Replace utf-8-unix with your chosen encoding.

用所选择的编码替换utf-8-unix。

I am not very convinced that the above will help. LinkText in your example displays well, but fire does not, doesn't look like an emacs/ESS issue.

我不太相信上面所说的会有帮助。在您的示例中,链接文本显示良好,但是fire不像emacs/ESS问题。

#2


1  

VitoshKa has made the perfectly correct suggestion. I just wanna add more of own findings here, as people may meet different but similar special character problems. Yet they can be solved in the same way.

VitoshKa提出了完全正确的建议。我只是想在这里添加更多的自己的发现,因为人们可能会遇到不同但相似的特殊性格问题。然而,它们可以用同样的方式得到解决。

The root cause is the input encoding setting to the current buffer process. As shown by the M-x describe-current-coding-system command, default buffer process encoding setting was good for output (utf-8-unix) but deteriorated for input:

根本原因是当前缓冲区进程的输入编码设置。正如M-x描述的电流编码系统命令所示,默认的缓冲过程编码设置对输出(utf-8-unix)很好,但是对于输入的性能却下降了:

    Coding systems for process I/O:
      encoding input to the process: 1 -- iso-latin-1-unix (alias: iso-8859-1-unix latin-1-unix)

      decoding output from the process: U -- utf-8-unix (alias: mule-utf-8-unix)

Changing the coding system for input into utf-8-unix, either by 'M-x set-buffer-process-coding-system' or adding the ess-post-run-hook into .emacs like suggested by VitoshKa, would suffice for solving the Chinese character display problem.

改变输入utf-8-unix的编码系统,通过“m x set-buffer-process-coding-system”或添加VitoshKa ess-post-run-hook成. emacs这样的建议,为解决汉字显示问题就足够了。

The other problem people may meet due to this setting is special character in ESS. When trying to input special characters, you may get the error message, 错误: 句法分析器%d行里不能有多字节字符 , or invalid multibyte character in parser at line %d in English.

由于这种背景,人们可能会遇到的另一个问题是ESS中的特殊角色。当尝试输入特殊字符,你可能得到错误消息,错误:句法分析器% d行里不能有多字节字符,或无效的多字节字符在第% 1行解析器在英语。

    > x <- data.frame(part = c("målløs", "ny"))
    错误: 句法分析器1行里不能有多字节字符

And with the correct utf-8-unix setting for input coding system of buffer process, the above error for special characters disappears.

对于缓冲过程的输入编码系统,使用正确的utf-8-unix设置,特殊字符的上述错误就消失了。