Mercurial > emacs
annotate lisp/language/china-util.el @ 19486:31fbf3a289c1
(display-time-hook): Minor doc fix.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 23 Aug 1997 17:01:03 +0000 |
parents | c42eb695ebcd |
children | f510736ce3d1 |
rev | line source |
---|---|
17315
a3ca5e15c82a
Fix the format of the first line.
Kenichi Handa <handa@m17n.org>
parents:
17098
diff
changeset
|
1 ;;; china-util.el --- utilities for Chinese |
17052 | 2 |
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. | |
18377
8b4a66c66dd6
Change copyright notice.
Richard M. Stallman <rms@gnu.org>
parents:
18309
diff
changeset
|
4 ;; Licensed to the Free Software Foundation. |
17052 | 5 |
6 ;; Keywords: mule, multilingual, Chinese | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it 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 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
17071 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
17052 | 24 |
25 ;;; Code: | |
26 | |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
27 ;;;###autoload |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
28 (defun setup-chinese-gb-environment () |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
29 "Setup multilingual environment (MULE) for Chinese GB2312 users." |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
30 (interactive) |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
31 (setup-english-environment) |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
32 |
19140
a86f1b81dcf5
(setup-chinese-gb-environment): Do not
Kenichi Handa <handa@m17n.org>
parents:
19092
diff
changeset
|
33 (set-default-coding-systems 'chinese-iso-8bit) |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
34 (setq coding-category-iso-8-2 'chinese-iso-8bit) |
18793
f98c1cb6b807
(setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents:
18553
diff
changeset
|
35 (setq coding-category-iso-7-else 'chinese-iso-7bit) |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
36 (setq coding-category-big5 'chinese-big5) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
37 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
38 (set-coding-priority |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
39 '(coding-category-iso-7 |
18793
f98c1cb6b807
(setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents:
18553
diff
changeset
|
40 coding-category-iso-7-else |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
41 coding-category-iso-8-2 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
42 coding-category-big5 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
43 coding-category-iso-8-1 |
18793
f98c1cb6b807
(setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents:
18553
diff
changeset
|
44 coding-category-emacs-mule |
f98c1cb6b807
(setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents:
18553
diff
changeset
|
45 coding-category-iso-8-else)) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
46 |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
47 (setq-default buffer-file-coding-system 'chinese-iso-8bit) |
19140
a86f1b81dcf5
(setup-chinese-gb-environment): Do not
Kenichi Handa <handa@m17n.org>
parents:
19092
diff
changeset
|
48 (setq default-terminal-coding-system 'chinese-iso-8bit) |
a86f1b81dcf5
(setup-chinese-gb-environment): Do not
Kenichi Handa <handa@m17n.org>
parents:
19092
diff
changeset
|
49 (setq default-keyboard-coding-system 'chinese-iso-8bit) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
50 |
19371
18e804fd153b
(setup-chinese-gb-environment): Delete
Kenichi Handa <handa@m17n.org>
parents:
19275
diff
changeset
|
51 (setq default-input-method "chinese-py-punct")) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
52 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
53 ;;;###autoload |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
54 (defun setup-chinese-big5-environment () |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
55 "Setup multilingual environment (MULE) for Chinese Big5 users." |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
56 (interactive) |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
57 (setup-english-environment) |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
58 |
19140
a86f1b81dcf5
(setup-chinese-gb-environment): Do not
Kenichi Handa <handa@m17n.org>
parents:
19092
diff
changeset
|
59 (set-default-coding-systems 'chinese-big5) |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
60 (setq coding-category-iso-8-2 'chinese-big5) |
18793
f98c1cb6b807
(setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents:
18553
diff
changeset
|
61 (setq coding-category-iso-7-else 'chinese-iso-7bit) |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
62 (setq coding-category-big5 'chinese-big5) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
63 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
64 (set-coding-priority |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
65 '(coding-category-iso-7 |
18793
f98c1cb6b807
(setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents:
18553
diff
changeset
|
66 coding-category-iso-7-else |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
67 coding-category-big5 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
68 coding-category-iso-8-2 |
18793
f98c1cb6b807
(setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents:
18553
diff
changeset
|
69 coding-category-emacs-mule |
f98c1cb6b807
(setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents:
18553
diff
changeset
|
70 coding-category-iso-8-else)) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
71 |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
72 (setq-default buffer-file-coding-system 'chinese-big5) |
19140
a86f1b81dcf5
(setup-chinese-gb-environment): Do not
Kenichi Handa <handa@m17n.org>
parents:
19092
diff
changeset
|
73 (setq default-terminal-coding-system 'chinese-big5) |
a86f1b81dcf5
(setup-chinese-gb-environment): Do not
Kenichi Handa <handa@m17n.org>
parents:
19092
diff
changeset
|
74 (setq default-keyboard-coding-system 'chinese-big5) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
75 |
19371
18e804fd153b
(setup-chinese-gb-environment): Delete
Kenichi Handa <handa@m17n.org>
parents:
19275
diff
changeset
|
76 (setq default-input-method "chinese-py-punct-b5")) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
77 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
78 ;;;###autoload |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
79 (defun setup-chinese-cns-environment () |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
80 "Setup multilingual environment (MULE) for Chinese CNS11643 family users." |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
81 (interactive) |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
82 (setup-english-environment) |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
83 |
18793
f98c1cb6b807
(setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents:
18553
diff
changeset
|
84 (setq coding-category-iso-7-else 'chinese-iso-7bit) |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
85 (setq coding-category-big5 'chinese-big5) |
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
86 (setq coding-category-iso-8-2 'chinese-big5) |
19140
a86f1b81dcf5
(setup-chinese-gb-environment): Do not
Kenichi Handa <handa@m17n.org>
parents:
19092
diff
changeset
|
87 (set-default-coding-systems 'chinese-iso-7bit) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
88 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
89 (set-coding-priority |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
90 '(coding-category-iso-7 |
18793
f98c1cb6b807
(setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents:
18553
diff
changeset
|
91 coding-category-iso-7-else |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
92 coding-category-iso-8-2 |
18793
f98c1cb6b807
(setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents:
18553
diff
changeset
|
93 coding-category-big5 |
f98c1cb6b807
(setup-chinese-gb-environment): Adjusted for the change of coding
Kenichi Handa <handa@m17n.org>
parents:
18553
diff
changeset
|
94 coding-category-iso-7-else)) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
95 |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
96 (setq-default buffer-file-coding-system 'chinese-iso-7bit) |
19140
a86f1b81dcf5
(setup-chinese-gb-environment): Do not
Kenichi Handa <handa@m17n.org>
parents:
19092
diff
changeset
|
97 (setq default-terminal-coding-system 'chinese-iso-7bit) |
a86f1b81dcf5
(setup-chinese-gb-environment): Do not
Kenichi Handa <handa@m17n.org>
parents:
19092
diff
changeset
|
98 (setq default-keyboard-coding-system 'chinese-iso-7bit) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
99 |
19371
18e804fd153b
(setup-chinese-gb-environment): Delete
Kenichi Handa <handa@m17n.org>
parents:
19275
diff
changeset
|
100 (setq default-input-method "chinese-quick-cns")) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
101 |
17052 | 102 ;; Hz/ZW encoding stuffs |
103 | |
104 ;; HZ is an encoding method for Chinese character set GB2312 used | |
105 ;; widely in Internet. It is very similar to 7-bit environment of | |
106 ;; ISO-2022. The difference is that HZ uses the sequence "~{" and | |
107 ;; "~}" for designating GB2312 and ASCII respectively, hence, it | |
108 ;; doesn't uses ESC (0x1B) code. | |
109 | |
110 ;; ZW is another encoding method for Chinese character set GB2312. It | |
111 ;; encodes Chinese characters line by line by starting each line with | |
112 ;; the sequence "zW". It also uses only 7-bit as HZ. | |
113 | |
114 ;; ISO-2022 escape sequence to designate GB2312. | |
115 (defvar iso2022-gb-designation "\e$A") | |
116 ;; HZ escape sequence to designate GB2312. | |
117 (defvar hz-gb-designnation "~{") | |
118 ;; ISO-2022 escape sequence to designate ASCII. | |
119 (defvar iso2022-ascii-designation "\e(B") | |
120 ;; HZ escape sequence to designate ASCII. | |
121 (defvar hz-ascii-designnation "~}") | |
122 ;; Regexp of ZW sequence to start GB2312. | |
123 (defvar zw-start-gb "^zW") | |
124 ;; Regexp for start of GB2312 in an encoding mixture of HZ and ZW. | |
125 (defvar hz/zw-start-gb (concat hz-gb-designnation "\\|" zw-start-gb)) | |
126 | |
127 (defvar decode-hz-line-continuation nil | |
128 "Flag to tell if we should care line continuation convention of Hz.") | |
129 | |
130 ;;;###autoload | |
131 (defun decode-hz-region (beg end) | |
132 "Decode HZ/ZW encoded text in the current region. | |
133 Return the length of resulting text." | |
134 (interactive "r") | |
135 (save-excursion | |
136 (save-restriction | |
137 (narrow-to-region beg end) | |
138 | |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
139 ;; We, at first, convert HZ/ZW to `iso-2022-7bit', |
17052 | 140 ;; then decode it. |
141 | |
142 ;; "~\n" -> "\n" | |
143 (goto-char (point-min)) | |
144 (while (search-forward "~" nil t) | |
145 (if (= (following-char) ?\n) (delete-char -1)) | |
146 (if (not (eobp)) (forward-char 1))) | |
147 | |
148 ;; "^zW...\n" -> Chinese GB2312 | |
149 ;; "~{...~}" -> Chinese GB2312 | |
150 (goto-char (point-min)) | |
151 (let ((chinese-found nil)) | |
152 (while (re-search-forward hz/zw-start-gb nil t) | |
153 (if (= (char-after (match-beginning 0)) ?z) | |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
154 ;; ZW -> iso-2022-7bit |
17052 | 155 (progn |
156 (delete-char -2) | |
157 (insert iso2022-gb-designation) | |
158 (end-of-line) | |
159 (insert iso2022-ascii-designation)) | |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
160 ;; HZ -> iso-2022-7bit |
17052 | 161 (delete-char -2) |
162 (insert iso2022-gb-designation) | |
163 (let ((pos (save-excursion (end-of-line) (point)))) | |
164 (if (search-forward hz-ascii-designnation pos t) | |
165 (replace-match iso2022-ascii-designation) | |
166 (if (not decode-hz-line-continuation) | |
167 (insert iso2022-ascii-designation))))) | |
168 (setq chinese-found t)) | |
169 (if (or chinese-found | |
170 (let ((enable-multibyte-characters nil)) | |
171 ;; Here we check if the text contains EUC (China) codes. | |
172 ;; If any, we had better decode them also. | |
173 (goto-char (point-min)) | |
174 (re-search-forward "[\240-\377]" nil t))) | |
17098
8917133b7e82
Remove prefix "coding-system-" from coding system symbol names.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
175 (decode-coding-region (point-min) (point-max) 'euc-china))) |
17052 | 176 |
177 ;; "~~" -> "~" | |
178 (goto-char (point-min)) | |
179 (while (search-forward "~~" nil t) (delete-char -1)) | |
180 (- (point-max) (point-min))))) | |
181 | |
182 ;;;###autoload | |
183 (defun decode-hz-buffer () | |
184 "Decode HZ/ZW encoded text in the current buffer." | |
185 (interactive) | |
186 (decode-hz-region (point-min) (point-max))) | |
187 | |
188 ;;;###autoload | |
189 (defun encode-hz-region (beg end) | |
190 "Encode the text in the current region to HZ. | |
191 Return the length of resulting text." | |
192 (interactive "r") | |
193 (save-excursion | |
194 (save-restriction | |
195 (narrow-to-region beg end) | |
196 | |
197 ;; "~" -> "~~" | |
198 (goto-char (point-min)) | |
199 (while (search-forward "~" nil t) (insert ?~)) | |
200 | |
201 ;; Chinese GB2312 -> "~{...~}" | |
202 (goto-char (point-min)) | |
203 (if (re-search-forward "\\cc" nil t) | |
204 (let ((enable-multibyte-characters nil) | |
205 pos) | |
206 (goto-char (setq pos (match-beginning 0))) | |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
207 (encode-coding-region pos (point-max) 'iso-2022-7bit) |
17052 | 208 (goto-char pos) |
209 (while (search-forward iso2022-gb-designation nil t) | |
210 (delete-char -3) | |
211 (insert hz-gb-designnation)) | |
212 (goto-char pos) | |
213 (while (search-forward iso2022-ascii-designation nil t) | |
214 (delete-char -3) | |
215 (insert hz-ascii-designnation)))) | |
216 (- (point-max) (point-min))))) | |
217 | |
218 ;;;###autoload | |
219 (defun encode-hz-buffer () | |
220 "Encode the text in the current buffer to HZ." | |
221 (interactive) | |
222 (encode-hz-region (point-min) (point-max))) | |
223 | |
224 ;; | |
18309
bd8b521f5218
Provide XXX-util instead of
Kenichi Handa <handa@m17n.org>
parents:
17993
diff
changeset
|
225 (provide 'china-util) |
17052 | 226 |
227 ;;; china-util.el ends here |