Commit | Line | Data |
---|---|---|
60370d40 | 1 | ;;; japan-util.el --- utilities for Japanese -*- coding: iso-2022-7bit; -*- |
4ed46869 | 2 | |
95df8112 | 3 | ;; Copyright (C) 2001-2011 Free Software Foundation, Inc. |
7976eda0 | 4 | ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
5df4f04c | 5 | ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
eaa61218 KH |
6 | ;; National Institute of Advanced Industrial Science and Technology (AIST) |
7 | ;; Registration Number H14PRO021 | |
4ed46869 KH |
8 | |
9 | ;; Keywords: mule, multilingual, Japanese | |
10 | ||
11 | ;; This file is part of GNU Emacs. | |
12 | ||
4936186e | 13 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
4ed46869 | 14 | ;; it under the terms of the GNU General Public License as published by |
4936186e GM |
15 | ;; the Free Software Foundation, either version 3 of the License, or |
16 | ;; (at your option) any later version. | |
4ed46869 KH |
17 | |
18 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | ;; GNU General Public License for more details. | |
22 | ||
23 | ;; You should have received a copy of the GNU General Public License | |
4936186e | 24 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
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 | 35 | (prefer-coding-system 'japanese-shift-jis) |
faf9aa0a | 36 | (prefer-coding-system 'japanese-iso-8bit)) |
99b070c5 | 37 | (use-cjk-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(?\e$B$e\e(B ?\e$B%e\e(B ?\e(I-\e(B) (?\e$B$g\e(B ?\e$B%g\e(B ?\e(I.\e(B) | |
33366a82 KH |
59 | (?\e$B$n\e(B ?\e$B%n\e(B "\e(I\\e(B") |
60 | ("\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 |
61 | "Japanese JISX0208 Kana character table. |
62 | Each element is of the form (HIRAGANA KATAKANA HANKAKU-KATAKANA), where | |
63 | HIRAGANA and KATAKANA belong to `japanese-jisx0208', | |
64 | HANKAKU-KATAKANA belongs to `japanese-jisx0201-kana'.") | |
65 | ||
66 | ;; Put properties 'katakana, 'hiragana, and 'jix0201 to each Japanese | |
67 | ;; kana characters for conversion among them. | |
68 | (let ((l japanese-kana-table) | |
69 | slot hiragana katakana jisx0201) | |
70 | (while l | |
71 | (setq slot (car l) | |
72 | hiragana (car slot) katakana (nth 1 slot) jisx0201 (nth 2 slot) | |
73 | l (cdr l)) | |
74 | (if hiragana | |
33366a82 KH |
75 | (if (stringp hiragana) |
76 | (if (> (length hiragana) 1) | |
77 | (let ((hira (aref hiragana 0))) | |
78 | (put-char-code-property | |
b2ba2dc0 | 79 | hira 'kana-composition |
33366a82 | 80 | (cons (cons (aref hiragana 1) katakana) |
b2ba2dc0 | 81 | (get-char-code-property hira 'kana-composition))))) |
4ed46869 | 82 | (put-char-code-property hiragana 'katakana katakana) |
33366a82 KH |
83 | (put-char-code-property hiragana 'jisx0201 jisx0201))) |
84 | (when (integerp katakana) | |
85 | (put-char-code-property katakana 'hiragana hiragana) | |
86 | (put-char-code-property katakana 'jisx0201 jisx0201)) | |
4ed46869 | 87 | (if jisx0201 |
33366a82 KH |
88 | (if (stringp jisx0201) |
89 | (if (> (length jisx0201) 1) | |
90 | (let ((kana (aref jisx0201 0))) | |
91 | (put-char-code-property | |
b2ba2dc0 | 92 | kana 'kana-composition |
33366a82 | 93 | (cons (cons (aref jisx0201 1) katakana) |
b2ba2dc0 | 94 | (get-char-code-property kana 'kana-composition))))) |
33366a82 KH |
95 | (put-char-code-property jisx0201 'hiragana hiragana) |
96 | (put-char-code-property jisx0201 'katakana katakana) | |
97 | (put-char-code-property jisx0201 'jisx0208 katakana))))) | |
4ed46869 KH |
98 | |
99 | (defconst japanese-symbol-table | |
33366a82 | 100 | '((?\\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 | 101 | (?\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 | 102 | (?\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 |
103 | (?\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 ?\") |
104 | (?\\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 |
105 | (?\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) |
106 | (?\e$B!\\e(B ?+) (?\e$B!]\e(B ?-) (?\e$B!a\e(B ?=) (?\e$B!c\e(B ?<) (?\e$B!d\e(B ?>) | |
4ed46869 | 107 | (?\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 ?*) |
1339cf20 KH |
108 | (?\e$B!w\e(B ?@) |
109 | ;; cp932-2-byte | |
110 | (#x2015 ?-) (#xFF5E ?~) (#xFF0D ?-)) | |
bf89fd7b | 111 | "Japanese JISX0208 and CP932 symbol character table. |
4ed46869 | 112 | Each element is of the form (SYMBOL ASCII HANKAKU), where SYMBOL |
bf89fd7b KH |
113 | belongs to `japanese-jisx0208' or `cp932', ASCII belongs to `ascii', |
114 | and HANKAKU belongs to `japanese-jisx0201-kana'.") | |
4ed46869 KH |
115 | |
116 | ;; Put properties 'jisx0208, 'jisx0201, and 'ascii to each Japanese | |
117 | ;; symbol and ASCII characters for conversion among them. | |
118 | (let ((l japanese-symbol-table) | |
119 | slot jisx0208 ascii jisx0201) | |
120 | (while l | |
121 | (setq slot (car l) | |
122 | jisx0208 (car slot) ascii (nth 1 slot) jisx0201 (nth 2 slot) | |
123 | l (cdr l)) | |
124 | (if ascii | |
125 | (progn | |
126 | (put-char-code-property jisx0208 'ascii ascii) | |
bf89fd7b KH |
127 | (if (encode-char jisx0208 'japanese-jisx0208) |
128 | (put-char-code-property ascii 'jisx0208 jisx0208)))) | |
4ed46869 KH |
129 | (if jisx0201 |
130 | (progn | |
131 | (put-char-code-property jisx0208 'jisx0201 jisx0201) | |
bf89fd7b KH |
132 | (if (encode-char jisx0208 'japanese-jisx0208) |
133 | (put-char-code-property jisx0201 'jisx0208 jisx0208)))))) | |
4ed46869 KH |
134 | |
135 | (defconst japanese-alpha-numeric-table | |
136 | '((?\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) | |
137 | (?\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 | 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) |
4ed46869 KH |
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 | (?\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) | |
144 | (?\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) | |
145 | (?\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) | |
146 | (?\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) | |
147 | (?\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)) | |
148 | "Japanese JISX0208 alpha numeric character table. | |
149 | Each element is of the form (ALPHA-NUMERIC ASCII), where ALPHA-NUMERIC | |
150 | belongs to `japanese-jisx0208', ASCII belongs to `ascii'.") | |
151 | ||
152 | ;; Put properties 'jisx0208 and 'ascii to each Japanese alpha numeric | |
153 | ;; and ASCII characters for conversion between them. | |
154 | (let ((l japanese-alpha-numeric-table) | |
155 | slot jisx0208 ascii) | |
156 | (while l | |
157 | (setq slot (car l) | |
158 | jisx0208 (car slot) ascii (cdr slot) | |
159 | l (cdr l)) | |
160 | (put-char-code-property jisx0208 'ascii ascii) | |
161 | (put-char-code-property ascii 'jisx0208 jisx0208))) | |
162 | ||
163 | ;; Convert string STR by FUNC and return a resulting string. | |
164 | (defun japanese-string-conversion (str func &rest args) | |
165 | (let ((buf (get-buffer-create " *Japanese work*"))) | |
9a529312 | 166 | (with-current-buffer buf |
4ed46869 KH |
167 | (erase-buffer) |
168 | (insert str) | |
169 | (apply func 1 (point) args) | |
170 | (buffer-string)))) | |
171 | ||
172 | ;;;###autoload | |
173 | (defun japanese-katakana (obj &optional hankaku) | |
174 | "Convert argument to Katakana and return that. | |
175 | The argument may be a character or string. The result has the same type. | |
176 | The argument object is not altered--the value is a copy. | |
177 | Optional argument HANKAKU t means to convert to `hankaku' Katakana | |
178 | \(`japanese-jisx0201-kana'), in which case return value | |
179 | may be a string even if OBJ is a character if two Katakanas are | |
180 | necessary to represent OBJ." | |
181 | (if (stringp obj) | |
182 | (japanese-string-conversion obj 'japanese-katakana-region hankaku) | |
183 | (or (get-char-code-property obj (if hankaku 'jisx0201 'katakana)) | |
184 | obj))) | |
185 | ||
186 | ;;;###autoload | |
187 | (defun japanese-hiragana (obj) | |
188 | "Convert argument to Hiragana and return that. | |
189 | The argument may be a character or string. The result has the same type. | |
190 | The argument object is not altered--the value is a copy." | |
191 | (if (stringp obj) | |
192 | (japanese-string-conversion obj 'japanese-hiragana-region) | |
193 | (or (get-char-code-property obj 'hiragana) | |
194 | obj))) | |
195 | ||
196 | ;;;###autoload | |
197 | (defun japanese-hankaku (obj &optional ascii-only) | |
198 | "Convert argument to `hankaku' and return that. | |
199 | The argument may be a character or string. The result has the same type. | |
200 | The argument object is not altered--the value is a copy. | |
201 | Optional argument ASCII-ONLY non-nil means to return only ASCII character." | |
202 | (if (stringp obj) | |
203 | (japanese-string-conversion obj 'japanese-hankaku-region ascii-only) | |
c79cb283 | 204 | (or (and (not ascii-only) |
4ed46869 | 205 | (get-char-code-property obj 'jisx0201)) |
c79cb283 | 206 | (get-char-code-property obj 'ascii) |
4ed46869 KH |
207 | obj))) |
208 | ||
209 | ;;;###autoload | |
210 | (defun japanese-zenkaku (obj) | |
211 | "Convert argument to `zenkaku' and return that. | |
212 | The argument may be a character or string. The result has the same type. | |
213 | The argument object is not altered--the value is a copy." | |
214 | (if (stringp obj) | |
215 | (japanese-string-conversion obj 'japanese-zenkaku-region) | |
216 | (or (get-char-code-property obj 'jisx0208) | |
217 | obj))) | |
218 | ||
b2ba2dc0 KH |
219 | (defun japanese-replace-region (from to string) |
220 | "Replace the region specified by FROM and TO to STRING." | |
221 | (goto-char from) | |
222 | (insert string) | |
223 | (delete-char (- to from))) | |
224 | ||
4ed46869 KH |
225 | ;;;###autoload |
226 | (defun japanese-katakana-region (from to &optional hankaku) | |
227 | "Convert Japanese `hiragana' chars in the region to `katakana' chars. | |
228 | Optional argument HANKAKU t means to convert to `hankaku katakana' character | |
229 | of which charset is `japanese-jisx0201-kana'." | |
230 | (interactive "r\nP") | |
231 | (save-restriction | |
232 | (narrow-to-region from to) | |
b2ba2dc0 KH |
233 | (save-excursion |
234 | (goto-char (point-min)) | |
235 | (while (re-search-forward "\\cH\\|\\cK" nil t) | |
236 | (let* ((kana (preceding-char)) | |
fbc7bbf7 KH |
237 | (composition |
238 | (and (not hankaku) | |
239 | (get-char-code-property kana 'kana-composition))) | |
b2ba2dc0 KH |
240 | next slot) |
241 | (if (and composition (setq slot (assq (following-char) composition))) | |
242 | (japanese-replace-region (match-beginning 0) (1+ (point)) | |
243 | (cdr slot)) | |
244 | (let ((kata (get-char-code-property | |
245 | kana (if hankaku 'jisx0201 'katakana)))) | |
246 | (if kata | |
247 | (japanese-replace-region (match-beginning 0) (point) | |
248 | kata))))))))) | |
249 | ||
4ed46869 KH |
250 | |
251 | ;;;###autoload | |
252 | (defun japanese-hiragana-region (from to) | |
33366a82 | 253 | "Convert Japanese `katakana' chars in the region to `hiragana' chars." |
4ed46869 KH |
254 | (interactive "r") |
255 | (save-restriction | |
256 | (narrow-to-region from to) | |
b2ba2dc0 KH |
257 | (save-excursion |
258 | (goto-char (point-min)) | |
259 | (while (re-search-forward "\\cK\\|\\ck" nil t) | |
260 | (let* ((kata (preceding-char)) | |
261 | (composition (get-char-code-property kata 'kana-composition)) | |
262 | next slot) | |
263 | (if (and composition (setq slot (assq (following-char) composition))) | |
264 | (japanese-replace-region (match-beginning 0) (1+ (point)) | |
265 | (get-char-code-property | |
266 | (cdr slot) 'hiragana)) | |
267 | (let ((hira (get-char-code-property kata 'hiragana))) | |
268 | (if hira | |
269 | (japanese-replace-region (match-beginning 0) (point) | |
270 | hira))))))))) | |
4ed46869 KH |
271 | |
272 | ;;;###autoload | |
273 | (defun japanese-hankaku-region (from to &optional ascii-only) | |
274 | "Convert Japanese `zenkaku' chars in the region to `hankaku' chars. | |
275 | `Zenkaku' chars belong to `japanese-jisx0208' | |
276 | `Hankaku' chars belong to `ascii' or `japanese-jisx0201-kana'. | |
277 | Optional argument ASCII-ONLY non-nil means to convert only to ASCII char." | |
278 | (interactive "r\nP") | |
279 | (save-restriction | |
280 | (narrow-to-region from to) | |
b2ba2dc0 KH |
281 | (save-excursion |
282 | (goto-char (point-min)) | |
283 | (while (re-search-forward "\\cj" nil t) | |
284 | (let* ((zenkaku (preceding-char)) | |
c79cb283 GM |
285 | (hankaku (or (and (not ascii-only) |
286 | (get-char-code-property zenkaku 'jisx0201)) | |
287 | (get-char-code-property zenkaku 'ascii)))) | |
b2ba2dc0 KH |
288 | (if hankaku |
289 | (japanese-replace-region (match-beginning 0) (match-end 0) | |
290 | hankaku))))))) | |
4ed46869 KH |
291 | |
292 | ;;;###autoload | |
b194460e | 293 | (defun japanese-zenkaku-region (from to &optional katakana-only) |
4ed46869 KH |
294 | "Convert hankaku' chars in the region to Japanese `zenkaku' chars. |
295 | `Zenkaku' chars belong to `japanese-jisx0208' | |
b194460e KH |
296 | `Hankaku' chars belong to `ascii' or `japanese-jisx0201-kana'. |
297 | Optional argument KATAKANA-ONLY non-nil means to convert only KATAKANA char." | |
298 | (interactive "r\nP") | |
4ed46869 KH |
299 | (save-restriction |
300 | (narrow-to-region from to) | |
b2ba2dc0 KH |
301 | (save-excursion |
302 | (goto-char (point-min)) | |
b194460e KH |
303 | (while (or (and katakana-only |
304 | (re-search-forward "\\ck" nil t)) | |
305 | (and (not katakana-only) | |
306 | (re-search-forward "\\ca\\|\\ck" nil t))) | |
b2ba2dc0 KH |
307 | (let* ((hankaku (preceding-char)) |
308 | (composition (get-char-code-property hankaku 'kana-composition)) | |
309 | next slot) | |
310 | (if (and composition (setq slot (assq (following-char) composition))) | |
311 | (japanese-replace-region (match-beginning 0) (1+ (point)) | |
312 | (cdr slot)) | |
313 | (let ((zenkaku (japanese-zenkaku hankaku))) | |
314 | (if zenkaku | |
315 | (japanese-replace-region (match-beginning 0) (match-end 0) | |
316 | zenkaku))))))))) | |
4ed46869 KH |
317 | |
318 | ;;;###autoload | |
319 | (defun read-hiragana-string (prompt &optional initial-input) | |
320 | "Read a Hiragana string from the minibuffer, prompting with string PROMPT. | |
321 | If non-nil, second arg INITIAL-INPUT is a string to insert before reading." | |
a6385fa9 | 322 | (read-multilingual-string prompt initial-input "japanese-hiragana")) |
4ed46869 KH |
323 | |
324 | ;; | |
650e8505 | 325 | (provide 'japan-util) |
4ed46869 | 326 | |
4ed46869 | 327 | ;;; japan-util.el ends here |