简体   繁体   English

不要使用emacs显示^ M个字符

[英]Don't display ^M characters with emacs

I am wondering if there is a way to temporarily not display the ^M characters in a file. 我想知道是否有办法暂时不在文件中显示^ M个字符。 I don't want to remove them I just want to not display them. 我不想删除它们我只是想不显示它们。

Cheers, 干杯,

I use the following function (forgot where I found it): 我使用以下功能(忘记我找到的地方):

(defun hide-ctrl-M ()
  "Hides the disturbing '^M' showing up in files containing mixed UNIX and DOS line endings."
  (interactive)
  (setq buffer-display-table (make-display-table))
  (aset buffer-display-table ?\^M []))

The GNU Emacs documentation describes how to handle Text Coding using revert-buffer-with-coding-system : GNU Emacs文档描述了如何使用revert-buffer-with-coding-system处理文本编码:

C-x <RET> r coding <RET>
Revisit the current file using the coding system coding (revert-buffer-with-coding-system).

In your case if the correct system coding isn't detected automatically you can type: 在您的情况下,如果未自动检测到正确的系统编码,您可以键入:

Cx RET r dos RET Cx RET r dos RET

to avoid displaying the ^M characters without actually modifying the file. 避免显示^M字符而不实际修改文件。

At least with emacs 22.3 this seems to be an issue only if your file has a combination of newline styles, say from editing with a "non-enlightened" editor under both windows unix. 至少对于emacs 22.3,这似乎只是一个问题,如果你的文件有新行样式的组合,比如在两个windows unix下使用“非开明”编辑器进行编辑。

If the lines are consistently terminated w/ ^M modern emacs will note at the bottom that it's [dos] mode and not show the ^M. 如果线路始终被终止,则现代emacs将在底部注明它是[dos]模式而不显示^ M. It's then smart enough to place ^M in the file when you save. 然后智能足以在保存时将^ M放在文件中。

If you've got some odd combination you can try running 如果你有一些奇怪的组合,你可以尝试跑步

$ unix2dos FILE

to get to a good state, after which hopefully you can keep it in DOS mode. 为了达到一个良好的状态,希望你可以保持它在DOS模式。

I note that my xemacs 21.4 doesn't have this feature, alas. 我注意到我的xemacs 21.4没有这个功能,唉。

There's a discussion here: http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/676113e90825d4e7 这里有一个讨论: http//groups.google.com/group/gnu.emacs.help/browse_thread/thread/676113e90825d4e7

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

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