Commit | Line | Data |
---|---|---|
60370d40 | 1 | ;;; japan-util.el --- utilities for Japanese -*- coding: iso-2022-7bit; -*- |
4ed46869 | 2 | |
4ed46869 | 3 | ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. |
fa526c4a | 4 | ;; Licensed to the Free Software Foundation. |
0216c3df | 5 | ;; Copyright (C) 2001 Free SOftware Foundation, Inc. |
4ed46869 KH |
6 | |
7 | ;; Keywords: mule, multilingual, Japanese | |
8 | ||
9 | ;; This file is part of GNU Emacs. | |
10 | ||
11 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 | ;; it under the terms of the GNU General Public License as published by | |
13 | ;; the Free Software Foundation; either version 2, or (at your option) | |
14 | ;; any later version. | |
15 | ||
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
369314dc KH |
22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 | ;; Boston, MA 02111-1307, USA. | |
4ed46869 | 25 | |
60370d40 PJ |
26 | ;;; Commentary: |
27 | ||
4ed46869 KH |
28 | ;;; Code: |
29 | ||
45717142 KH |
30 | ;;;###autoload |
31 | (defun setup-japanese-environment-internal () | |
9a05d1fa KH |
32 | ;; By default, we use 'japanese-iso-8bit for file names. But, the |
33 | ;; following prefer-coding-system will override it. | |
d5f9316f | 34 | (if (memq system-type '(windows-nt ms-dos cygwin)) |
1a5f6e6a KH |
35 | (prefer-coding-system 'japanese-shift-jis) |
36 | (prefer-coding-system 'japanese-iso-8bit))) | |
335a7ad7 | 37 | |
4ed46869 KH |
38 | (defconst japanese-kana-table |
39 | '((?\e$B$"\e(B ?\e$B%"\e(B ?\e(I1\e(B) (?\e$B$$\e(B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(B "\e(I\\e(B") |
59 | ("\e$B$&!+\e(B" ?\e$B%t\e(B "\e(I3^\e(B") (nil ?\e$B%u\e(B "\e(I6\e(B") (nil ?\e$B%v\e(B "\e(I9\e(B")) | |
4ed46869 KH |
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 | |
33366a82 KH |
74 | (if (stringp hiragana) |
75 | (if (> (length hiragana) 1) | |
76 | (let ((hira (aref hiragana 0))) | |
77 | (put-char-code-property | |
b2ba2dc0 | 78 | hira 'kana-composition |
33366a82 | 79 | (cons (cons (aref hiragana 1) katakana) |
b2ba2dc0 | 80 | (get-char-code-property hira 'kana-composition))))) |
4ed46869 | 81 | (put-char-code-property hiragana 'katakana katakana) |
33366a82 KH |
82 | (put-char-code-property hiragana 'jisx0201 jisx0201))) |
83 | (when (integerp katakana) | |
84 | (put-char-code-property katakana 'hiragana hiragana) | |
85 | (put-char-code-property katakana 'jisx0201 jisx0201)) | |
4ed46869 | 86 | (if jisx0201 |
33366a82 KH |
87 | (if (stringp jisx0201) |
88 | (if (> (length jisx0201) 1) | |
89 | (let ((kana (aref jisx0201 0))) | |
90 | (put-char-code-property | |
b2ba2dc0 | 91 | kana 'kana-composition |
33366a82 | 92 | (cons (cons (aref jisx0201 1) katakana) |
b2ba2dc0 | 93 | (get-char-code-property kana 'kana-composition))))) |
33366a82 KH |
94 | (put-char-code-property jisx0201 'hiragana hiragana) |
95 | (put-char-code-property jisx0201 'katakana katakana) | |
96 | (put-char-code-property jisx0201 'jisx0208 katakana))))) | |
4ed46869 KH |
97 | |
98 | (defconst japanese-symbol-table | |
33366a82 | 99 | '((?\\e$B!!\e(B ?\ ) (?\e$B!$\e(B ?, ?\e(I$\e(B) (?\e$B!%\e(B ?. ?\e(I!\e(B) (?\e$B!"\e(B ?, ?\e(I$\e(B) (?\e$B!#\e(B ?. ?\e(I!\e(B) (?\e$B!&\e(B nil ?\e(I%\e(B) |
4ed46869 | 100 | (?\e$B!'\e(B ?:) (?\e$B!(\e(B ?\;) (?\e$B!)\e(B ??) (?\e$B!*\e(B ?!) (?\e$B!+\e(B nil ?\e(I^\e(B) (?\e$B!,\e(B nil ?\e(I_\e(B) |
0216c3df | 101 | (?\e$B!-\e(B ?') (?\e$B!.\e(B ?`) (?\e$B!0\e(B ?^) (?\e$B!2\e(B ?_) (?\e$B!<\e(B ?- ?\e(I0\e(B) (?\e$B!=\e(B ?-) (?\e$B!>\e(B ?-) |
4ed46869 KH |
102 | (?\e$B!?\e(B ?/) (?\e$B!@\e(B ?\\) (?\e$B!A\e(B ?~) (?\e$B!C\e(B ?|) (?\e$B!F\e(B ?`) (?\e$B!G\e(B ?') (?\e$B!H\e(B ?\") (?\e$B!I\e(B ?\") |
103 | (?\\e$B!J\e(B ?\() (?\\e$B!K\e(B ?\)) (?\\e$B!N\e(B ?[) (?\\e$B!O\e(B ?]) (?\\e$B!P\e(B ?{) (?\\e$B!Q\e(B ?}) | |
8a4d8a5d KH |
104 | (?\e$B!R\e(B ?<) (?\e$B!S\e(B ?>) (?\\e$B!V\e(B nil ?\\e(I"\e(B) (?\\e$B!W\e(B nil ?\\e(I#\e(B) |
105 | (?\e$B!\\e(B ?+) (?\e$B!]\e(B ?-) (?\e$B!a\e(B ?=) (?\e$B!c\e(B ?<) (?\e$B!d\e(B ?>) | |
4ed46869 KH |
106 | (?\e$B!l\e(B ?') (?\e$B!m\e(B ?\") (?\e$B!o\e(B ?\\) (?\e$B!p\e(B ?$) (?\e$B!s\e(B ?%) (?\e$B!t\e(B ?#) (?\e$B!u\e(B ?&) (?\e$B!v\e(B ?*) |
107 | (?\e$B!w\e(B ?@)) | |
108 | "Japanese JISX0208 symbol character table. | |
109 | Each element is of the form (SYMBOL ASCII HANKAKU), where SYMBOL | |
110 | belongs to `japanese-jisx0208', ASCII belongs to `ascii', and HANKAKU | |
111 | belongs to `japanese-jisx0201-kana'.") | |
112 | ||
113 | ;; Put properties 'jisx0208, 'jisx0201, and 'ascii to each Japanese | |
114 | ;; symbol and ASCII characters for conversion among them. | |
115 | (let ((l japanese-symbol-table) | |
116 | slot jisx0208 ascii jisx0201) | |
117 | (while l | |
118 | (setq slot (car l) | |
119 | jisx0208 (car slot) ascii (nth 1 slot) jisx0201 (nth 2 slot) | |
120 | l (cdr l)) | |
121 | (if ascii | |
122 | (progn | |
123 | (put-char-code-property jisx0208 'ascii ascii) | |
124 | (put-char-code-property ascii 'jisx0208 jisx0208))) | |
125 | (if jisx0201 | |
126 | (progn | |
127 | (put-char-code-property jisx0208 'jisx0201 jisx0201) | |
128 | (put-char-code-property jisx0201 'jisx0208 jisx0208))))) | |
129 | ||
130 | (defconst japanese-alpha-numeric-table | |
131 | '((?\e$B#0\e(B . ?0) (?\e$B#1\e(B . ?1) (?\e$B#2\e(B . ?2) (?\e$B#3\e(B . ?3) (?\e$B#4\e(B . ?4) | |
132 | (?\e$B#5\e(B . ?5) (?\e$B#6\e(B . ?6) (?\e$B#7\e(B . ?7) (?\e$B#8\e(B . ?8) (?\e$B#9\e(B . ?9) | |
a1506d29 | 133 | (?\e$B#A\e(B . ?A) (?\e$B#B\e(B . ?B) (?\e$B#C\e(B . ?C) (?\e$B#D\e(B . ?D) (?\e$B#E\e(B . ?E) |
4ed46869 KH |
134 | (?\e$B#F\e(B . ?F) (?\e$B#G\e(B . ?G) (?\e$B#H\e(B . ?H) (?\e$B#I\e(B . ?I) (?\e$B#J\e(B . ?J) |
135 | (?\e$B#K\e(B . ?K) (?\e$B#L\e(B . ?L) (?\e$B#M\e(B . ?M) (?\e$B#N\e(B . ?N) (?\e$B#O\e(B . ?O) | |
136 | (?\e$B#P\e(B . ?P) (?\e$B#Q\e(B . ?Q) (?\e$B#R\e(B . ?R) (?\e$B#S\e(B . ?S) (?\e$B#T\e(B . ?T) | |
137 | (?\e$B#U\e(B . ?U) (?\e$B#V\e(B . ?V) (?\e$B#W\e(B . ?W) (?\e$B#X\e(B . ?X) (?\e$B#Y\e(B . ?Y) (?\e$B#Z\e(B . ?Z) | |
138 | (?\e$B#a\e(B . ?a) (?\e$B#b\e(B . ?b) (?\e$B#c\e(B . ?c) (?\e$B#d\e(B . ?d) (?\e$B#e\e(B . ?e) | |
139 | (?\e$B#f\e(B . ?f) (?\e$B#g\e(B . ?g) (?\e$B#h\e(B . ?h) (?\e$B#i\e(B . ?i) (?\e$B#j\e(B . ?j) | |
140 | (?\e$B#k\e(B . ?k) (?\e$B#l\e(B . ?l) (?\e$B#m\e(B . ?m) (?\e$B#n\e(B . ?n) (?\e$B#o\e(B . ?o) | |
141 | (?\e$B#p\e(B . ?p) (?\e$B#q\e(B . ?q) (?\e$B#r\e(B . ?r) (?\e$B#s\e(B . ?s) (?\e$B#t\e(B . ?t) | |
142 | (?\e$B#u\e(B . ?u) (?\e$B#v\e(B . ?v) (?\e$B#w\e(B . ?w) (?\e$B#x\e(B . ?x) (?\e$B#y\e(B . ?y) (?\e$B#z\e(B . ?z)) | |
143 | "Japanese JISX0208 alpha numeric character table. | |
144 | Each element is of the form (ALPHA-NUMERIC ASCII), where ALPHA-NUMERIC | |
145 | belongs to `japanese-jisx0208', ASCII belongs to `ascii'.") | |
146 | ||
147 | ;; Put properties 'jisx0208 and 'ascii to each Japanese alpha numeric | |
148 | ;; and ASCII characters for conversion between them. | |
149 | (let ((l japanese-alpha-numeric-table) | |
150 | slot jisx0208 ascii) | |
151 | (while l | |
152 | (setq slot (car l) | |
153 | jisx0208 (car slot) ascii (cdr slot) | |
154 | l (cdr l)) | |
155 | (put-char-code-property jisx0208 'ascii ascii) | |
156 | (put-char-code-property ascii 'jisx0208 jisx0208))) | |
157 | ||
158 | ;; Convert string STR by FUNC and return a resulting string. | |
159 | (defun japanese-string-conversion (str func &rest args) | |
160 | (let ((buf (get-buffer-create " *Japanese work*"))) | |
161 | (save-excursion | |
162 | (set-buffer buf) | |
163 | (erase-buffer) | |
164 | (insert str) | |
165 | (apply func 1 (point) args) | |
166 | (buffer-string)))) | |
167 | ||
168 | ;;;###autoload | |
169 | (defun japanese-katakana (obj &optional hankaku) | |
170 | "Convert argument to Katakana and return that. | |
171 | The argument may be a character or string. The result has the same type. | |
172 | The argument object is not altered--the value is a copy. | |
173 | Optional argument HANKAKU t means to convert to `hankaku' Katakana | |
174 | \(`japanese-jisx0201-kana'), in which case return value | |
175 | may be a string even if OBJ is a character if two Katakanas are | |
176 | necessary to represent OBJ." | |
177 | (if (stringp obj) | |
178 | (japanese-string-conversion obj 'japanese-katakana-region hankaku) | |
179 | (or (get-char-code-property obj (if hankaku 'jisx0201 'katakana)) | |
180 | obj))) | |
181 | ||
182 | ;;;###autoload | |
183 | (defun japanese-hiragana (obj) | |
184 | "Convert argument to Hiragana and return that. | |
185 | The argument may be a character or string. The result has the same type. | |
186 | The argument object is not altered--the value is a copy." | |
187 | (if (stringp obj) | |
188 | (japanese-string-conversion obj 'japanese-hiragana-region) | |
189 | (or (get-char-code-property obj 'hiragana) | |
190 | obj))) | |
191 | ||
192 | ;;;###autoload | |
193 | (defun japanese-hankaku (obj &optional ascii-only) | |
194 | "Convert argument to `hankaku' and return that. | |
195 | The argument may be a character or string. The result has the same type. | |
196 | The argument object is not altered--the value is a copy. | |
197 | Optional argument ASCII-ONLY non-nil means to return only ASCII character." | |
198 | (if (stringp obj) | |
199 | (japanese-string-conversion obj 'japanese-hankaku-region ascii-only) | |
c79cb283 | 200 | (or (and (not ascii-only) |
4ed46869 | 201 | (get-char-code-property obj 'jisx0201)) |
c79cb283 | 202 | (get-char-code-property obj 'ascii) |
4ed46869 KH |
203 | obj))) |
204 | ||
205 | ;;;###autoload | |
206 | (defun japanese-zenkaku (obj) | |
207 | "Convert argument to `zenkaku' and return that. | |
208 | The argument may be a character or string. The result has the same type. | |
209 | The argument object is not altered--the value is a copy." | |
210 | (if (stringp obj) | |
211 | (japanese-string-conversion obj 'japanese-zenkaku-region) | |
212 | (or (get-char-code-property obj 'jisx0208) | |
213 | obj))) | |
214 | ||
b2ba2dc0 KH |
215 | (defun japanese-replace-region (from to string) |
216 | "Replace the region specified by FROM and TO to STRING." | |
217 | (goto-char from) | |
218 | (insert string) | |
219 | (delete-char (- to from))) | |
220 | ||
4ed46869 KH |
221 | ;;;###autoload |
222 | (defun japanese-katakana-region (from to &optional hankaku) | |
223 | "Convert Japanese `hiragana' chars in the region to `katakana' chars. | |
224 | Optional argument HANKAKU t means to convert to `hankaku katakana' character | |
225 | of which charset is `japanese-jisx0201-kana'." | |
226 | (interactive "r\nP") | |
227 | (save-restriction | |
228 | (narrow-to-region from to) | |
b2ba2dc0 KH |
229 | (save-excursion |
230 | (goto-char (point-min)) | |
231 | (while (re-search-forward "\\cH\\|\\cK" nil t) | |
232 | (let* ((kana (preceding-char)) | |
fbc7bbf7 KH |
233 | (composition |
234 | (and (not hankaku) | |
235 | (get-char-code-property kana 'kana-composition))) | |
b2ba2dc0 KH |
236 | next slot) |
237 | (if (and composition (setq slot (assq (following-char) composition))) | |
238 | (japanese-replace-region (match-beginning 0) (1+ (point)) | |
239 | (cdr slot)) | |
240 | (let ((kata (get-char-code-property | |
241 | kana (if hankaku 'jisx0201 'katakana)))) | |
242 | (if kata | |
243 | (japanese-replace-region (match-beginning 0) (point) | |
244 | kata))))))))) | |
245 | ||
4ed46869 KH |
246 | |
247 | ;;;###autoload | |
248 | (defun japanese-hiragana-region (from to) | |
33366a82 | 249 | "Convert Japanese `katakana' chars in the region to `hiragana' chars." |
4ed46869 KH |
250 | (interactive "r") |
251 | (save-restriction | |
252 | (narrow-to-region from to) | |
b2ba2dc0 KH |
253 | (save-excursion |
254 | (goto-char (point-min)) | |
255 | (while (re-search-forward "\\cK\\|\\ck" nil t) | |
256 | (let* ((kata (preceding-char)) | |
257 | (composition (get-char-code-property kata 'kana-composition)) | |
258 | next slot) | |
259 | (if (and composition (setq slot (assq (following-char) composition))) | |
260 | (japanese-replace-region (match-beginning 0) (1+ (point)) | |
261 | (get-char-code-property | |
262 | (cdr slot) 'hiragana)) | |
263 | (let ((hira (get-char-code-property kata 'hiragana))) | |
264 | (if hira | |
265 | (japanese-replace-region (match-beginning 0) (point) | |
266 | hira))))))))) | |
4ed46869 KH |
267 | |
268 | ;;;###autoload | |
269 | (defun japanese-hankaku-region (from to &optional ascii-only) | |
270 | "Convert Japanese `zenkaku' chars in the region to `hankaku' chars. | |
271 | `Zenkaku' chars belong to `japanese-jisx0208' | |
272 | `Hankaku' chars belong to `ascii' or `japanese-jisx0201-kana'. | |
273 | Optional argument ASCII-ONLY non-nil means to convert only to ASCII char." | |
274 | (interactive "r\nP") | |
275 | (save-restriction | |
276 | (narrow-to-region from to) | |
b2ba2dc0 KH |
277 | (save-excursion |
278 | (goto-char (point-min)) | |
279 | (while (re-search-forward "\\cj" nil t) | |
280 | (let* ((zenkaku (preceding-char)) | |
c79cb283 GM |
281 | (hankaku (or (and (not ascii-only) |
282 | (get-char-code-property zenkaku 'jisx0201)) | |
283 | (get-char-code-property zenkaku 'ascii)))) | |
b2ba2dc0 KH |
284 | (if hankaku |
285 | (japanese-replace-region (match-beginning 0) (match-end 0) | |
286 | hankaku))))))) | |
4ed46869 KH |
287 | |
288 | ;;;###autoload | |
b194460e | 289 | (defun japanese-zenkaku-region (from to &optional katakana-only) |
4ed46869 KH |
290 | "Convert hankaku' chars in the region to Japanese `zenkaku' chars. |
291 | `Zenkaku' chars belong to `japanese-jisx0208' | |
b194460e KH |
292 | `Hankaku' chars belong to `ascii' or `japanese-jisx0201-kana'. |
293 | Optional argument KATAKANA-ONLY non-nil means to convert only KATAKANA char." | |
294 | (interactive "r\nP") | |
4ed46869 KH |
295 | (save-restriction |
296 | (narrow-to-region from to) | |
b2ba2dc0 KH |
297 | (save-excursion |
298 | (goto-char (point-min)) | |
b194460e KH |
299 | (while (or (and katakana-only |
300 | (re-search-forward "\\ck" nil t)) | |
301 | (and (not katakana-only) | |
302 | (re-search-forward "\\ca\\|\\ck" nil t))) | |
b2ba2dc0 KH |
303 | (let* ((hankaku (preceding-char)) |
304 | (composition (get-char-code-property hankaku 'kana-composition)) | |
305 | next slot) | |
306 | (if (and composition (setq slot (assq (following-char) composition))) | |
307 | (japanese-replace-region (match-beginning 0) (1+ (point)) | |
308 | (cdr slot)) | |
309 | (let ((zenkaku (japanese-zenkaku hankaku))) | |
310 | (if zenkaku | |
311 | (japanese-replace-region (match-beginning 0) (match-end 0) | |
312 | zenkaku))))))))) | |
4ed46869 KH |
313 | |
314 | ;;;###autoload | |
315 | (defun read-hiragana-string (prompt &optional initial-input) | |
316 | "Read a Hiragana string from the minibuffer, prompting with string PROMPT. | |
317 | If non-nil, second arg INITIAL-INPUT is a string to insert before reading." | |
a6385fa9 | 318 | (read-multilingual-string prompt initial-input "japanese-hiragana")) |
4ed46869 KH |
319 | |
320 | ;; | |
650e8505 | 321 | (provide 'japan-util) |
4ed46869 | 322 | |
ab5796a9 | 323 | ;;; arch-tag: b579595c-c9ad-4b57-9314-98cd8b214f89 |
4ed46869 | 324 | ;;; japan-util.el ends here |