comparison lisp/language/china-util.el @ 207:e45d5e7c476e r20-4b2

Import from CVS: tag r20-4b2
author cvs
date Mon, 13 Aug 2007 10:03:52 +0200
parents 3bb7ccffb0c0
children
comparison
equal deleted inserted replaced
206:d3e9274cbc4e 207:e45d5e7c476e
1 ;;; china-util.el --- utilities for Chinese 1 ;;; china-util.el --- utilities for Chinese
2 2
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. 3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
5 ;; Copyright (C) 1997 MORIOKA Tomohiko
5 6
6 ;; Keywords: mule, multilingual, Chinese 7 ;; Keywords: mule, multilingual, Chinese
7 8
8 ;; This file is part of GNU Emacs. 9 ;; This file is part of XEmacs.
9 10
10 ;; GNU Emacs is free software; you can redistribute it and/or modify 11 ;; XEmacs is free software; you can redistribute it and/or modify it
11 ;; it under the terms of the GNU General Public License as published by 12 ;; under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option) 13 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version. 14 ;; any later version.
14 15
15 ;; GNU Emacs is distributed in the hope that it will be useful, 16 ;; XEmacs is distributed in the hope that it will be useful, but
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; GNU General Public License for more details. 19 ;; General Public License for more details.
19 20
20 ;; You should have received a copy of the GNU General Public License 21 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the 22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 ;; Boston, MA 02111-1307, USA. 24 ;; 02111-1307, USA.
24 25
25 ;;; Code: 26 ;;; Code:
27
28 ;;;###autoload
29 (defun setup-chinese-gb-environment ()
30 "Setup multilingual environment (MULE) for Chinese GB2312 users."
31 (interactive)
32 (setup-english-environment)
33
34 (set-default-coding-systems 'cn-gb-2312)
35 ;; (setq coding-category-iso-8-2 'chinese-iso-8bit)
36 (set-coding-category-system 'iso-8-2 'cn-gb-2312)
37 ;; (setq coding-category-iso-7-else 'chinese-iso-7bit)
38 ;; (setq coding-category-big5 'chinese-big5)
39
40 ;; (set-coding-priority
41 ;; '(coding-category-iso-7
42 ;; coding-category-iso-7-else
43 ;; coding-category-iso-8-2
44 ;; coding-category-big5
45 ;; coding-category-iso-8-1
46 ;; coding-category-emacs-mule
47 ;; coding-category-iso-8-else))
48 (set-coding-priority-list
49 '(iso-7
50 iso-8-2
51 big5
52 iso-8-1
53 no-conversion
54 iso-8-designate
55 iso-lock-shift
56 shift-jis))
57
58 ;; (when (eq 'x (device-type (selected-device)))
59 ;; (x-use-halfwidth-roman-font 'chinese-gb2312 "gb1988"))))
60 (when (featurep 'egg)
61 (setq-default its:*current-map* (its:get-mode-map "PinYin")))
62 (setq default-input-method "chinese-py-punct")
63 )
64
65 ;;;###autoload
66 (defun setup-chinese-big5-environment ()
67 "Setup multilingual environment (MULE) for Chinese Big5 users."
68 (interactive)
69 (setup-english-environment)
70
71 (set-default-coding-systems 'big5)
72 ;; (setq coding-category-iso-8-2 'chinese-big5)
73 (set-coding-category-system 'iso-8-2 'cn-gb-2312)
74 ;; (setq coding-category-iso-7-else 'chinese-iso-7bit)
75 ;; (setq coding-category-big5 'chinese-big5)
76
77 ;; (set-coding-priority
78 ;; '(coding-category-iso-7
79 ;; coding-category-iso-7-else
80 ;; coding-category-big5
81 ;; coding-category-iso-8-2
82 ;; coding-category-emacs-mule
83 ;; coding-category-iso-8-else))
84 (set-coding-priority-list
85 '(iso-7
86 big5
87 iso-8-2
88 no-conversion
89 iso-8-1
90 iso-8-designate
91 iso-lock-shift
92 shift-jis))
93
94 (setq default-input-method "chinese-py-punct-b5")
95 )
96
97 ;; ;;;###autoload
98 ;; (defun setup-chinese-cns-environment ()
99 ;; "Setup multilingual environment (MULE) for Chinese CNS11643 family users."
100 ;; (interactive)
101 ;; (setup-english-environment)
102 ;;
103 ;; (setq coding-category-iso-7-else 'chinese-iso-7bit)
104 ;; (setq coding-category-big5 'chinese-big5)
105 ;; (setq coding-category-iso-8-2 'chinese-big5)
106 ;; (set-default-coding-systems 'chinese-iso-7bit)
107 ;;
108 ;; (set-coding-priority
109 ;; '(coding-category-iso-7
110 ;; coding-category-iso-7-else
111 ;; coding-category-iso-8-2
112 ;; coding-category-big5
113 ;; coding-category-iso-7-else))
114 ;;
115 ;; (setq-default buffer-file-coding-system 'chinese-iso-7bit)
116 ;; (setq default-terminal-coding-system 'chinese-iso-7bit)
117 ;; (setq default-keyboard-coding-system 'chinese-iso-7bit)
118 ;;
119 ;; (setq default-input-method "chinese-quick-cns"))
26 120
27 ;; Hz/ZW encoding stuffs 121 ;; Hz/ZW encoding stuffs
28 122
29 ;; HZ is an encoding method for Chinese character set GB2312 used 123 ;; HZ is an encoding method for Chinese character set GB2312 used
30 ;; widely in Internet. It is very similar to 7-bit environment of 124 ;; widely in Internet. It is very similar to 7-bit environment of
59 (interactive "r") 153 (interactive "r")
60 (save-excursion 154 (save-excursion
61 (save-restriction 155 (save-restriction
62 (narrow-to-region beg end) 156 (narrow-to-region beg end)
63 157
64 ;; We, at first, convert HZ/ZW to `iso-2022-7', 158 ;; We, at first, convert HZ/ZW to `iso-2022-7bit',
65 ;; then decode it. 159 ;; then decode it.
66 160
67 ;; "~\n" -> "\n" 161 ;; "~\n" -> "\n"
68 (goto-char (point-min)) 162 (goto-char (point-min))
69 (while (search-forward "~" nil t) 163 (while (search-forward "~" nil t)
74 ;; "~{...~}" -> Chinese GB2312 168 ;; "~{...~}" -> Chinese GB2312
75 (goto-char (point-min)) 169 (goto-char (point-min))
76 (let ((chinese-found nil)) 170 (let ((chinese-found nil))
77 (while (re-search-forward hz/zw-start-gb nil t) 171 (while (re-search-forward hz/zw-start-gb nil t)
78 (if (= (char-after (match-beginning 0)) ?z) 172 (if (= (char-after (match-beginning 0)) ?z)
79 ;; ZW -> iso-20227-7 173 ;; ZW -> iso-2022-7bit
80 (progn 174 (progn
81 (delete-char -2) 175 (delete-char -2)
82 (insert iso2022-gb-designation) 176 (insert iso2022-gb-designation)
83 (end-of-line) 177 (end-of-line)
84 (insert iso2022-ascii-designation)) 178 (insert iso2022-ascii-designation))
85 ;; HZ -> iso-20227-7 179 ;; HZ -> iso-2022-7bit
86 (delete-char -2) 180 (delete-char -2)
87 (insert iso2022-gb-designation) 181 (insert iso2022-gb-designation)
88 (let ((pos (save-excursion (end-of-line) (point)))) 182 (let ((pos (save-excursion (end-of-line) (point))))
89 (if (search-forward hz-ascii-designnation pos t) 183 (if (search-forward hz-ascii-designnation pos t)
90 (replace-match iso2022-ascii-designation) 184 (replace-match iso2022-ascii-designation)
95 (let ((enable-multibyte-characters nil)) 189 (let ((enable-multibyte-characters nil))
96 ;; Here we check if the text contains EUC (China) codes. 190 ;; Here we check if the text contains EUC (China) codes.
97 ;; If any, we had better decode them also. 191 ;; If any, we had better decode them also.
98 (goto-char (point-min)) 192 (goto-char (point-min))
99 (re-search-forward "[\240-\377]" nil t))) 193 (re-search-forward "[\240-\377]" nil t)))
100 (decode-coding-region (point-min) (point-max) 'cn-gb-2312))) 194 (decode-coding-region (point-min) (point-max) 'euc-china)))
101 195
102 ;; "~~" -> "~" 196 ;; "~~" -> "~"
103 (goto-char (point-min)) 197 (goto-char (point-min))
104 (while (search-forward "~~" nil t) (delete-char -1)) 198 (while (search-forward "~~" nil t) (delete-char -1))
105 (- (point-max) (point-min))))) 199 (- (point-max) (point-min)))))
127 (goto-char (point-min)) 221 (goto-char (point-min))
128 (if (re-search-forward "\\cc" nil t) 222 (if (re-search-forward "\\cc" nil t)
129 (let ((enable-multibyte-characters nil) 223 (let ((enable-multibyte-characters nil)
130 pos) 224 pos)
131 (goto-char (setq pos (match-beginning 0))) 225 (goto-char (setq pos (match-beginning 0)))
132 (encode-coding-region pos (point-max) 'iso-2022-7) 226 (encode-coding-region pos (point-max) 'iso-2022-7bit)
133 (goto-char pos) 227 (goto-char pos)
134 (while (search-forward iso2022-gb-designation nil t) 228 (while (search-forward iso2022-gb-designation nil t)
135 (delete-char -3) 229 (delete-char -3)
136 (insert hz-gb-designnation)) 230 (insert hz-gb-designnation))
137 (goto-char pos) 231 (goto-char pos)
145 "Encode the text in the current buffer to HZ." 239 "Encode the text in the current buffer to HZ."
146 (interactive) 240 (interactive)
147 (encode-hz-region (point-min) (point-max))) 241 (encode-hz-region (point-min) (point-max)))
148 242
149 ;; 243 ;;
150 (provide 'language/china-util) 244 (provide 'china-util)
151 245
152 ;;; Local Variables:
153 ;;; generated-autoload-file: "../loaddefs.el"
154 ;;; End:
155 ;;; china-util.el ends here 246 ;;; china-util.el ends here