2012年(7)
分类: LINUX
2012-04-10 16:44:56
查看当前文件编码的命令:
M-x describe-code-system
编码设置命令:
(setq default-buffer-file-coding-system 'utf-8) ;默认buffer编码是utf-8,(新文件)
(prefer-coding-system 'utf-8) ;指定文件编码优先,此时buffer新建和读取都默认是utf-8,也可以M-x prefer-coding-system 只执行一次
Specifying a Coding System for File Text
In cases where Emacs does not automatically choose the right coding system for a file's contents, you can use these commands to specify one:
C-xThe command C-x
You can also use this command to specify the end-of-line conversion (see ) for encoding the current buffer. For example, C-x
Another way to specify the coding system for a file is when you visit the file. First use the command C-x
So if the immediately following command is C-x C-f, for example, it reads the file using that coding system (and records the coding system for when you later save the file). Or if the immediately following command is C-x C-w, it writes the file using that coding system. When you specify the coding system for saving in this way, instead of with C-x
Other file commands affected by a specified coding system include C-x i and C-x C-v, as well as the other-window variants of C-x C-f. C-x
An easy way to visit a file with no conversion is with the M-x find-file-literally command. See .
The default value of the variable buffer-file-coding-system specifies the choice of coding system to use when you create a new file. It applies when you find a new file, and when you create a buffer and then save it in a file. Selecting a language environment typically sets this variable to a good choice of default coding system for that language environment.
If you visit a file with a wrong coding system, you can correct this with C-x
If a piece of text has already been inserted into a buffer using the wrong coding system, you can redo the decoding of it using M-x recode-region. This prompts you for the proper coding system, then for the wrong coding system that was actually used, and does the conversion. It first encodes the region using the wrong coding system, then decodes it again using the proper coding system.