Mercurial > emacs
annotate lisp/language/japan-util.el @ 94038:a66451222c6a
(Fexpand_file_name): Add declaration for `p' missing in previous change.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Sat, 12 Apr 2008 09:13:14 +0000 |
parents | 1e3a407766b9 |
children | 55b7f25d920a |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37913
diff
changeset
|
1 ;;; japan-util.el --- utilities for Japanese -*- coding: iso-2022-7bit; -*- |
17052 | 2 |
79711 | 3 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
74544 | 4 ;; Free Software Foundation, Inc. |
74605
6ee41fdd69ff
Update AIST copyright years.
Kenichi Handa <handa@m17n.org>
parents:
74544
diff
changeset
|
5 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
79711 | 6 ;; 2005, 2006, 2007, 2008 |
62396 | 7 ;; National Institute of Advanced Industrial Science and Technology (AIST) |
8 ;; Registration Number H14PRO021 | |
17052 | 9 |
10 ;; Keywords: mule, multilingual, Japanese | |
11 | |
12 ;; This file is part of GNU Emacs. | |
13 | |
14 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
15 ;; it under the terms of the GNU General Public License as published by | |
78309
0938de05f510
Restore comma mistakenly removed in last change.
Glenn Morris <rgm@gnu.org>
parents:
78300
diff
changeset
|
16 ;; the Free Software Foundation; either version 3, or (at your option) |
17052 | 17 ;; any later version. |
18 | |
19 ;; GNU Emacs is distributed in the hope that it will be useful, | |
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 ;; GNU General Public License for more details. | |
23 | |
24 ;; You should have received a copy of the GNU General Public License | |
17071 | 25 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64085 | 26 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
27 ;; Boston, MA 02110-1301, USA. | |
17052 | 28 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37913
diff
changeset
|
29 ;;; Commentary: |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37913
diff
changeset
|
30 |
17052 | 31 ;;; Code: |
32 | |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
33 ;;;###autoload |
22987
708271862495
(setup-XXX-environment): Just call set-language-environment. If
Kenichi Handa <handa@m17n.org>
parents:
22776
diff
changeset
|
34 (defun setup-japanese-environment-internal () |
50089
f302927f8302
(setup-japanese-environment-internal):
Kenichi Handa <handa@m17n.org>
parents:
50007
diff
changeset
|
35 ;; By default, we use 'japanese-iso-8bit for file names. But, the |
f302927f8302
(setup-japanese-environment-internal):
Kenichi Handa <handa@m17n.org>
parents:
50007
diff
changeset
|
36 ;; following prefer-coding-system will override it. |
50091
e43f492e9944
(setup-japanese-environment-internal): Prefer japanese-shift-jis on
Kenichi Handa <handa@m17n.org>
parents:
50089
diff
changeset
|
37 (if (memq system-type '(windows-nt ms-dos cygwin)) |
50334
04c0558bea4f
If system-type is not for Windows, prefer japanese-iso-8bit.
Kenichi Handa <handa@m17n.org>
parents:
50091
diff
changeset
|
38 (prefer-coding-system 'japanese-shift-jis) |
91935
0e222c52ad00
(setup-japanese-environment-internal):
Kenichi Handa <handa@m17n.org>
parents:
79711
diff
changeset
|
39 (prefer-coding-system 'japanese-iso-8bit)) |
0e222c52ad00
(setup-japanese-environment-internal):
Kenichi Handa <handa@m17n.org>
parents:
79711
diff
changeset
|
40 (use-cjk-char-width-table)) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
41 |
17052 | 42 (defconst japanese-kana-table |
43 '((?$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) | |
44 (?$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) | |
45 (?$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) | |
46 (?$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) | |
47 (?$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) | |
48 (?$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) | |
49 (?$B$^(B ?$B%^(B ?(IO(B) (?$B$_(B ?$B%_(B ?(IP(B) (?$B$`(B ?$B%`(B ?(IQ(B) (?$B$a(B ?$B%a(B ?(IR(B) (?$B$b(B ?$B%b(B ?(IS(B) | |
50 (?$B$d(B ?$B%d(B ?(IT(B) (?$B$f(B ?$B%f(B ?(IU(B) (?$B$h(B ?$B%h(B ?(IV(B) | |
51 (?$B$i(B ?$B%i(B ?(IW(B) (?$B$j(B ?$B%j(B ?(IX(B) (?$B$k(B ?$B%k(B ?(IY(B) (?$B$l(B ?$B%l(B ?(IZ(B) (?$B$m(B ?$B%m(B ?(I[(B) | |
22548
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
52 (?$B$o(B ?$B%o(B ?(I\(B) (?$B$p(B ?$B%p(B "(I2(B") (?$B$q(B ?$B%q(B "(I4(B") (?$B$r(B ?$B%r(B ?(I&(B) |
17052 | 53 (?$B$s(B ?$B%s(B ?(I](B) |
54 (?$B$,(B ?$B%,(B "(I6^(B") (?$B$.(B ?$B%.(B "(I7^(B") (?$B$0(B ?$B%0(B "(I8^(B") (?$B$2(B ?$B%2(B "(I9^(B") (?$B$4(B ?$B%4(B "(I:^(B") | |
55 (?$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") | |
56 (?$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") | |
57 (?$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") | |
58 (?$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") | |
59 (?$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) | |
60 (?$B$C(B ?$B%C(B ?(I/(B) | |
61 (?$B$c(B ?$B%c(B ?(I,(B) (?$B$e(B ?$B%e(B ?(I-(B) (?$B$g(B ?$B%g(B ?(I.(B) | |
22548
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
62 (?$B$n(B ?$B%n(B "(I\(B") |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
63 ("$B$&!+(B" ?$B%t(B "(I3^(B") (nil ?$B%u(B "(I6(B") (nil ?$B%v(B "(I9(B")) |
17052 | 64 "Japanese JISX0208 Kana character table. |
65 Each element is of the form (HIRAGANA KATAKANA HANKAKU-KATAKANA), where | |
66 HIRAGANA and KATAKANA belong to `japanese-jisx0208', | |
67 HANKAKU-KATAKANA belongs to `japanese-jisx0201-kana'.") | |
68 | |
69 ;; Put properties 'katakana, 'hiragana, and 'jix0201 to each Japanese | |
70 ;; kana characters for conversion among them. | |
71 (let ((l japanese-kana-table) | |
72 slot hiragana katakana jisx0201) | |
73 (while l | |
74 (setq slot (car l) | |
75 hiragana (car slot) katakana (nth 1 slot) jisx0201 (nth 2 slot) | |
76 l (cdr l)) | |
77 (if hiragana | |
22548
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
78 (if (stringp hiragana) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
79 (if (> (length hiragana) 1) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
80 (let ((hira (aref hiragana 0))) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
81 (put-char-code-property |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
82 hira 'kana-composition |
22548
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
83 (cons (cons (aref hiragana 1) katakana) |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
84 (get-char-code-property hira 'kana-composition))))) |
17052 | 85 (put-char-code-property hiragana 'katakana katakana) |
22548
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
86 (put-char-code-property hiragana 'jisx0201 jisx0201))) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
87 (when (integerp katakana) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
88 (put-char-code-property katakana 'hiragana hiragana) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
89 (put-char-code-property katakana 'jisx0201 jisx0201)) |
17052 | 90 (if jisx0201 |
22548
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
91 (if (stringp jisx0201) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
92 (if (> (length jisx0201) 1) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
93 (let ((kana (aref jisx0201 0))) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
94 (put-char-code-property |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
95 kana 'kana-composition |
22548
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
96 (cons (cons (aref jisx0201 1) katakana) |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
97 (get-char-code-property kana 'kana-composition))))) |
22548
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
98 (put-char-code-property jisx0201 'hiragana hiragana) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
99 (put-char-code-property jisx0201 'katakana katakana) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
100 (put-char-code-property jisx0201 'jisx0208 katakana))))) |
17052 | 101 |
102 (defconst japanese-symbol-table | |
22548
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
103 '((?\$B!!(B ?\ ) (?$B!$(B ?, ?(I$(B) (?$B!%(B ?. ?(I!(B) (?$B!"(B ?, ?(I$(B) (?$B!#(B ?. ?(I!(B) (?$B!&(B nil ?(I%(B) |
17052 | 104 (?$B!'(B ?:) (?$B!((B ?\;) (?$B!)(B ??) (?$B!*(B ?!) (?$B!+(B nil ?(I^(B) (?$B!,(B nil ?(I_(B) |
37871
dfd29e68d398
(japanese-symbol-table): Fix handling of
Gerd Moellmann <gerd@gnu.org>
parents:
36683
diff
changeset
|
105 (?$B!-(B ?') (?$B!.(B ?`) (?$B!0(B ?^) (?$B!2(B ?_) (?$B!<(B ?- ?(I0(B) (?$B!=(B ?-) (?$B!>(B ?-) |
17052 | 106 (?$B!?(B ?/) (?$B!@(B ?\\) (?$B!A(B ?~) (?$B!C(B ?|) (?$B!F(B ?`) (?$B!G(B ?') (?$B!H(B ?\") (?$B!I(B ?\") |
107 (?\$B!J(B ?\() (?\$B!K(B ?\)) (?\$B!N(B ?[) (?\$B!O(B ?]) (?\$B!P(B ?{) (?\$B!Q(B ?}) | |
50007
10bcbf340393
(japanese-symbol-table): Add two entries to make it complete.
Kenichi Handa <handa@m17n.org>
parents:
49947
diff
changeset
|
108 (?$B!R(B ?<) (?$B!S(B ?>) (?\$B!V(B nil ?\(I"(B) (?\$B!W(B nil ?\(I#(B) |
10bcbf340393
(japanese-symbol-table): Add two entries to make it complete.
Kenichi Handa <handa@m17n.org>
parents:
49947
diff
changeset
|
109 (?$B!\(B ?+) (?$B!](B ?-) (?$B!a(B ?=) (?$B!c(B ?<) (?$B!d(B ?>) |
17052 | 110 (?$B!l(B ?') (?$B!m(B ?\") (?$B!o(B ?\\) (?$B!p(B ?$) (?$B!s(B ?%) (?$B!t(B ?#) (?$B!u(B ?&) (?$B!v(B ?*) |
111 (?$B!w(B ?@)) | |
112 "Japanese JISX0208 symbol character table. | |
113 Each element is of the form (SYMBOL ASCII HANKAKU), where SYMBOL | |
114 belongs to `japanese-jisx0208', ASCII belongs to `ascii', and HANKAKU | |
115 belongs to `japanese-jisx0201-kana'.") | |
116 | |
117 ;; Put properties 'jisx0208, 'jisx0201, and 'ascii to each Japanese | |
118 ;; symbol and ASCII characters for conversion among them. | |
119 (let ((l japanese-symbol-table) | |
120 slot jisx0208 ascii jisx0201) | |
121 (while l | |
122 (setq slot (car l) | |
123 jisx0208 (car slot) ascii (nth 1 slot) jisx0201 (nth 2 slot) | |
124 l (cdr l)) | |
125 (if ascii | |
126 (progn | |
127 (put-char-code-property jisx0208 'ascii ascii) | |
128 (put-char-code-property ascii 'jisx0208 jisx0208))) | |
129 (if jisx0201 | |
130 (progn | |
131 (put-char-code-property jisx0208 'jisx0201 jisx0201) | |
132 (put-char-code-property jisx0201 'jisx0208 jisx0208))))) | |
133 | |
134 (defconst japanese-alpha-numeric-table | |
135 '((?$B#0(B . ?0) (?$B#1(B . ?1) (?$B#2(B . ?2) (?$B#3(B . ?3) (?$B#4(B . ?4) | |
136 (?$B#5(B . ?5) (?$B#6(B . ?6) (?$B#7(B . ?7) (?$B#8(B . ?8) (?$B#9(B . ?9) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38414
diff
changeset
|
137 (?$B#A(B . ?A) (?$B#B(B . ?B) (?$B#C(B . ?C) (?$B#D(B . ?D) (?$B#E(B . ?E) |
17052 | 138 (?$B#F(B . ?F) (?$B#G(B . ?G) (?$B#H(B . ?H) (?$B#I(B . ?I) (?$B#J(B . ?J) |
139 (?$B#K(B . ?K) (?$B#L(B . ?L) (?$B#M(B . ?M) (?$B#N(B . ?N) (?$B#O(B . ?O) | |
140 (?$B#P(B . ?P) (?$B#Q(B . ?Q) (?$B#R(B . ?R) (?$B#S(B . ?S) (?$B#T(B . ?T) | |
141 (?$B#U(B . ?U) (?$B#V(B . ?V) (?$B#W(B . ?W) (?$B#X(B . ?X) (?$B#Y(B . ?Y) (?$B#Z(B . ?Z) | |
142 (?$B#a(B . ?a) (?$B#b(B . ?b) (?$B#c(B . ?c) (?$B#d(B . ?d) (?$B#e(B . ?e) | |
143 (?$B#f(B . ?f) (?$B#g(B . ?g) (?$B#h(B . ?h) (?$B#i(B . ?i) (?$B#j(B . ?j) | |
144 (?$B#k(B . ?k) (?$B#l(B . ?l) (?$B#m(B . ?m) (?$B#n(B . ?n) (?$B#o(B . ?o) | |
145 (?$B#p(B . ?p) (?$B#q(B . ?q) (?$B#r(B . ?r) (?$B#s(B . ?s) (?$B#t(B . ?t) | |
146 (?$B#u(B . ?u) (?$B#v(B . ?v) (?$B#w(B . ?w) (?$B#x(B . ?x) (?$B#y(B . ?y) (?$B#z(B . ?z)) | |
147 "Japanese JISX0208 alpha numeric character table. | |
148 Each element is of the form (ALPHA-NUMERIC ASCII), where ALPHA-NUMERIC | |
149 belongs to `japanese-jisx0208', ASCII belongs to `ascii'.") | |
150 | |
151 ;; Put properties 'jisx0208 and 'ascii to each Japanese alpha numeric | |
152 ;; and ASCII characters for conversion between them. | |
153 (let ((l japanese-alpha-numeric-table) | |
154 slot jisx0208 ascii) | |
155 (while l | |
156 (setq slot (car l) | |
157 jisx0208 (car slot) ascii (cdr slot) | |
158 l (cdr l)) | |
159 (put-char-code-property jisx0208 'ascii ascii) | |
160 (put-char-code-property ascii 'jisx0208 jisx0208))) | |
161 | |
162 ;; Convert string STR by FUNC and return a resulting string. | |
163 (defun japanese-string-conversion (str func &rest args) | |
164 (let ((buf (get-buffer-create " *Japanese work*"))) | |
165 (save-excursion | |
166 (set-buffer buf) | |
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) | |
37913
49a0ec256ceb
(japanese-hankaku): Prefer the charset
Gerd Moellmann <gerd@gnu.org>
parents:
37871
diff
changeset
|
204 (or (and (not ascii-only) |
17052 | 205 (get-char-code-property obj 'jisx0201)) |
37913
49a0ec256ceb
(japanese-hankaku): Prefer the charset
Gerd Moellmann <gerd@gnu.org>
parents:
37871
diff
changeset
|
206 (get-char-code-property obj 'ascii) |
17052 | 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 | |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
219 (defun japanese-replace-region (from to string) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
220 "Replace the region specified by FROM and TO to STRING." |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
221 (goto-char from) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
222 (insert string) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
223 (delete-char (- to from))) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
224 |
17052 | 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) | |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
233 (save-excursion |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
234 (goto-char (point-min)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
235 (while (re-search-forward "\\cH\\|\\cK" nil t) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
236 (let* ((kana (preceding-char)) |
30451
153802156ca9
(japanese-katakana-region): Fix handling HANKAKU argument.
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
237 (composition |
153802156ca9
(japanese-katakana-region): Fix handling HANKAKU argument.
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
238 (and (not hankaku) |
153802156ca9
(japanese-katakana-region): Fix handling HANKAKU argument.
Kenichi Handa <handa@m17n.org>
parents:
28906
diff
changeset
|
239 (get-char-code-property kana 'kana-composition))) |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
240 next slot) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
241 (if (and composition (setq slot (assq (following-char) composition))) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
242 (japanese-replace-region (match-beginning 0) (1+ (point)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
243 (cdr slot)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
244 (let ((kata (get-char-code-property |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
245 kana (if hankaku 'jisx0201 'katakana)))) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
246 (if kata |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
247 (japanese-replace-region (match-beginning 0) (point) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
248 kata))))))))) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
249 |
17052 | 250 |
251 ;;;###autoload | |
252 (defun japanese-hiragana-region (from to) | |
22548
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
253 "Convert Japanese `katakana' chars in the region to `hiragana' chars." |
17052 | 254 (interactive "r") |
255 (save-restriction | |
256 (narrow-to-region from to) | |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
257 (save-excursion |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
258 (goto-char (point-min)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
259 (while (re-search-forward "\\cK\\|\\ck" nil t) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
260 (let* ((kata (preceding-char)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
261 (composition (get-char-code-property kata 'kana-composition)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
262 next slot) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
263 (if (and composition (setq slot (assq (following-char) composition))) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
264 (japanese-replace-region (match-beginning 0) (1+ (point)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
265 (get-char-code-property |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
266 (cdr slot) 'hiragana)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
267 (let ((hira (get-char-code-property kata 'hiragana))) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
268 (if hira |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
269 (japanese-replace-region (match-beginning 0) (point) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
270 hira))))))))) |
17052 | 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) | |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
281 (save-excursion |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
282 (goto-char (point-min)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
283 (while (re-search-forward "\\cj" nil t) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
284 (let* ((zenkaku (preceding-char)) |
37913
49a0ec256ceb
(japanese-hankaku): Prefer the charset
Gerd Moellmann <gerd@gnu.org>
parents:
37871
diff
changeset
|
285 (hankaku (or (and (not ascii-only) |
49a0ec256ceb
(japanese-hankaku): Prefer the charset
Gerd Moellmann <gerd@gnu.org>
parents:
37871
diff
changeset
|
286 (get-char-code-property zenkaku 'jisx0201)) |
49a0ec256ceb
(japanese-hankaku): Prefer the charset
Gerd Moellmann <gerd@gnu.org>
parents:
37871
diff
changeset
|
287 (get-char-code-property zenkaku 'ascii)))) |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
288 (if hankaku |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
289 (japanese-replace-region (match-beginning 0) (match-end 0) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
290 hankaku))))))) |
17052 | 291 |
292 ;;;###autoload | |
23722
b0c66c87b29b
(japanese-zenkaku-region): New optional arg KATAKANA-ONLY.
Kenichi Handa <handa@m17n.org>
parents:
22987
diff
changeset
|
293 (defun japanese-zenkaku-region (from to &optional katakana-only) |
17052 | 294 "Convert hankaku' chars in the region to Japanese `zenkaku' chars. |
295 `Zenkaku' chars belong to `japanese-jisx0208' | |
23722
b0c66c87b29b
(japanese-zenkaku-region): New optional arg KATAKANA-ONLY.
Kenichi Handa <handa@m17n.org>
parents:
22987
diff
changeset
|
296 `Hankaku' chars belong to `ascii' or `japanese-jisx0201-kana'. |
b0c66c87b29b
(japanese-zenkaku-region): New optional arg KATAKANA-ONLY.
Kenichi Handa <handa@m17n.org>
parents:
22987
diff
changeset
|
297 Optional argument KATAKANA-ONLY non-nil means to convert only KATAKANA char." |
b0c66c87b29b
(japanese-zenkaku-region): New optional arg KATAKANA-ONLY.
Kenichi Handa <handa@m17n.org>
parents:
22987
diff
changeset
|
298 (interactive "r\nP") |
17052 | 299 (save-restriction |
300 (narrow-to-region from to) | |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
301 (save-excursion |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
302 (goto-char (point-min)) |
23722
b0c66c87b29b
(japanese-zenkaku-region): New optional arg KATAKANA-ONLY.
Kenichi Handa <handa@m17n.org>
parents:
22987
diff
changeset
|
303 (while (or (and katakana-only |
b0c66c87b29b
(japanese-zenkaku-region): New optional arg KATAKANA-ONLY.
Kenichi Handa <handa@m17n.org>
parents:
22987
diff
changeset
|
304 (re-search-forward "\\ck" nil t)) |
b0c66c87b29b
(japanese-zenkaku-region): New optional arg KATAKANA-ONLY.
Kenichi Handa <handa@m17n.org>
parents:
22987
diff
changeset
|
305 (and (not katakana-only) |
b0c66c87b29b
(japanese-zenkaku-region): New optional arg KATAKANA-ONLY.
Kenichi Handa <handa@m17n.org>
parents:
22987
diff
changeset
|
306 (re-search-forward "\\ca\\|\\ck" nil t))) |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
307 (let* ((hankaku (preceding-char)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
308 (composition (get-char-code-property hankaku 'kana-composition)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
309 next slot) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
310 (if (and composition (setq slot (assq (following-char) composition))) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
311 (japanese-replace-region (match-beginning 0) (1+ (point)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
312 (cdr slot)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
313 (let ((zenkaku (japanese-zenkaku hankaku))) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
314 (if zenkaku |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
315 (japanese-replace-region (match-beginning 0) (match-end 0) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
316 zenkaku))))))))) |
17052 | 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." | |
19854
c6f58c509273
(setup-japanese-environment): Give
Kenichi Handa <handa@m17n.org>
parents:
19764
diff
changeset
|
322 (read-multilingual-string prompt initial-input "japanese-hiragana")) |
17052 | 323 |
324 ;; | |
18309
bd8b521f5218
Provide XXX-util instead of
Kenichi Handa <handa@m17n.org>
parents:
18203
diff
changeset
|
325 (provide 'japan-util) |
17052 | 326 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
91935
diff
changeset
|
327 ;; arch-tag: b579595c-c9ad-4b57-9314-98cd8b214f89 |
17052 | 328 ;;; japan-util.el ends here |