简体   繁体   English

Emacs在进程缓冲区中显示^ M

[英]Emacs showing ^M in a process buffer

At the moment, I have a process-buffer which is utf-8-auto (emacs modeline reports the buffer as utf-8-auto-dos ) with CRLF style newlines. 目前,我有一个带有CRLF样式换行符的utf-8-auto (emacs modeline报告该缓冲区为utf-8-auto-dos )进程缓冲区。 When I write multi-line text into the buffer via a process-send-region or process-send-string each line is suffixed with ^M . 当我通过process-send-regionprocess-send-string将多行文本写入缓冲区时,每行都带有^M后缀。

What makes this problem odd is that text written to the process-buffer directly from the process, does not contain ^M 's. 使这个问题变得奇怪的是,直接从流程写入流程缓冲区的文本不包含^M

It doesn't seem to make any difference where the source text comes from, in fact, even a multi-line region marked and sent that already appears in the process buffer (that doesn't contain ^M ) will have them when sent. 实际上,源文本的来源似乎没有任何区别,实际上,即使已标记并发送的多行区域已经出现在进程缓冲区(不包含^M )中,也将在发送时包含它们。

( Note the source text for the process-send-region will always come from a Emacs buffer, process-send-string, when multi-line will be from the Windows clipboard interface to the killring, or again from an Emacs buffer to killring.) 请注意 ,当多行从Windows剪贴板界面到杀戮,或从Emacs缓冲区杀到杀戮时,process-send-region的源文本将始终来自Emacs缓冲区,process-send-string。 )

I should also add that the incoming text to the buffer is parsed by a after-change-functions hook (to do some colorisation based on input) so a last resort I'd do an additional regexp-replace-in-string on this incoming text as part of that hook function, I'd like to avoid that because it seems wrong , but I'll add it as a hacky solution if nothing else works. 我还应该补充一点,缓冲区中的传入文本是通过after-change-functions钩子解析的(基于输入进行一些着色),因此,万不得已时,我会对此传入regexp-replace-in-string进行额外的regexp-replace-in-string文本作为该钩子函数的一部分,我想避免这种情况,因为它似乎是错误的 ,但是如果没有其他效果,我将其添加为hacky解决方案。

Addendum 附录

I updated the encoding settings for the buffer and the process to use utf-8-dos instead of utf-8-auto and the ^M 's vanished. 我更新了缓冲区的编码设置以及使用utf-8-dos而不是utf-8-auto ,并且^M消失了。

So in the buffer setup part of my app, I did... 因此,在我的应用程序的缓冲区设置部分中,我做了...

(switch-to-buffer "sock-buffer")
(set-process-coding-system (get-process sock-process) 'utf-8-dos 'utf-8-dos)
(set-buffer-file-coding-system 'utf-8-dos nil)
(set-buffer-process-coding-system 'utf-8-dos 'utf-8-dos)

Then reduced this to just... 然后减少到...

(switch-to-buffer "sock-buffer")
(set-buffer-process-coding-system 'utf-8-dos 'utf-8-dos)

And everything worked fine. 而且一切正常。

This is because those files are in DOS/Windows line endings. 这是因为这些文件位于DOS / Windows行尾。 You can use Cx [Enter] f unix [Enter] to convert them to the Unix encoding. 您可以使用Cx [Enter] f Unix [Enter]将它们转换为Unix编码。

^L is a page break. ^L是分页符。 I've seen them some times to separate different parts of source code (for old-fashioned listings in a text printer), or in text documentation to insert an actual "new page" command. 我见过几次它们可以分隔源代码的不同部分(用于文本打印机中的老式列表),或者在文本文档中可以插入实际的“新页面”命令。

As of the update, here you can see that you have to select set-process-coding-system to the correct coding system. 从更新开始,您可以在这里看到必须将set-process-coding-system选择为正确的编码系统。

Alternately to the dos2unix approach, you could use one of the MULE commands in Emacs, or (my favorite), since these characters are mistakenly treated as part of the text, you can replace them using the command to replace a string in the text: M-% Cq CM RETURN 除了dos2unix方法之外,您还可以使用Emacs中的MULE命令之一,或者(我最喜欢的),因为这些字符被错误地视为文本的一部分,因此可以使用以下命令替换它们,以替换文本中的字符串: M-%Cq CM返回

M-% is the query-replace command. M-%是query-replace命令。

Cq means "let me type the next character without interpreting it as the RETURN key". Cq的意思是“让我键入下一个字符而不将其解释为RETURN键”。

我相信您会因为换行不一致(例如Windows换行与* nux的不一致)而看到这些,您应该尝试使用dos2unix

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM