Mercurial > emacs
annotate lisp/language/japan-util.el @ 21043:1ae9ab956d88
(setup-japanese-environment): Set
default-file-name-coding-system to japanese-iso-8bit.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Tue, 03 Mar 1998 01:36:51 +0000 |
parents | f510736ce3d1 |
children | ea0bc6fdefd5 |
rev | line source |
---|---|
17315
a3ca5e15c82a
Fix the format of the first line.
Kenichi Handa <handa@m17n.org>
parents:
17071
diff
changeset
|
1 ;;; japan-util.el --- utilities for Japanese |
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, Japanese | |
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-japanese-environment () |
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
29 "Setup multilingual environment (MULE) for Japanese." |
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) |
20738
f510736ce3d1
In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents:
19854
diff
changeset
|
32 (set-language-environment-coding-systems "Japanese") |
f510736ce3d1
In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents:
19854
diff
changeset
|
33 (if (eq system-type 'ms-dos) |
f510736ce3d1
In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents:
19854
diff
changeset
|
34 (prefer-coding-system 'japanese-shift-jis)) |
21043
1ae9ab956d88
(setup-japanese-environment): Set
Kenichi Handa <handa@m17n.org>
parents:
20738
diff
changeset
|
35 (setq default-file-name-coding-system 'japanese-iso-8bit) |
19368
63415fa4039d
(setup-japanese-environment): Delete
Kenichi Handa <handa@m17n.org>
parents:
19272
diff
changeset
|
36 (setq default-input-method "japanese")) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
37 |
17052 | 38 (defconst japanese-kana-table |
39 '((?$B$"(B ?$B%"(B ?(I1(B) (?$B$$(B ?$B%$(B ?(I2(B) (?$B$&(B ?$B%&(B ?(I3(B) (?$B$((B ?$B%((B ?(I4(B) (?$B$*(B ?$B%*(B ?(I5(B) | |
40 (?$B$+(B ?$B%+(B ?(I6(B) (?$B$-(B ?$B%-(B ?(I7(B) (?$B$/(B ?$B%/(B ?(I8(B) (?$B$1(B ?$B%1(B ?(I9(B) (?$B$3(B ?$B%3(B ?(I:(B) | |
41 (?$B$5(B ?$B%5(B ?(I;(B) (?$B$7(B ?$B%7(B ?(I<(B) (?$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$B$6(B ?$B%6(B "(I;^(B") (?$B$8(B ?$B%8(B "(I<^(B") (?$B$:(B ?$B%:(B "(I=^(B") (?$B$<(B ?$B%<(B "(I>^(B") (?$B$>(B ?$B%>(B "(I?^(B") | |
52 (?$B$@(B ?$B%@(B "(I@^(B") (?$B$B(B ?$B%B(B "(IA^(B") (?$B$E(B ?$B%E(B "(IB^(B") (?$B$G(B ?$B%G(B "(IC^(B") (?$B$I(B ?$B%I(B "(ID^(B") | |
53 (?$B$P(B ?$B%P(B "(IJ^(B") (?$B$S(B ?$B%S(B "(IK^(B") (?$B$V(B ?$B%V(B "(IL^(B") (?$B$Y(B ?$B%Y(B "(IM^(B") (?$B$\(B ?$B%\(B "(IN^(B") | |
54 (?$B$Q(B ?$B%Q(B "(IJ_(B") (?$B$T(B ?$B%T(B "(IK_(B") (?$B$W(B ?$B%W(B "(IL_(B") (?$B$Z(B ?$B%Z(B "(IM_(B") (?$B$](B ?$B%](B "(IN_(B") | |
55 (?$B$!(B ?$B%!(B ?(I'(B) (?$B$#(B ?$B%#(B ?(I((B) (?$B$%(B ?$B%%(B ?(I)(B) (?$B$'(B ?$B%'(B ?(I*(B) (?$B$)(B ?$B%)(B ?(I+(B) | |
56 (?$B$C(B ?$B%C(B ?(I/(B) | |
57 (?$B$c(B ?$B%c(B ?(I,(B) (?$B$e(B ?$B%e(B ?(I-(B) (?$B$g(B ?$B%g(B ?(I.(B) | |
58 (?$B$n(B ?$B%n(B nil) | |
59 (nil ?$B%t(B "(I3^(B") (nil ?$B%u(B nil) (nil ?$B%v(B nil)) | |
60 "Japanese JISX0208 Kana character table. | |
61 Each element is of the form (HIRAGANA KATAKANA HANKAKU-KATAKANA), where | |
62 HIRAGANA and KATAKANA belong to `japanese-jisx0208', | |
63 HANKAKU-KATAKANA belongs to `japanese-jisx0201-kana'.") | |
64 | |
65 ;; Put properties 'katakana, 'hiragana, and 'jix0201 to each Japanese | |
66 ;; kana characters for conversion among them. | |
67 (let ((l japanese-kana-table) | |
68 slot hiragana katakana jisx0201) | |
69 (while l | |
70 (setq slot (car l) | |
71 hiragana (car slot) katakana (nth 1 slot) jisx0201 (nth 2 slot) | |
72 l (cdr l)) | |
73 (if hiragana | |
74 (progn | |
75 (put-char-code-property hiragana 'katakana katakana) | |
76 (put-char-code-property katakana 'hiragana hiragana) | |
77 (if jisx0201 | |
78 (progn | |
79 (put-char-code-property hiragana 'jisx0201 jisx0201) | |
80 (if (integerp jisx0201) | |
81 (put-char-code-property jisx0201 'hiragana hiragana)))))) | |
82 (if jisx0201 | |
83 (progn | |
84 (put-char-code-property katakana 'jisx0201 jisx0201) | |
85 (if (integerp jisx0201) | |
86 (put-char-code-property jisx0201 'katakana katakana)))))) | |
87 | |
88 (defconst japanese-symbol-table | |
89 '((?\$B!!(B ?\ ) (?$B!"(B ?, ?(I$(B) (?$B!#(B ?. ?(I!(B) (?$B!$(B ?, ?(I$(B) (?$B!%(B ?. ?(I!(B) (?$B!&(B nil ?(I%(B) | |
90 (?$B!'(B ?:) (?$B!((B ?\;) (?$B!)(B ??) (?$B!*(B ?!) (?$B!+(B nil ?(I^(B) (?$B!,(B nil ?(I_(B) | |
91 (?$B!-(B ?') (?$B!.(B ?`) (?$B!0(B ?^) (?$B!2(B ?_) (?$B!<(B ?-) (?$B!=(B ?-) (?$B!>(B ?-) | |
92 (?$B!?(B ?/) (?$B!@(B ?\\) (?$B!A(B ?~) (?$B!C(B ?|) (?$B!F(B ?`) (?$B!G(B ?') (?$B!H(B ?\") (?$B!I(B ?\") | |
93 (?\$B!J(B ?\() (?\$B!K(B ?\)) (?\$B!N(B ?[) (?\$B!O(B ?]) (?\$B!P(B ?{) (?\$B!Q(B ?}) | |
94 (?$B!R(B ?<) (?$B!S(B ?>) (?$B!\(B ?+) (?$B!](B ?-) (?$B!a(B ?=) (?$B!c(B ?<) (?$B!d(B ?>) | |
95 (?$B!l(B ?') (?$B!m(B ?\") (?$B!o(B ?\\) (?$B!p(B ?$) (?$B!s(B ?%) (?$B!t(B ?#) (?$B!u(B ?&) (?$B!v(B ?*) | |
96 (?$B!w(B ?@)) | |
97 "Japanese JISX0208 symbol character table. | |
98 Each element is of the form (SYMBOL ASCII HANKAKU), where SYMBOL | |
99 belongs to `japanese-jisx0208', ASCII belongs to `ascii', and HANKAKU | |
100 belongs to `japanese-jisx0201-kana'.") | |
101 | |
102 ;; Put properties 'jisx0208, 'jisx0201, and 'ascii to each Japanese | |
103 ;; symbol and ASCII characters for conversion among them. | |
104 (let ((l japanese-symbol-table) | |
105 slot jisx0208 ascii jisx0201) | |
106 (while l | |
107 (setq slot (car l) | |
108 jisx0208 (car slot) ascii (nth 1 slot) jisx0201 (nth 2 slot) | |
109 l (cdr l)) | |
110 (if ascii | |
111 (progn | |
112 (put-char-code-property jisx0208 'ascii ascii) | |
113 (put-char-code-property ascii 'jisx0208 jisx0208))) | |
114 (if jisx0201 | |
115 (progn | |
116 (put-char-code-property jisx0208 'jisx0201 jisx0201) | |
117 (put-char-code-property jisx0201 'jisx0208 jisx0208))))) | |
118 | |
119 (defconst japanese-alpha-numeric-table | |
120 '((?$B#0(B . ?0) (?$B#1(B . ?1) (?$B#2(B . ?2) (?$B#3(B . ?3) (?$B#4(B . ?4) | |
121 (?$B#5(B . ?5) (?$B#6(B . ?6) (?$B#7(B . ?7) (?$B#8(B . ?8) (?$B#9(B . ?9) | |
122 (?$B#A(B . ?A) (?$B#B(B . ?B) (?$B#C(B . ?C) (?$B#D(B . ?D) (?$B#E(B . ?E) | |
123 (?$B#F(B . ?F) (?$B#G(B . ?G) (?$B#H(B . ?H) (?$B#I(B . ?I) (?$B#J(B . ?J) | |
124 (?$B#K(B . ?K) (?$B#L(B . ?L) (?$B#M(B . ?M) (?$B#N(B . ?N) (?$B#O(B . ?O) | |
125 (?$B#P(B . ?P) (?$B#Q(B . ?Q) (?$B#R(B . ?R) (?$B#S(B . ?S) (?$B#T(B . ?T) | |
126 (?$B#U(B . ?U) (?$B#V(B . ?V) (?$B#W(B . ?W) (?$B#X(B . ?X) (?$B#Y(B . ?Y) (?$B#Z(B . ?Z) | |
127 (?$B#a(B . ?a) (?$B#b(B . ?b) (?$B#c(B . ?c) (?$B#d(B . ?d) (?$B#e(B . ?e) | |
128 (?$B#f(B . ?f) (?$B#g(B . ?g) (?$B#h(B . ?h) (?$B#i(B . ?i) (?$B#j(B . ?j) | |
129 (?$B#k(B . ?k) (?$B#l(B . ?l) (?$B#m(B . ?m) (?$B#n(B . ?n) (?$B#o(B . ?o) | |
130 (?$B#p(B . ?p) (?$B#q(B . ?q) (?$B#r(B . ?r) (?$B#s(B . ?s) (?$B#t(B . ?t) | |
131 (?$B#u(B . ?u) (?$B#v(B . ?v) (?$B#w(B . ?w) (?$B#x(B . ?x) (?$B#y(B . ?y) (?$B#z(B . ?z)) | |
132 "Japanese JISX0208 alpha numeric character table. | |
133 Each element is of the form (ALPHA-NUMERIC ASCII), where ALPHA-NUMERIC | |
134 belongs to `japanese-jisx0208', ASCII belongs to `ascii'.") | |
135 | |
136 ;; Put properties 'jisx0208 and 'ascii to each Japanese alpha numeric | |
137 ;; and ASCII characters for conversion between them. | |
138 (let ((l japanese-alpha-numeric-table) | |
139 slot jisx0208 ascii) | |
140 (while l | |
141 (setq slot (car l) | |
142 jisx0208 (car slot) ascii (cdr slot) | |
143 l (cdr l)) | |
144 (put-char-code-property jisx0208 'ascii ascii) | |
145 (put-char-code-property ascii 'jisx0208 jisx0208))) | |
146 | |
147 ;; Convert string STR by FUNC and return a resulting string. | |
148 (defun japanese-string-conversion (str func &rest args) | |
149 (let ((buf (get-buffer-create " *Japanese work*"))) | |
150 (save-excursion | |
151 (set-buffer buf) | |
152 (erase-buffer) | |
153 (insert str) | |
154 (apply func 1 (point) args) | |
155 (buffer-string)))) | |
156 | |
157 ;;;###autoload | |
158 (defun japanese-katakana (obj &optional hankaku) | |
159 "Convert argument to Katakana and return that. | |
160 The argument may be a character or string. The result has the same type. | |
161 The argument object is not altered--the value is a copy. | |
162 Optional argument HANKAKU t means to convert to `hankaku' Katakana | |
163 \(`japanese-jisx0201-kana'), in which case return value | |
164 may be a string even if OBJ is a character if two Katakanas are | |
165 necessary to represent OBJ." | |
166 (if (stringp obj) | |
167 (japanese-string-conversion obj 'japanese-katakana-region hankaku) | |
168 (or (get-char-code-property obj (if hankaku 'jisx0201 'katakana)) | |
169 obj))) | |
170 | |
171 ;;;###autoload | |
172 (defun japanese-hiragana (obj) | |
173 "Convert argument to Hiragana and return that. | |
174 The argument may be a character or string. The result has the same type. | |
175 The argument object is not altered--the value is a copy." | |
176 (if (stringp obj) | |
177 (japanese-string-conversion obj 'japanese-hiragana-region) | |
178 (or (get-char-code-property obj 'hiragana) | |
179 obj))) | |
180 | |
181 ;;;###autoload | |
182 (defun japanese-hankaku (obj &optional ascii-only) | |
183 "Convert argument to `hankaku' and return that. | |
184 The argument may be a character or string. The result has the same type. | |
185 The argument object is not altered--the value is a copy. | |
186 Optional argument ASCII-ONLY non-nil means to return only ASCII character." | |
187 (if (stringp obj) | |
188 (japanese-string-conversion obj 'japanese-hankaku-region ascii-only) | |
189 (or (get-char-code-property obj 'ascii) | |
190 (and (not ascii-only) | |
191 (get-char-code-property obj 'jisx0201)) | |
192 obj))) | |
193 | |
194 ;;;###autoload | |
195 (defun japanese-zenkaku (obj) | |
196 "Convert argument to `zenkaku' and return that. | |
197 The argument may be a character or string. The result has the same type. | |
198 The argument object is not altered--the value is a copy." | |
199 (if (stringp obj) | |
200 (japanese-string-conversion obj 'japanese-zenkaku-region) | |
201 (or (get-char-code-property obj 'jisx0208) | |
202 obj))) | |
203 | |
204 ;;;###autoload | |
205 (defun japanese-katakana-region (from to &optional hankaku) | |
206 "Convert Japanese `hiragana' chars in the region to `katakana' chars. | |
207 Optional argument HANKAKU t means to convert to `hankaku katakana' character | |
208 of which charset is `japanese-jisx0201-kana'." | |
209 (interactive "r\nP") | |
210 (save-restriction | |
211 (narrow-to-region from to) | |
212 (goto-char (point-min)) | |
213 (while (re-search-forward "\\cH\\|\\cK" nil t) | |
214 (let* ((hira (preceding-char)) | |
215 (kata (japanese-katakana hira hankaku))) | |
216 (if kata | |
217 (progn | |
218 (delete-region (match-beginning 0) (match-end 0)) | |
219 (insert kata))))))) | |
220 | |
221 ;;;###autoload | |
222 (defun japanese-hiragana-region (from to) | |
223 "Convert Japanese `katakana' chars in the region to `hiragana' chars." | |
224 (interactive "r") | |
225 (save-restriction | |
226 (narrow-to-region from to) | |
227 (goto-char (point-min)) | |
228 (while (re-search-forward "\\cK\\|\\ck" nil t) | |
229 (let* ((kata (preceding-char)) | |
230 (hira (japanese-hiragana kata))) | |
231 (if hira | |
232 (progn | |
233 (delete-region (match-beginning 0) (match-end 0)) | |
234 (insert hira))))))) | |
235 | |
236 ;;;###autoload | |
237 (defun japanese-hankaku-region (from to &optional ascii-only) | |
238 "Convert Japanese `zenkaku' chars in the region to `hankaku' chars. | |
239 `Zenkaku' chars belong to `japanese-jisx0208' | |
240 `Hankaku' chars belong to `ascii' or `japanese-jisx0201-kana'. | |
241 Optional argument ASCII-ONLY non-nil means to convert only to ASCII char." | |
242 (interactive "r\nP") | |
243 (save-restriction | |
244 (narrow-to-region from to) | |
245 (goto-char (point-min)) | |
246 (while (re-search-forward "\\cj" nil t) | |
247 (let* ((zenkaku (preceding-char)) | |
248 (hankaku (japanese-hankaku zenkaku ascii-only))) | |
249 (if hankaku | |
250 (progn | |
251 (delete-region (match-beginning 0) (match-end 0)) | |
252 (insert hankaku))))))) | |
253 | |
254 ;;;###autoload | |
255 (defun japanese-zenkaku-region (from to) | |
256 "Convert hankaku' chars in the region to Japanese `zenkaku' chars. | |
257 `Zenkaku' chars belong to `japanese-jisx0208' | |
258 `Hankaku' chars belong to `ascii' or `japanese-jisx0201-kana'." | |
259 (interactive "r") | |
260 (save-restriction | |
261 (narrow-to-region from to) | |
262 (goto-char (point-min)) | |
263 (while (re-search-forward "\\ca\\|\\ck" nil t) | |
264 (let* ((hankaku (preceding-char)) | |
265 (zenkaku (japanese-zenkaku hankaku))) | |
266 (if zenkaku | |
267 (progn | |
268 (delete-region (match-beginning 0) (match-end 0)) | |
269 (insert zenkaku))))))) | |
270 | |
271 ;;;###autoload | |
272 (defun read-hiragana-string (prompt &optional initial-input) | |
273 "Read a Hiragana string from the minibuffer, prompting with string PROMPT. | |
274 If non-nil, second arg INITIAL-INPUT is a string to insert before reading." | |
19854
c6f58c509273
(setup-japanese-environment): Give
Kenichi Handa <handa@m17n.org>
parents:
19764
diff
changeset
|
275 (read-multilingual-string prompt initial-input "japanese-hiragana")) |
17052 | 276 |
277 ;; | |
18309
bd8b521f5218
Provide XXX-util instead of
Kenichi Handa <handa@m17n.org>
parents:
18203
diff
changeset
|
278 (provide 'japan-util) |
17052 | 279 |
280 ;;; japan-util.el ends here |