Emacs (RSS)

Emacs

How to use Chinese characters in Athena: (3) Settings for Emacs (cont.)

Input Chinese characters in Emacs

Once your Emacs can display Chinese characters correctly, you can try to use the MULE (Multilingual Environment) for Emacs to input Chinese characters in Emacs. It can be done in two simple steps:

  1. Set languange environment to Chinese (GB or GBK).

    If you use menu, click Options->MULE->Set Language Environment->Chinese->Chinese-GB

    Note: If you haven't set coding system correctly in your .emacs file, you might need to set it manually at this time.

  2. Toggle input method to a Chinese input method. (You can find it in the MULE menu, too.)

Alternatively, to make these two steps easier, you can write a elisp function in your .emacs file, and bind it to a hotkey, e.g., Ctrl-Space.

(defun my-chinese-mode ()
(interactive)
(set-language-environment 'Chinese-GB)
; or (set-language-environment 'Chinese-GBK)
(set-input-method 'chinese-py-punct)
)

(global-set-key (kbd "C-SPC") 'my-chinese-mode)

Then when you press Ctrl-Space in your Emacs, it will switch to Chinese input method.


Note: You would probably feel the chinese-py-punct input method is quite naive if you, like me, have been used to some "advanced" input methods such as Ziguang Pinyin. Anyway, it provides a simple way to input most frequently used Chinese characters, without installing other software in your system.

Other use of Emacs (BBS client, etc.)

Emacs has a built-in terminal-emulator, in which you can telnet to remote servers that support ANSI colors. "M-x ansi-term" will start a terminal-emulator in a new buffer. This is particularly useful and convenient, if you ever want to connect to a BBS in your Emacs. Of course you have to make sure your Emacs can display Chinese characters properly before you connect to a Chinese BBS site. If you want many BBS-specific features (such as anti-idle), however, you might turn to some "professional" telnet clients. As far as I know, qterm is a good choice under Linux.

For more setting about Emacs, you might want to try the following resources (many other useful documents can be found online, try google!):

posted by wenyang with 0 Comments

How to use Chinese characters in Athena: (2) Settings for Emacs

Display Chinese Characters in Emacs

Usually, if you modify your Emacs config file (i.e., ~/.emacs or ~/.emacs.el) properly, you will be able to display the GB2312 character set, provided that your workstation has at least one Chinese font available. (If you are to check whether the system has provided Chinese fonts or not, try fc-list or xfontsel.)

The following elisp commands will, at least in most cases, enable the display of Chinese characters:

(set-terminal-coding-system 'chinese-iso-8bit)
(set-keyboard-coding-system 'chinese-iso-8bit)
(set-language-environment 'Chinese-GB)
(setq locale-coding-system 'chinese-iso-8bit)
(setq current-language-environment "Chinese-GB")

If your system has fonts that support GBK or GB18030, you may think of using a package called "chinese-gbk" to let Emacs support GBK fonts. If so, instead of setting to language environment to Chinese-GB, you would probably need to set it to Chinese-gbk, by adding the following commands in your .emacs file:

(load "chinese-gbk") ; need to download and install corresponding elisp files
(set-keyboard-coding-system 'chinese-gbk)
(set-selection-coding-system 'chinese-gbk)
(set-keyboard-coding-system 'chinese-gbk)
(set-language-environment 'chinese-gbk)
(setq locale-coding-system 'chinese-gbk)
(setq current-language-environment "Chinese-GBK")

After changing .emacs file, you would need to let Emacs re-evaluate the settings to make it take effect. Either runs the command eval-current-buffer for your .emacs file, or close/kill your current Emacs and then run it again.

Try to open a text file with Chinese characters. If, instead of displaying the Chinese fonts properly, you see a bunch of "boxes", this means either your system does not have an Chinese font available, or your Emacs cannot find a proper fontset to display the characters. Try to specify a useful fontset for your Emacs. For example, in the Linux version of Athena, if SimSun and Ming (a Traditional Chinese font) are available, you can use:

(if (not (member '("-*-tahoma-normal-r-*-*-16-*-*-*-c-*-fontset-chinese"
. "fontset-gbk") fontset-alias-alist))
(progn
(create-fontset-from-fontset-spec
"-*-tahoma-normal-r-*-*-16-*-*-*-c-*-fontset-gbk,
ascii:-*-*-medium-r-normal-*-16-*-*-*-*-*-iso8859-1,
chinese-gb2312:-*-simsun-medium-r-normal-*-16-160-*-*-*-*-gb2312*-*,
korean-ksc5601:-*-medium-r-normal-*-*-*-ksc5601*-*,
chinese-cns11643-5:-*-simsun-medium-r-normal-*-16-160-*-*-*-*-gbk*-0,
chinese-cns11643-6:-*-simsun-medium-r-normal-*-16-160-*-*-*-*-gbk*-0,
chinese-cns11643-7:-*-simsun-medium-r-normal-*-16-160-*-*-*-*-gbk*-0,
chinese-big5-1:-*-Ming(for ISO10646)-*-*-*-*-16-160-*-*-*-*-big5*-*,
chinese-big5-2:-*-Ming(for ISO10646)-*-*-*-*-16-*-*-*-*-*-big5*-*" t)
)
)

(setq default-frame-alist
(append
'((font . "fontset-gbk"))
default-frame-alist))

posted by wenyang with 0 Comments