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