Mercurial > emacs
annotate lisp/language/japan-util.el @ 25690:0e71134aaba2
(Fmake_hash_table): Fix string continuation.
author | Dave Love <fx@gnu.org> |
---|---|
date | Mon, 13 Sep 1999 19:03:19 +0000 |
parents | b0c66c87b29b |
children | cc03e8352d48 |
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) |
22987
708271862495
(setup-XXX-environment): Just call set-language-environment. If
Kenichi Handa <handa@m17n.org>
parents:
22776
diff
changeset
|
33 (set-language-environment "Japanese")) |
708271862495
(setup-XXX-environment): Just call set-language-environment. If
Kenichi Handa <handa@m17n.org>
parents:
22776
diff
changeset
|
34 |
708271862495
(setup-XXX-environment): Just call set-language-environment. If
Kenichi Handa <handa@m17n.org>
parents:
22776
diff
changeset
|
35 ;;;###autoload |
708271862495
(setup-XXX-environment): Just call set-language-environment. If
Kenichi Handa <handa@m17n.org>
parents:
22776
diff
changeset
|
36 (defun setup-japanese-environment-internal () |
20738
f510736ce3d1
In setup-LANGUAGE-environment functions,
Kenichi Handa <handa@m17n.org>
parents:
19854
diff
changeset
|
37 (if (eq system-type 'ms-dos) |
22987
708271862495
(setup-XXX-environment): Just call set-language-environment. If
Kenichi Handa <handa@m17n.org>
parents:
22776
diff
changeset
|
38 (prefer-coding-system 'japanese-shift-jis) |
708271862495
(setup-XXX-environment): Just call set-language-environment. If
Kenichi Handa <handa@m17n.org>
parents:
22776
diff
changeset
|
39 (setq default-file-name-coding-system 'japanese-iso-8bit)) |
21376
ea0bc6fdefd5
(setup-japanese-environment): Setup
Kenichi Handa <handa@m17n.org>
parents:
21043
diff
changeset
|
40 (setq sentence-end-save sentence-end) |
ea0bc6fdefd5
(setup-japanese-environment): Setup
Kenichi Handa <handa@m17n.org>
parents:
21043
diff
changeset
|
41 (setq sentence-end (concat sentence-end "\\|[$B!#!)!*(B]"))) |
ea0bc6fdefd5
(setup-japanese-environment): Setup
Kenichi Handa <handa@m17n.org>
parents:
21043
diff
changeset
|
42 |
ea0bc6fdefd5
(setup-japanese-environment): Setup
Kenichi Handa <handa@m17n.org>
parents:
21043
diff
changeset
|
43 (defun exit-japanese-environment () |
ea0bc6fdefd5
(setup-japanese-environment): Setup
Kenichi Handa <handa@m17n.org>
parents:
21043
diff
changeset
|
44 (setq sentence-end sentence-end-save)) |
17993
73869115ae0a
Most of setup-LANGUAGE-environment functions are
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
45 |
17052 | 46 (defconst japanese-kana-table |
47 '((?$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) | |
48 (?$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) | |
49 (?$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) | |
50 (?$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) | |
51 (?$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) | |
52 (?$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) | |
53 (?$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) | |
54 (?$B$d(B ?$B%d(B ?(IT(B) (?$B$f(B ?$B%f(B ?(IU(B) (?$B$h(B ?$B%h(B ?(IV(B) | |
55 (?$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
|
56 (?$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 | 57 (?$B$s(B ?$B%s(B ?(I](B) |
58 (?$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") | |
59 (?$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") | |
60 (?$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") | |
61 (?$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") | |
62 (?$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") | |
63 (?$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) | |
64 (?$B$C(B ?$B%C(B ?(I/(B) | |
65 (?$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
|
66 (?$B$n(B ?$B%n(B "(I\(B") |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
67 ("$B$&!+(B" ?$B%t(B "(I3^(B") (nil ?$B%u(B "(I6(B") (nil ?$B%v(B "(I9(B")) |
17052 | 68 "Japanese JISX0208 Kana character table. |
69 Each element is of the form (HIRAGANA KATAKANA HANKAKU-KATAKANA), where | |
70 HIRAGANA and KATAKANA belong to `japanese-jisx0208', | |
71 HANKAKU-KATAKANA belongs to `japanese-jisx0201-kana'.") | |
72 | |
73 ;; Put properties 'katakana, 'hiragana, and 'jix0201 to each Japanese | |
74 ;; kana characters for conversion among them. | |
75 (let ((l japanese-kana-table) | |
76 slot hiragana katakana jisx0201) | |
77 (while l | |
78 (setq slot (car l) | |
79 hiragana (car slot) katakana (nth 1 slot) jisx0201 (nth 2 slot) | |
80 l (cdr l)) | |
81 (if hiragana | |
22548
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
82 (if (stringp hiragana) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
83 (if (> (length hiragana) 1) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
84 (let ((hira (aref hiragana 0))) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
85 (put-char-code-property |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
86 hira 'kana-composition |
22548
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
87 (cons (cons (aref hiragana 1) katakana) |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
88 (get-char-code-property hira 'kana-composition))))) |
17052 | 89 (put-char-code-property hiragana 'katakana katakana) |
22548
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
90 (put-char-code-property hiragana 'jisx0201 jisx0201))) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
91 (when (integerp katakana) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
92 (put-char-code-property katakana 'hiragana hiragana) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
93 (put-char-code-property katakana 'jisx0201 jisx0201)) |
17052 | 94 (if jisx0201 |
22548
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
95 (if (stringp jisx0201) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
96 (if (> (length jisx0201) 1) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
97 (let ((kana (aref jisx0201 0))) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
98 (put-char-code-property |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
99 kana 'kana-composition |
22548
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
100 (cons (cons (aref jisx0201 1) katakana) |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
101 (get-char-code-property kana 'kana-composition))))) |
22548
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
102 (put-char-code-property jisx0201 'hiragana hiragana) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
103 (put-char-code-property jisx0201 'katakana katakana) |
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
104 (put-char-code-property jisx0201 'jisx0208 katakana))))) |
17052 | 105 |
106 (defconst japanese-symbol-table | |
22548
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
107 '((?\$B!!(B ?\ ) (?$B!$(B ?, ?(I$(B) (?$B!%(B ?. ?(I!(B) (?$B!"(B ?, ?(I$(B) (?$B!#(B ?. ?(I!(B) (?$B!&(B nil ?(I%(B) |
17052 | 108 (?$B!'(B ?:) (?$B!((B ?\;) (?$B!)(B ??) (?$B!*(B ?!) (?$B!+(B nil ?(I^(B) (?$B!,(B nil ?(I_(B) |
109 (?$B!-(B ?') (?$B!.(B ?`) (?$B!0(B ?^) (?$B!2(B ?_) (?$B!<(B ?-) (?$B!=(B ?-) (?$B!>(B ?-) | |
110 (?$B!?(B ?/) (?$B!@(B ?\\) (?$B!A(B ?~) (?$B!C(B ?|) (?$B!F(B ?`) (?$B!G(B ?') (?$B!H(B ?\") (?$B!I(B ?\") | |
111 (?\$B!J(B ?\() (?\$B!K(B ?\)) (?\$B!N(B ?[) (?\$B!O(B ?]) (?\$B!P(B ?{) (?\$B!Q(B ?}) | |
112 (?$B!R(B ?<) (?$B!S(B ?>) (?$B!\(B ?+) (?$B!](B ?-) (?$B!a(B ?=) (?$B!c(B ?<) (?$B!d(B ?>) | |
113 (?$B!l(B ?') (?$B!m(B ?\") (?$B!o(B ?\\) (?$B!p(B ?$) (?$B!s(B ?%) (?$B!t(B ?#) (?$B!u(B ?&) (?$B!v(B ?*) | |
114 (?$B!w(B ?@)) | |
115 "Japanese JISX0208 symbol character table. | |
116 Each element is of the form (SYMBOL ASCII HANKAKU), where SYMBOL | |
117 belongs to `japanese-jisx0208', ASCII belongs to `ascii', and HANKAKU | |
118 belongs to `japanese-jisx0201-kana'.") | |
119 | |
120 ;; Put properties 'jisx0208, 'jisx0201, and 'ascii to each Japanese | |
121 ;; symbol and ASCII characters for conversion among them. | |
122 (let ((l japanese-symbol-table) | |
123 slot jisx0208 ascii jisx0201) | |
124 (while l | |
125 (setq slot (car l) | |
126 jisx0208 (car slot) ascii (nth 1 slot) jisx0201 (nth 2 slot) | |
127 l (cdr l)) | |
128 (if ascii | |
129 (progn | |
130 (put-char-code-property jisx0208 'ascii ascii) | |
131 (put-char-code-property ascii 'jisx0208 jisx0208))) | |
132 (if jisx0201 | |
133 (progn | |
134 (put-char-code-property jisx0208 'jisx0201 jisx0201) | |
135 (put-char-code-property jisx0201 'jisx0208 jisx0208))))) | |
136 | |
137 (defconst japanese-alpha-numeric-table | |
138 '((?$B#0(B . ?0) (?$B#1(B . ?1) (?$B#2(B . ?2) (?$B#3(B . ?3) (?$B#4(B . ?4) | |
139 (?$B#5(B . ?5) (?$B#6(B . ?6) (?$B#7(B . ?7) (?$B#8(B . ?8) (?$B#9(B . ?9) | |
140 (?$B#A(B . ?A) (?$B#B(B . ?B) (?$B#C(B . ?C) (?$B#D(B . ?D) (?$B#E(B . ?E) | |
141 (?$B#F(B . ?F) (?$B#G(B . ?G) (?$B#H(B . ?H) (?$B#I(B . ?I) (?$B#J(B . ?J) | |
142 (?$B#K(B . ?K) (?$B#L(B . ?L) (?$B#M(B . ?M) (?$B#N(B . ?N) (?$B#O(B . ?O) | |
143 (?$B#P(B . ?P) (?$B#Q(B . ?Q) (?$B#R(B . ?R) (?$B#S(B . ?S) (?$B#T(B . ?T) | |
144 (?$B#U(B . ?U) (?$B#V(B . ?V) (?$B#W(B . ?W) (?$B#X(B . ?X) (?$B#Y(B . ?Y) (?$B#Z(B . ?Z) | |
145 (?$B#a(B . ?a) (?$B#b(B . ?b) (?$B#c(B . ?c) (?$B#d(B . ?d) (?$B#e(B . ?e) | |
146 (?$B#f(B . ?f) (?$B#g(B . ?g) (?$B#h(B . ?h) (?$B#i(B . ?i) (?$B#j(B . ?j) | |
147 (?$B#k(B . ?k) (?$B#l(B . ?l) (?$B#m(B . ?m) (?$B#n(B . ?n) (?$B#o(B . ?o) | |
148 (?$B#p(B . ?p) (?$B#q(B . ?q) (?$B#r(B . ?r) (?$B#s(B . ?s) (?$B#t(B . ?t) | |
149 (?$B#u(B . ?u) (?$B#v(B . ?v) (?$B#w(B . ?w) (?$B#x(B . ?x) (?$B#y(B . ?y) (?$B#z(B . ?z)) | |
150 "Japanese JISX0208 alpha numeric character table. | |
151 Each element is of the form (ALPHA-NUMERIC ASCII), where ALPHA-NUMERIC | |
152 belongs to `japanese-jisx0208', ASCII belongs to `ascii'.") | |
153 | |
154 ;; Put properties 'jisx0208 and 'ascii to each Japanese alpha numeric | |
155 ;; and ASCII characters for conversion between them. | |
156 (let ((l japanese-alpha-numeric-table) | |
157 slot jisx0208 ascii) | |
158 (while l | |
159 (setq slot (car l) | |
160 jisx0208 (car slot) ascii (cdr slot) | |
161 l (cdr l)) | |
162 (put-char-code-property jisx0208 'ascii ascii) | |
163 (put-char-code-property ascii 'jisx0208 jisx0208))) | |
164 | |
165 ;; Convert string STR by FUNC and return a resulting string. | |
166 (defun japanese-string-conversion (str func &rest args) | |
167 (let ((buf (get-buffer-create " *Japanese work*"))) | |
168 (save-excursion | |
169 (set-buffer buf) | |
170 (erase-buffer) | |
171 (insert str) | |
172 (apply func 1 (point) args) | |
173 (buffer-string)))) | |
174 | |
175 ;;;###autoload | |
176 (defun japanese-katakana (obj &optional hankaku) | |
177 "Convert argument to Katakana and return that. | |
178 The argument may be a character or string. The result has the same type. | |
179 The argument object is not altered--the value is a copy. | |
180 Optional argument HANKAKU t means to convert to `hankaku' Katakana | |
181 \(`japanese-jisx0201-kana'), in which case return value | |
182 may be a string even if OBJ is a character if two Katakanas are | |
183 necessary to represent OBJ." | |
184 (if (stringp obj) | |
185 (japanese-string-conversion obj 'japanese-katakana-region hankaku) | |
186 (or (get-char-code-property obj (if hankaku 'jisx0201 'katakana)) | |
187 obj))) | |
188 | |
189 ;;;###autoload | |
190 (defun japanese-hiragana (obj) | |
191 "Convert argument to Hiragana and return that. | |
192 The argument may be a character or string. The result has the same type. | |
193 The argument object is not altered--the value is a copy." | |
194 (if (stringp obj) | |
195 (japanese-string-conversion obj 'japanese-hiragana-region) | |
196 (or (get-char-code-property obj 'hiragana) | |
197 obj))) | |
198 | |
199 ;;;###autoload | |
200 (defun japanese-hankaku (obj &optional ascii-only) | |
201 "Convert argument to `hankaku' and return that. | |
202 The argument may be a character or string. The result has the same type. | |
203 The argument object is not altered--the value is a copy. | |
204 Optional argument ASCII-ONLY non-nil means to return only ASCII character." | |
205 (if (stringp obj) | |
206 (japanese-string-conversion obj 'japanese-hankaku-region ascii-only) | |
207 (or (get-char-code-property obj 'ascii) | |
208 (and (not ascii-only) | |
209 (get-char-code-property obj 'jisx0201)) | |
210 obj))) | |
211 | |
212 ;;;###autoload | |
213 (defun japanese-zenkaku (obj) | |
214 "Convert argument to `zenkaku' and return that. | |
215 The argument may be a character or string. The result has the same type. | |
216 The argument object is not altered--the value is a copy." | |
217 (if (stringp obj) | |
218 (japanese-string-conversion obj 'japanese-zenkaku-region) | |
219 (or (get-char-code-property obj 'jisx0208) | |
220 obj))) | |
221 | |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
222 (defun japanese-replace-region (from to string) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
223 "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
|
224 (goto-char from) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
225 (insert string) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
226 (delete-char (- to from))) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
227 |
17052 | 228 ;;;###autoload |
229 (defun japanese-katakana-region (from to &optional hankaku) | |
230 "Convert Japanese `hiragana' chars in the region to `katakana' chars. | |
231 Optional argument HANKAKU t means to convert to `hankaku katakana' character | |
232 of which charset is `japanese-jisx0201-kana'." | |
233 (interactive "r\nP") | |
234 (save-restriction | |
235 (narrow-to-region from to) | |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
236 (save-excursion |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
237 (goto-char (point-min)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
238 (while (re-search-forward "\\cH\\|\\cK" nil t) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
239 (let* ((kana (preceding-char)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
240 (composition (get-char-code-property kana 'kana-composition)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
241 next slot) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
242 (if (and composition (setq slot (assq (following-char) composition))) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
243 (japanese-replace-region (match-beginning 0) (1+ (point)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
244 (cdr slot)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
245 (let ((kata (get-char-code-property |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
246 kana (if hankaku 'jisx0201 'katakana)))) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
247 (if kata |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
248 (japanese-replace-region (match-beginning 0) (point) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
249 kata))))))))) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
250 |
17052 | 251 |
252 ;;;###autoload | |
253 (defun japanese-hiragana-region (from to) | |
22548
b054cd9f66df
Introduce new character code property
Kenichi Handa <handa@m17n.org>
parents:
21376
diff
changeset
|
254 "Convert Japanese `katakana' chars in the region to `hiragana' chars." |
17052 | 255 (interactive "r") |
256 (save-restriction | |
257 (narrow-to-region from to) | |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
258 (save-excursion |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
259 (goto-char (point-min)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
260 (while (re-search-forward "\\cK\\|\\ck" nil t) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
261 (let* ((kata (preceding-char)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
262 (composition (get-char-code-property kata 'kana-composition)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
263 next slot) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
264 (if (and composition (setq slot (assq (following-char) composition))) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
265 (japanese-replace-region (match-beginning 0) (1+ (point)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
266 (get-char-code-property |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
267 (cdr slot) 'hiragana)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
268 (let ((hira (get-char-code-property kata 'hiragana))) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
269 (if hira |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
270 (japanese-replace-region (match-beginning 0) (point) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
271 hira))))))))) |
17052 | 272 |
273 ;;;###autoload | |
274 (defun japanese-hankaku-region (from to &optional ascii-only) | |
275 "Convert Japanese `zenkaku' chars in the region to `hankaku' chars. | |
276 `Zenkaku' chars belong to `japanese-jisx0208' | |
277 `Hankaku' chars belong to `ascii' or `japanese-jisx0201-kana'. | |
278 Optional argument ASCII-ONLY non-nil means to convert only to ASCII char." | |
279 (interactive "r\nP") | |
280 (save-restriction | |
281 (narrow-to-region from to) | |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
282 (save-excursion |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
283 (goto-char (point-min)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
284 (while (re-search-forward "\\cj" nil t) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
285 (let* ((zenkaku (preceding-char)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
286 (hankaku (or (get-char-code-property zenkaku 'ascii) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
287 (and (not ascii-only) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
288 (get-char-code-property zenkaku 'jisx0201))))) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
289 (if hankaku |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
290 (japanese-replace-region (match-beginning 0) (match-end 0) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
291 hankaku))))))) |
17052 | 292 |
293 ;;;###autoload | |
23722
b0c66c87b29b
(japanese-zenkaku-region): New optional arg KATAKANA-ONLY.
Kenichi Handa <handa@m17n.org>
parents:
22987
diff
changeset
|
294 (defun japanese-zenkaku-region (from to &optional katakana-only) |
17052 | 295 "Convert hankaku' chars in the region to Japanese `zenkaku' chars. |
296 `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
|
297 `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
|
298 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
|
299 (interactive "r\nP") |
17052 | 300 (save-restriction |
301 (narrow-to-region from to) | |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
302 (save-excursion |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
303 (goto-char (point-min)) |
23722
b0c66c87b29b
(japanese-zenkaku-region): New optional arg KATAKANA-ONLY.
Kenichi Handa <handa@m17n.org>
parents:
22987
diff
changeset
|
304 (while (or (and katakana-only |
b0c66c87b29b
(japanese-zenkaku-region): New optional arg KATAKANA-ONLY.
Kenichi Handa <handa@m17n.org>
parents:
22987
diff
changeset
|
305 (re-search-forward "\\ck" nil t)) |
b0c66c87b29b
(japanese-zenkaku-region): New optional arg KATAKANA-ONLY.
Kenichi Handa <handa@m17n.org>
parents:
22987
diff
changeset
|
306 (and (not katakana-only) |
b0c66c87b29b
(japanese-zenkaku-region): New optional arg KATAKANA-ONLY.
Kenichi Handa <handa@m17n.org>
parents:
22987
diff
changeset
|
307 (re-search-forward "\\ca\\|\\ck" nil t))) |
22776
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
308 (let* ((hankaku (preceding-char)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
309 (composition (get-char-code-property hankaku 'kana-composition)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
310 next slot) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
311 (if (and composition (setq slot (assq (following-char) composition))) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
312 (japanese-replace-region (match-beginning 0) (1+ (point)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
313 (cdr slot)) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
314 (let ((zenkaku (japanese-zenkaku hankaku))) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
315 (if zenkaku |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
316 (japanese-replace-region (match-beginning 0) (match-end 0) |
1e2bf1acab23
(japanese-replace-region): New function.
Kenichi Handa <handa@m17n.org>
parents:
22548
diff
changeset
|
317 zenkaku))))))))) |
17052 | 318 |
319 ;;;###autoload | |
320 (defun read-hiragana-string (prompt &optional initial-input) | |
321 "Read a Hiragana string from the minibuffer, prompting with string PROMPT. | |
322 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
|
323 (read-multilingual-string prompt initial-input "japanese-hiragana")) |
17052 | 324 |
325 ;; | |
18309
bd8b521f5218
Provide XXX-util instead of
Kenichi Handa <handa@m17n.org>
parents:
18203
diff
changeset
|
326 (provide 'japan-util) |
17052 | 327 |
328 ;;; japan-util.el ends here |