2010-06-15 29 views

回答

11

我使用下面的函數(忘了,我發現它):

(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 [])) 
+0

可以使用該代碼,但我建議使用Emacs內置的功能來正確處理[文本編碼](http://stackoverflow.com/a/14009245/462302)。 – aculich 2012-12-23 06:58:32

0

至少Emacs的22.3,這似乎是唯一的,如果你的文件有新行樣式的組合問題,從兩個窗口UNIX下一個「非開明」編輯器中編輯說。

如果行始終終止w/^ M現代emacs會在底部注意它是[dos]模式並且不顯示^ M。當你保存時,它足夠聰明以將^ M放入文件中。

如果你有一些奇怪的組合,你可以嘗試運行

$ unix2dos FILE 

得到一個良好的狀態,之後,希望你可以把它在DOS模式下。

我注意到我的xemacs 21.4沒有這個功能,唉。

這裏有一個討論: http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/676113e90825d4e7

+2

unix2dos更改文件,這不是OP要 – 2010-06-16 06:56:50

+0

正確的文件,但是......提供考慮unix2dos的建議是一種解決文件包含混合換行符問題的方法。換句話說,這裏提供的答案適用於OP *可能不知道要問的問題*。 – Cheeso 2010-06-17 13:37:34

4

GNU Emacs documentation介紹如何處理文本使用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). 

在你的情況下,如果沒有自動檢測到正確的系統編碼,你可以鍵入:

C-X RETřDOS RET

避免而不真正修改文件顯示^M字符。