让 Emacs 在没有转换编码的情况下显示 BOMs

;; Delete codings like `utf-*-with-signature' (they hide BOMs)
;; to allow to always display the BOM (Byte-order mark signature)
;; to be able to remove it without the need to visit files literally
;; or with `C-x RET c utf-8 RET C-x C-f'.
;; SEE ALSO http://thread.gmane.org/gmane.emacs.devel/116668/focus=116738
(setq auto-coding-regexp-alist
      (delete (rassoc 'utf-16be-with-signature auto-coding-regexp-alist)
      (delete (rassoc 'utf-16le-with-signature auto-coding-regexp-alist)
      (delete (rassoc 'utf-8-with-signature auto-coding-regexp-alist)
              auto-coding-regexp-alist))))

BOM 头是一个很恶心的东西,如果在 Windows 下面制作好的 Unix 编码的文件,如果在 Mac 上面使用就会遇到 BOM 头的问题。在比较文件内容的时候,你很可能就会被恶心到,因为肉眼看起来完全一样的字符串,比较却是不相等的。

2 个赞

另外在 emacs 里面使用命令 find-file-literally-at-point 是可以显示这些 BOM 字符的,nice!

2 个赞

好东西,这两天正在找类似的资料呢。

其实还可以使用 hexl-find-file 在二进制 mode 下面打开,这样就可以看到他真实的字符存储是什么了。 在 hexl-mode 下面按 C-c C-c 即可回到原来的模式, Emacs Rocks! :smile:

2 个赞

这个也值得一读