Jessica CHEN Joy and Loneliness CATEGORIES TIMEMACHINE TAGS GEMS

關於簡體中文系統(GBK)環境裡的EMACS編碼配置

[ coding  elisp  emacs  encoding  gbk  utf8  ]

關於modify-coding-system-alist,這裡摘錄部分文檔:

> > (modify-coding-system-alist TARGET-TYPE REGEXP CODING-SYSTEM) > > > > Modify one of look up tables for finding a coding system on I/O operation. There are three of such tables, `file-coding-system-alist`, `process-coding-system-alist`, and `network-coding-system-alist`. > > > > TARGET-TYPE specifies which of them to modify. If it is `file`, it affects `file-coding-system-alist` (which see). If it is `process`, it affects `process-coding-system-alist` (which see). If it is `network`, it affects `network-coding-system-alist` (which see). > > > > REGEXP is a regular expression matching a target of I/O operation. The target is a file name if TARGET-TYPE is `file`, a program name if TARGET-TYPE is `process`, or a network service name or a port number to connect to if TARGET-TYPE is `network`. > > > > CODING-SYSTEM is a coding system to perform code conversion on the I/O > > > > operation, or a cons cell (DECODING . ENCODING) specifying the coding systems for decoding and encoding respectively, or a function symbol which, when called, returns such a cons cell. > >

不過我又要 默認用UTF-8新建跟編輯文件,所以再配置下面兩句:

<span class="p">(</span><span class="nv">prefer-coding-system</span> <span class="ss">'utf-8-unix</span><span class="p">)</span>
<span class="p">(</span><span class="k">setq</span> <span class="nv">buffer-file-coding-system</span> <span class="ss">'utf-8-unix</span><span class="p">)</span>

關於prefer-coding-system,這裡摘錄部分文檔:

(prefer-coding-system CODING-SYSTEM) > > > > Add CODING-SYSTEM at the front of the priority list for automatic detection. This also sets the following coding systems: * coding system of a newly created buffer * default coding system for subprocess I/O This also sets the following values: * default value used as `file-name-coding-system` for converting file names * default value for the command `set-terminal-coding-system` * default value for the command `set-keyboard-coding-system` > >

所以在需要 M-x shell 的時候用 M-x cygwin 來代替就可以了,其它時候還是emacs默認的方式,這樣就不會有編碼的問題了。

NOTE1: 如果出現“stty: standard input: Inappropriate ioctl for device”,原因是

> > Your shell startup file (.cshrc, .bashrc, .kshrc, whichever is appropriate for your shell) contains stty commands, which should only be done in interactive shells (in fact, probably only in the initial login shell, so they should probably be in .login or .profile). > >

NOTE2: 如果出現^[]~^G之類的,原因可能是PS1的設置造成的,可以在~/.bashrc裡重新export PS1為想要的格式,比如 export PS1="[[e[32m]u@h [e[33m]w[e[0m]]$ ",看PS1的值可以在 cygwin 裡 echo $PS1關於PS1