Emacs显示^米一个缓冲过程

时间:2022-09-01 09:37:20

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. When I write multi-line text into the buffer via a process-send-region or process-send-string each line is suffixed with ^M.

目前,我有一个进程缓冲区,它是utf-8-auto (emacs modeline将缓冲区报告为utf-8-auto-dos),带有CRLF风格的新行。当我写多行文本到缓冲通过process-send-region或process-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.

是什么让这个问题奇怪的是,文本写入process-buffer直接从这个过程中,不包含^ 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.)

(请注意,流程-send区域的源文本将始终来自Emacs缓冲区、process-send-string,当多行将从Windows剪贴板接口到killring时,或者从Emacs缓冲区返回到killring。)

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钩(做一些colorisation基于输入)所以最后我做额外regexp-replace-in-string在这输入文本作为钩子函数的一部分,我想避免,因为它似乎错了,但我会把它作为一个出租汽车司机的解决方案如果没有其他作品。

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.

和一切工作正常。

3 个解决方案

#1


2  

This is because those files are in DOS/Windows line endings. You can use C-x [Enter] f unix [Enter] to convert them to the Unix encoding.

这是因为这些文件位于DOS/Windows行结尾。您可以使用C-x [Enter] f unix [Enter]将它们转换为unix编码。

^L is a page break. 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.

^ L是一个分页符。我曾经见过它们分离源代码的不同部分(对于老式的文本打印机清单),或者在文本文档中插入一个实际的“新页面”命令。

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选择到正确的编码系统。

#2


1  

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-% C-q C-M RETURN

对于dos2unix方法,您可以在Emacs中使用MULE命令之一,或者(我最喜欢的),因为这些字符被错误地当作文本的一部分,所以您可以使用命令替换它们,以替换文本中的字符串:M-% C-q C-M

M-% is the query-replace command.

M-%是查询-替换命令。

C-q means "let me type the next character without interpreting it as the RETURN key".

C-q的意思是“让我输入下一个字符,而不把它解释为返回键”。

#3


0  

I believe you see those because of the inconsistencies in your newlines (e.g. windows newlines vs *nux ones), you should probably try dos2unix

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

#1


2  

This is because those files are in DOS/Windows line endings. You can use C-x [Enter] f unix [Enter] to convert them to the Unix encoding.

这是因为这些文件位于DOS/Windows行结尾。您可以使用C-x [Enter] f unix [Enter]将它们转换为unix编码。

^L is a page break. 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.

^ L是一个分页符。我曾经见过它们分离源代码的不同部分(对于老式的文本打印机清单),或者在文本文档中插入一个实际的“新页面”命令。

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选择到正确的编码系统。

#2


1  

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-% C-q C-M RETURN

对于dos2unix方法,您可以在Emacs中使用MULE命令之一,或者(我最喜欢的),因为这些字符被错误地当作文本的一部分,所以您可以使用命令替换它们,以替换文本中的字符串:M-% C-q C-M

M-% is the query-replace command.

M-%是查询-替换命令。

C-q means "let me type the next character without interpreting it as the RETURN key".

C-q的意思是“让我输入下一个字符,而不把它解释为返回键”。

#3


0  

I believe you see those because of the inconsistencies in your newlines (e.g. windows newlines vs *nux ones), you should probably try dos2unix

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