Chinaunix首页 | 论坛 | 博客
  • 博客访问: 21920
  • 博文数量: 7
  • 博客积分: 146
  • 博客等级: 入伍新兵
  • 技术积分: 50
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-06 19:49
文章分类
文章存档

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-x f coding Use coding system coding for saving or revisiting the visited file in the current buffer. 
C-x c coding Specify coding system coding for the immediately following command. 
C-x r coding Revisit the current file using the coding system coding. 
M-x recode-region  right  wrong Convert a region that was decoded using coding system wrong, decoding it using coding system right instead.

The command C-x f (set-buffer-file-coding-system) sets the file coding system for the current buffer—in other words, it says which coding system to use when saving or reverting the visited file. You specify which coding system using the minibuffer. If you specify a coding system that cannot handle all of the characters in the buffer, Emacs warns you about the troublesome characters when you actually save the buffer.

You can also use this command to specify the end-of-line conversion (see ) for encoding the current buffer. For example, C-x f dos  will cause Emacs to save the current buffer's text with DOS-style CRLF line endings.

Another way to specify the coding system for a file is when you visit the file. First use the command C-x c (universal-coding-system-argument); this command uses the minibuffer to read a coding system name. After you exit the minibuffer, the specified coding system is used for the immediately following command.

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 f, there is no warning if the buffer contains characters that the coding system cannot handle.

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 c also affects commands that start subprocesses, including M-x shell (see ). If the immediately following command does not use the coding system, then C-x c ultimately has no effect.

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 r (revert-buffer-with-coding-system). This visits the current file again, using a coding system you specify.

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.

阅读(2752) | 评论(3) | 转发(0) |
给主人留下些什么吧!~~

垒砖匠2012-04-12 21:17:45

小蝌蚪123: EMACS打开GB2312的文件,出现一堆乱码的样子的说。。。怎么回事??.....
C-x <RET> r coding <RET>Revisit the current file using the coding system coding.

C-x <RET> r gb2312 <RET>

垒砖匠2012-04-12 21:17:08

小蝌蚪123: EMACS打开GB2312的文件,出现一堆乱码的样子的说。。。怎么回事??.....
C-x <RET> r coding <RET>Revisit the current file using the coding system coding.

C-x <RET> r gb2312 <RET

小蝌蚪1232012-04-11 17:03:34

EMACS打开GB2312的文件,出现一堆乱码的样子的说。。。怎么回事??