代码之家  ›  专栏  ›  技术社区  ›  Chmouel Boudjnah

不显示带Emacs的^m字符

  •  10
  • Chmouel Boudjnah  · 技术社区  · 14 年前

    我想知道是否有办法暂时不显示文件中的^M字符。我不想删除它们,我只是不想显示它们。

    干杯,

    3 回复  |  直到 12 年前
        1
  •  11
  •   Otto Pichlhoefer    14 年前

    我使用以下函数(忘记在哪里找到它):

    (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 []))
    
        2
  •  7
  •   aculich    12 年前

    这个 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 R DOS RET(C-X RET R DOS RET)

    以避免显示 ^M 不实际修改文件的字符。

        3
  •  0
  •   Paul Rubel    14 年前

    至少在Emacs22.3中,这似乎是一个问题,只有当您的文件结合了换行样式时,比如说在两个WindowsUnix下使用“非开明”编辑器进行编辑时。

    如果行总是以w/^m结尾,那么现代Emacs会在底部注意到它是[DOS]模式,而不是显示^m。这样,在保存时,它就足够智能地将^m放在文件中。

    如果你有一些奇怪的组合,你可以试着跑步

    $ unix2dos FILE
    

    为了达到一个良好的状态,在这之后,希望你能保持它在DOS模式。

    我注意到我的Xemacs 21.4没有这个功能,唉。

    这里有一个讨论: http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/676113e90825d4e7