开发者

Emacs: is there a way to determine coding system of a file?

开发者 https://www.devze.com 2023-04-05 08:16 出处:网络
Suppose I open a file and find there Ïåñíÿ àëüïèíèñòîâ and so on. Can I make emacs find the c开发者_StackOverflow中文版orrect encoding? AkelPad for example has such feature - in mos

Suppose I open a file and find there

Ïåñíÿ àëüïèíèñòîâ

and so on. Can I make emacs find the c开发者_StackOverflow中文版orrect encoding? AkelPad for example has such feature - in most cases it'll open a file with a correct encoding.


This page http://www.gnu.org/s/libtool/manual/emacs/Recognize-Coding.html explains emacs' system for detecting coding systems. You can control it to some extent:

The variables auto-coding-alist, auto-coding-regexp-alist and auto-coding-functions are the strongest way to specify the coding system for certain patterns of file names, or for files containing certain patterns

You may have inadvertently disabled this feature:

However, there may be cases that you want to read escape sequences in a file as is. In such a case, you can set the variable inhibit-iso-escape-detection to non-nil. Then the code detection ignores any escape sequences, and never uses an ISO-2022 encoding. The result is that all escape sequences become visible in the buffer.


Consider this: characters are really just numbers. You can open up a text file and say, "I think this is ANSI". And then when you encounter a number that you KNOW isn't in ANSI, the only thing you can say for certain is "ok, this isn't ANSI".

You can't automatically detect an encoding, but you can detect what are probably incorrect encodings. In this way you can hypothesize an encoding, but never be fully certain.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号