Mercurial > emacs
annotate lisp/language/china-util.el @ 18583:66e7a91e32ef
(load-with-code-conversion):
Don't run kill-buffer-hook or kill-buffer-query-functions.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 04 Jul 1997 00:17:55 +0000 |
parents | 62e17ab4e33e |
children | f98c1cb6b807 |
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 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
33 (setq primary-language "Chinese-GB") |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
34 |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
35 (setq coding-category-iso-8-2 'chinese-iso-8bit) |
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
36 (setq coding-category-iso-else 'chinese-iso-7bit) |
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
37 (setq coding-category-big5 'chinese-big5) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
38 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
39 (set-coding-priority |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
40 '(coding-category-iso-7 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
41 coding-category-iso-else |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
42 coding-category-iso-8-2 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
43 coding-category-big5 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
44 coding-category-iso-8-1 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
45 coding-category-emacs-mule)) |
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) |
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
48 (set-terminal-coding-system-internal 'chinese-iso-8bit) |
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
49 (set-keyboard-coding-system-internal 'chinese-iso-8bit) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
50 (setq sendmail-coding-system nil |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
51 rmail-file-coding-system 'chinese-iso-7bit) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
52 |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
53 (setq default-input-method '("Chinese-GB" . "chinese-py"))) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
54 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
55 ;;;###autoload |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
56 (defun setup-chinese-big5-environment () |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
57 "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
|
58 (interactive) |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
59 (setup-english-environment) |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
60 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
61 (setq primary-language "Chinese-BIG5") |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
62 |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
63 (setq coding-category-iso-8-2 'chinese-big5) |
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
64 (setq coding-category-iso-else 'chinese-iso-7bit) |
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
65 (setq coding-category-big5 'chinese-big5) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
66 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
67 (set-coding-priority |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
68 '(coding-category-iso-7 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
69 coding-category-iso-else |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
70 coding-category-big5 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
71 coding-category-iso-8-2 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
72 coding-category-emacs-mule)) |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
73 |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
74 (setq-default buffer-file-coding-system 'chinese-big5) |
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
75 (set-terminal-coding-system-internal 'chinese-big5) |
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
76 (set-keyboard-coding-system-internal 'chinese-big5) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
77 (setq sendmail-coding-system nil |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
78 rmail-file-coding-system 'chienese-iso-7bit) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
79 |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
80 (setq default-input-method '("Chinese-BIG5" . "chinese-b5-py"))) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
81 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
82 ;;;###autoload |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
83 (defun setup-chinese-cns-environment () |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
84 "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
|
85 (interactive) |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
86 (setup-english-environment) |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
87 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
88 (setq primary-language "Chinese-CNS") |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
89 |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
90 (setq coding-category-iso-else 'chinese-iso-7bit) |
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
91 (setq coding-category-big5 'chinese-big5) |
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
92 (setq coding-category-iso-8-2 'chinese-big5) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
93 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
94 (set-coding-priority |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
95 '(coding-category-iso-7 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
96 coding-category-iso-else |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
97 coding-category-iso-8-2 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
98 coding-category-big5)) |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
99 |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
100 (setq-default buffer-file-coding-system 'chinese-iso-7bit) |
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
101 (set-terminal-coding-system-internal 'chinese-iso-7bit) |
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
102 (set-keyboard-coding-system-internal 'chinese-iso-7bit) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
103 (setq sendmail-coding-system nil |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
104 rmail-file-coding-system 'chinese-iso-7bit) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
105 |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
106 (setq default-input-method '("Chinese-CNS" . "quail-quick-cns"))) |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
107 |
17052 | 108 ;; Hz/ZW encoding stuffs |
109 | |
110 ;; HZ is an encoding method for Chinese character set GB2312 used | |
111 ;; widely in Internet. It is very similar to 7-bit environment of | |
112 ;; ISO-2022. The difference is that HZ uses the sequence "~{" and | |
113 ;; "~}" for designating GB2312 and ASCII respectively, hence, it | |
114 ;; doesn't uses ESC (0x1B) code. | |
115 | |
116 ;; ZW is another encoding method for Chinese character set GB2312. It | |
117 ;; encodes Chinese characters line by line by starting each line with | |
118 ;; the sequence "zW". It also uses only 7-bit as HZ. | |
119 | |
120 ;; ISO-2022 escape sequence to designate GB2312. | |
121 (defvar iso2022-gb-designation "\e$A") | |
122 ;; HZ escape sequence to designate GB2312. | |
123 (defvar hz-gb-designnation "~{") | |
124 ;; ISO-2022 escape sequence to designate ASCII. | |
125 (defvar iso2022-ascii-designation "\e(B") | |
126 ;; HZ escape sequence to designate ASCII. | |
127 (defvar hz-ascii-designnation "~}") | |
128 ;; Regexp of ZW sequence to start GB2312. | |
129 (defvar zw-start-gb "^zW") | |
130 ;; Regexp for start of GB2312 in an encoding mixture of HZ and ZW. | |
131 (defvar hz/zw-start-gb (concat hz-gb-designnation "\\|" zw-start-gb)) | |
132 | |
133 (defvar decode-hz-line-continuation nil | |
134 "Flag to tell if we should care line continuation convention of Hz.") | |
135 | |
136 ;;;###autoload | |
137 (defun decode-hz-region (beg end) | |
138 "Decode HZ/ZW encoded text in the current region. | |
139 Return the length of resulting text." | |
140 (interactive "r") | |
141 (save-excursion | |
142 (save-restriction | |
143 (narrow-to-region beg end) | |
144 | |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
145 ;; We, at first, convert HZ/ZW to `iso-2022-7bit', |
17052 | 146 ;; then decode it. |
147 | |
148 ;; "~\n" -> "\n" | |
149 (goto-char (point-min)) | |
150 (while (search-forward "~" nil t) | |
151 (if (= (following-char) ?\n) (delete-char -1)) | |
152 (if (not (eobp)) (forward-char 1))) | |
153 | |
154 ;; "^zW...\n" -> Chinese GB2312 | |
155 ;; "~{...~}" -> Chinese GB2312 | |
156 (goto-char (point-min)) | |
157 (let ((chinese-found nil)) | |
158 (while (re-search-forward hz/zw-start-gb nil t) | |
159 (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
|
160 ;; ZW -> iso-2022-7bit |
17052 | 161 (progn |
162 (delete-char -2) | |
163 (insert iso2022-gb-designation) | |
164 (end-of-line) | |
165 (insert iso2022-ascii-designation)) | |
18553
62e17ab4e33e
Use true coding system names instead of
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
166 ;; HZ -> iso-2022-7bit |
17052 | 167 (delete-char -2) |
168 (insert iso2022-gb-designation) | |
169 (let ((pos (save-excursion (end-of-line) (point)))) | |
170 (if (search-forward hz-ascii-designnation pos t) | |
171 (replace-match iso2022-ascii-designation) | |
172 (if (not decode-hz-line-continuation) | |
173 (insert iso2022-ascii-designation))))) | |
174 (setq chinese-found t)) | |
175 (if (or chinese-found | |
176 (let ((enable-multibyte-characters nil)) | |
177 ;; Here we check if the text contains EUC (China) codes. | |
178 ;; If any, we had better decode them also. | |
179 (goto-char (point-min)) | |
180 (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
|
181 (decode-coding-region (point-min) (point-max) 'euc-china))) |
17052 | 182 |
183 ;; "~~" -> "~" | |
184 (goto-char (point-min)) | |
185 (while (search-forward "~~" nil t) (delete-char -1)) | |
186 (- (point-max) (point-min))))) | |
187 | |
188 ;;;###autoload | |
189 (defun decode-hz-buffer () | |
190 "Decode HZ/ZW encoded text in the current buffer." | |
191 (interactive) | |
192 (decode-hz-region (point-min) (point-max))) | |
193 | |
194 ;;;###autoload | |
195 (defun encode-hz-region (beg end) | |
196 "Encode the text in the current region to HZ. | |
197 Return the length of resulting text." | |
198 (interactive "r") | |
199 (save-excursion | |
200 (save-restriction | |
201 (narrow-to-region beg end) | |
202 | |
203 ;; "~" -> "~~" | |
204 (goto-char (point-min)) | |
205 (while (search-forward "~" nil t) (insert ?~)) | |
206 | |
207 ;; Chinese GB2312 -> "~{...~}" | |
208 (goto-char (point-min)) | |
209 (if (re-search-forward "\\cc" nil t) | |
210 (let ((enable-multibyte-characters nil) | |
211 pos) | |
212 (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
|
213 (encode-coding-region pos (point-max) 'iso-2022-7bit) |
17052 | 214 (goto-char pos) |
215 (while (search-forward iso2022-gb-designation nil t) | |
216 (delete-char -3) | |
217 (insert hz-gb-designnation)) | |
218 (goto-char pos) | |
219 (while (search-forward iso2022-ascii-designation nil t) | |
220 (delete-char -3) | |
221 (insert hz-ascii-designnation)))) | |
222 (- (point-max) (point-min))))) | |
223 | |
224 ;;;###autoload | |
225 (defun encode-hz-buffer () | |
226 "Encode the text in the current buffer to HZ." | |
227 (interactive) | |
228 (encode-hz-region (point-min) (point-max))) | |
229 | |
230 ;; | |
18309
bd8b521f5218
Provide XXX-util instead of
Kenichi Handa <handa@m17n.org>
parents:
17993
diff
changeset
|
231 (provide 'china-util) |
17052 | 232 |
233 ;;; china-util.el ends here |