Mercurial > emacs
annotate leim/quail/hangul.el @ 95582:4d17533ba12f
Docstrings and comments improved.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Thu, 05 Jun 2008 07:23:16 +0000 |
parents | ad40a2d6712f |
children | 572e23ede3f0 |
rev | line source |
---|---|
95500 | 1 ;;; hangul.el --- Korean Hangul input method |
18673 | 2 |
95500 | 3 ;; Author: Jihyun Cho <jihyun.jo@gmail.com> |
18673 | 4 ;; Keywords: multilingual, input method, Korean, Hangul |
5 | |
6 ;; This file is part of GNU Emacs. | |
7 | |
94710
4f1fd208c354
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79727
diff
changeset
|
8 ;; GNU Emacs is free software: you can redistribute it and/or modify |
18673 | 9 ;; it under the terms of the GNU General Public License as published by |
94710
4f1fd208c354
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79727
diff
changeset
|
10 ;; the Free Software Foundation, either version 3 of the License, or |
4f1fd208c354
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79727
diff
changeset
|
11 ;; (at your option) any later version. |
18673 | 12 |
13 ;; GNU Emacs is distributed in the hope that it will be useful, | |
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 ;; GNU General Public License for more details. | |
17 | |
18 ;; You should have received a copy of the GNU General Public License | |
94710
4f1fd208c354
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79727
diff
changeset
|
19 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
18673 | 20 |
38453
519983161a46
Some fixes to follow lisp coding conventions and typo fixes.
Pavel Janík <Pavel@Janik.cz>
parents:
37396
diff
changeset
|
21 ;;; Commentary: |
519983161a46
Some fixes to follow lisp coding conventions and typo fixes.
Pavel Janík <Pavel@Janik.cz>
parents:
37396
diff
changeset
|
22 |
95500 | 23 ;; This file is to implement the following hangul automata: |
24 ;; - Hangul 2-Bulsik input method | |
25 ;; - Hangul 3-Bulsik final input method | |
26 ;; - Hangul 3-Bulsik 390 input method | |
44421 | 27 |
18673 | 28 ;;; Code: |
29 | |
30 (require 'quail) | |
95500 | 31 (require 'cl) |
32 (require 'hanja-util) | |
33 | |
34 ;; Hangul double jamo table. | |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
35 ;; The format is an alist of JAMO-TYPE vs. DOUBLE-JAMO-TABLE. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
36 ;; |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
37 ;; JAMO-TYPE is a symbol `cho' for Choseong, `jung' for Jungseong, and |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
38 ;; `jong' for Jongseong. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
39 ;; |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
40 ;; DOUBLE-JAMO-TABLE is an alist of jamo index vs. the vector of jamo |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
41 ;; indies that can be combined with the car part. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
42 ;; |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
43 ;; Jamo index is a relative index in `hangul Compatibility Jamo' area |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
44 ;; of the Unicode (i.e. 1 for U+3131). |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
45 |
95500 | 46 (defconst hangul-djamo-table |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
47 '((cho . ((1 . [1]) ; Choseong |
95500 | 48 (7 . [7]) |
49 (18 . [18]) | |
50 (21 . [21]) | |
51 (24 . [24]))) | |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
52 (jung . ((39 . [31 32 51]) ; Jungseong |
95500 | 53 (44 . [35 36 51]) |
54 (49 . [51]))) | |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
55 (jong . ((1 . [1 21]) ; Jongseong |
95500 | 56 (4 . [24 30]) |
57 (9 . [1 17 18 21 28 29 30]) | |
58 (18 . [18 21]) | |
59 (21 . [21]))))) | |
18673 | 60 |
95500 | 61 ;; Hangul 2-Bulsik keymap. |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
62 ;; It converts an ASCII code A-Z, a-z, to the corresponding hangul |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
63 ;; jamo index. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
64 |
95500 | 65 (defconst hangul2-keymap |
66 [17 48 26 23 7 9 30 39 33 35 31 51 49 44 32 36 18 1 4 21 37 29 24 28 43 27]) | |
18673 | 67 |
95500 | 68 ;; Hangul 3-Bulsik final keymap. 3-Bulsik use full keyboard layout. |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
69 ;; Therefore, we must map all printable ASCII codes (`!' to `~') |
95500 | 70 ;; to Hangul 3-Bulsik codes. |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
71 ;; Other parts are the same as `hangul2-keymap'. |
95500 | 72 (defconst hangul3-keymap |
73 [2 183 24 15 14 8220 120 39 126 8221 43 44 41 46 74 119 30 22 18 78 83 | |
74 68 73 85 79 52 110 44 62 46 33 10 7 63 27 12 5 11 69 48 55 49 50 51 | |
75 34 45 56 57 29 16 6 13 54 3 28 20 53 26 40 58 60 61 59 42 23 79 71 | |
76 86 72 66 84 96 109 115 93 116 122 113 118 121 21 67 4 70 99 74 9 1 | |
77 101 17 37 92 47 8251]) | |
18673 | 78 |
95500 | 79 ;; Hangul 3-Bulsik 390 keymap. |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
80 ;; The role is the same as `hangul3-keymap'. |
95500 | 81 (defconst hangul390-keymap |
82 [24 34 35 36 37 38 120 40 41 42 43 44 45 46 73 119 30 22 18 77 82 67 72 | |
83 84 78 58 110 50 61 51 63 64 7 33 11 10 27 2 47 39 56 52 53 54 49 48 | |
84 57 62 29 68 6 59 55 16 28 20 60 26 91 92 93 94 95 96 23 78 70 85 71 | |
85 65 83 90 109 115 87 116 122 113 118 121 21 66 4 69 99 73 9 1 101 17 | |
86 123 124 125 126]) | |
18673 | 87 |
95500 | 88 (defvar hangul-im-keymap |
89 (let ((map (make-sparse-keymap))) | |
90 (define-key map "\d" 'hangul-delete-backward-char) | |
91 (define-key map [f9] 'hangul-to-hanja-conversion) | |
92 map) | |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
93 "Keymap for Hangul method. It is used by all Hangul input method.") |
95500 | 94 |
95 ;; Current input character buffer. Store separated hangul character. | |
96 ;; First and second index of vector stored "Choseong". | |
97 ;; Third and forth index of vector stored "Jungseong". | |
98 ;; Fifth and sixth index of vector stored "Jongseong". | |
99 (defvar hangul-queue | |
100 (make-vector 6 0)) | |
101 | |
102 (defsubst notzerop (number) | |
103 (not (zerop number))) | |
104 | |
105 (defsubst alphabetp (char) | |
106 (or (and (>= char ?A) (<= char ?Z)) | |
107 (and (>= char ?a) (<= char ?z)))) | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44421
diff
changeset
|
108 |
95500 | 109 (defun hangul-character (cho jung jong) |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
110 "Convert CHO, JUNG, JONG to the precomposed `Hangul Syllables' character. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
111 CHO, JUNG, JONG are relative indices in `Hangul Compatibility Jamo' of unicode. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
112 Return a zero-length string if the conversion fails." |
95500 | 113 (or |
114 (decode-char | |
115 'ucs | |
116 (if (and (/= cho 0) (/= jung 0)) | |
117 (+ #xac00 | |
118 (* 588 | |
119 (- cho | |
120 (cond ((< cho 3) 1) | |
121 ((< cho 5) 2) | |
122 ((< cho 10) 4) | |
123 ((< cho 20) 11) | |
124 (t 12)))) | |
125 (* 28 (- jung 31)) | |
126 (- jong | |
127 (cond ((< jong 8) 0) | |
128 ((< jong 19) 1) | |
129 ((< jong 25) 2) | |
130 (t 3)))) | |
131 (+ #x3130 | |
132 (cond ((/= cho 0) cho) | |
133 ((/= jung 0) jung) | |
134 ((/= jong 0) jong))))) | |
135 "")) | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44421
diff
changeset
|
136 |
95500 | 137 (defun hangul-insert-character (&rest queues) |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
138 "Insert characters generated from QUEUEs. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
139 Each QUEUE has the same form as `hangul-queue'. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
140 Setup `quail-overlay' to the last character." |
95500 | 141 (if (and mark-active transient-mark-mode) |
142 (progn | |
143 (delete-region (region-beginning) (region-end)) | |
144 (deactivate-mark))) | |
145 (quail-delete-region) | |
146 (let ((first (car queues))) | |
147 (insert | |
148 (hangul-character | |
149 (+ (aref first 0) (hangul-djamo 'cho (aref first 0) (aref first 1))) | |
150 (+ (aref first 2) (hangul-djamo 'jung (aref first 2) (aref first 3))) | |
151 (+ (aref first 4) (hangul-djamo 'jong (aref first 4) (aref first 5)))))) | |
152 (move-overlay quail-overlay (overlay-start quail-overlay) (point)) | |
153 (dolist (queue (cdr queues)) | |
154 (insert | |
155 (hangul-character | |
156 (+ (aref queue 0) (hangul-djamo 'cho (aref queue 0) (aref queue 1))) | |
157 (+ (aref queue 2) (hangul-djamo 'jung (aref queue 2) (aref queue 3))) | |
158 (+ (aref queue 4) (hangul-djamo 'jong (aref queue 4) (aref queue 5))))) | |
159 (move-overlay quail-overlay (1+ (overlay-start quail-overlay)) (point)))) | |
160 | |
161 (defun hangul-djamo (jamo char1 char2) | |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
162 "Return the dobule jamo index calculated from the arguments. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
163 JAMO is a type of Hangul jamo; `cho', `jung', or `jong'. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
164 CHAR1 and CAHR2 are Hangul jamo indices. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
165 Return nil if CHAR1 and CHAR2 can not combined." |
95500 | 166 (let* ((jamo (cdr (assoc jamo hangul-djamo-table))) |
167 (char1 (cdr (assoc char1 jamo)))) | |
168 (if char1 | |
169 (let ((i (length char1))) | |
170 (or (catch 'found | |
171 (while (> i 0) | |
172 (if (= char2 (aref char1 (1- i))) | |
173 (throw 'found i)) | |
174 (setf i (1- i)))) | |
175 0)) | |
176 0))) | |
177 | |
178 (defsubst hangul2-input-method-jaum (char) | |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
179 "Store hangul jamo indice CHAR in `hangul-queue'. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
180 Maybe, it is a Hangul 2-Bulsik jaum. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
181 This function processes a Hangul 2-Bulsik jaum. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
182 Unless the function inserts CHAR to current input queue, |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
183 commit current character and then start next character. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
184 The Hangul 2-Bulsik is composed of `jaum' and `moum'." |
95500 | 185 (if (cond ((zerop (aref hangul-queue 0)) |
186 (aset hangul-queue 0 char)) | |
187 ((and (zerop (aref hangul-queue 1)) | |
188 (zerop (aref hangul-queue 2)) | |
189 (notzerop (hangul-djamo 'cho (aref hangul-queue 0) char))) | |
190 (aset hangul-queue 1 char)) | |
191 ((and (zerop (aref hangul-queue 4)) | |
192 (notzerop (aref hangul-queue 2)) | |
193 (/= char 8) | |
194 (/= char 19) | |
195 (/= char 25) | |
196 (numberp | |
197 (hangul-character | |
198 (+ (aref hangul-queue 0) | |
199 (hangul-djamo | |
200 'cho | |
201 (aref hangul-queue 0) | |
202 (aref hangul-queue 1))) | |
203 (+ (aref hangul-queue 2) | |
204 (hangul-djamo | |
205 'jung | |
206 (aref hangul-queue 2) | |
207 (aref hangul-queue 3))) | |
208 char))) | |
209 (aset hangul-queue 4 char)) | |
210 ((and (zerop (aref hangul-queue 5)) | |
211 (notzerop (hangul-djamo 'jong (aref hangul-queue 4) char)) | |
212 (numberp | |
213 (hangul-character | |
214 (+ (aref hangul-queue 0) | |
215 (hangul-djamo | |
216 'cho | |
217 (aref hangul-queue 0) | |
218 (aref hangul-queue 1))) | |
219 (+ (aref hangul-queue 2) | |
220 (hangul-djamo | |
221 'jung | |
222 (aref hangul-queue 2) | |
223 (aref hangul-queue 3))) | |
224 (+ (aref hangul-queue 4) | |
225 (hangul-djamo | |
226 'jong | |
227 (aref hangul-queue 4) | |
228 char))))) | |
229 (aset hangul-queue 5 char))) | |
230 (hangul-insert-character hangul-queue) | |
231 (hangul-insert-character hangul-queue | |
232 (setq hangul-queue (vector char 0 0 0 0 0))))) | |
233 | |
234 (defsubst hangul2-input-method-moum (char) | |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
235 "Store hangul jamo indice CHAR in `hangul-queue'. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
236 Maybe, it is a Hangul 2-Bulsik moum. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
237 This function process a Hangul 2-Bulsik moum. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
238 Other parts are the same as a `hangul2-input-method-jaum'." |
95500 | 239 (if (cond ((zerop (aref hangul-queue 2)) |
240 (aset hangul-queue 2 char)) | |
241 ((and (zerop (aref hangul-queue 3)) | |
242 (zerop (aref hangul-queue 4)) | |
243 (notzerop (hangul-djamo 'jung (aref hangul-queue 2) char))) | |
244 (aset hangul-queue 3 char))) | |
245 (hangul-insert-character hangul-queue) | |
246 (let ((next-char (vector 0 0 char 0 0 0))) | |
247 (cond ((notzerop (aref hangul-queue 5)) | |
248 (aset next-char 0 (aref hangul-queue 5)) | |
249 (aset hangul-queue 5 0)) | |
250 ((notzerop (aref hangul-queue 4)) | |
251 (aset next-char 0 (aref hangul-queue 4)) | |
252 (aset hangul-queue 4 0))) | |
253 (hangul-insert-character hangul-queue | |
254 (setq hangul-queue next-char))))) | |
255 | |
256 (defsubst hangul3-input-method-cho (char) | |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
257 "Store hangul jamo indice CHAR in `hangul-queue'. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
258 Maybe, it is a Hangul 3-Bulsik choseong. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
259 This function process a Hangul 3-Bulsik choseong. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
260 The Hangul 3-Bulsik is composed of `choseong', `jungseong' and `jongseong'. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
261 Other parts are the same as a `hangul2-input-method-jaum'." |
95500 | 262 (if (cond ((and (zerop (aref hangul-queue 0)) |
263 (zerop (aref hangul-queue 4))) | |
264 (aset hangul-queue 0 char)) | |
265 ((and (zerop (aref hangul-queue 1)) | |
266 (zerop (aref hangul-queue 2)) | |
267 (notzerop (hangul-djamo 'cho (aref hangul-queue 0) char))) | |
268 (aset hangul-queue 1 char))) | |
269 (hangul-insert-character hangul-queue) | |
270 (hangul-insert-character hangul-queue | |
271 (setq hangul-queue (vector char 0 0 0 0 0))))) | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44421
diff
changeset
|
272 |
95500 | 273 (defsubst hangul3-input-method-jung (char) |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
274 "Store hangul jamo indice CHAR in `hangul-queue'. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
275 Maybe, it is a Hangul 3-Bulsik jungseong. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
276 This function process a Hangul 3-Bulsik jungseong. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
277 Other parts are the same as a `hangul3-input-method-cho'." |
95500 | 278 (if (cond ((and (zerop (aref hangul-queue 2)) |
279 (zerop (aref hangul-queue 4))) | |
280 (aset hangul-queue 2 char)) | |
281 ((and (zerop (aref hangul-queue 3)) | |
282 (notzerop (hangul-djamo 'jung (aref hangul-queue 2) char))) | |
283 (aset hangul-queue 3 char))) | |
284 (hangul-insert-character hangul-queue) | |
285 (hangul-insert-character hangul-queue | |
286 (setq hangul-queue (vector 0 0 char 0 0 0))))) | |
287 | |
288 (defsubst hangul3-input-method-jong (char) | |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
289 "Store hangul jamo indice CHAR in `hangul-queue'. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
290 Maybe, it is a Hangul 3-Bulsik jongseong. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
291 This function process a Hangul 3-Bulsik jongseong. |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
292 Other parts are the same as a `hangul3-input-method-cho'." |
95500 | 293 (if (cond ((and (zerop (aref hangul-queue 4)) |
294 (notzerop (aref hangul-queue 0)) | |
295 (notzerop (aref hangul-queue 2)) | |
296 (numberp | |
297 (hangul-character | |
298 (+ (aref hangul-queue 0) | |
299 (hangul-djamo | |
300 'cho | |
301 (aref hangul-queue 0) | |
302 (aref hangul-queue 1))) | |
303 (+ (aref hangul-queue 2) | |
304 (hangul-djamo | |
305 'jung | |
306 (aref hangul-queue 2) | |
307 (aref hangul-queue 3))) | |
308 char))) | |
309 (aset hangul-queue 4 char)) | |
310 ((and (zerop (aref hangul-queue 5)) | |
311 (notzerop (hangul-djamo 'jong (aref hangul-queue 4) char)) | |
312 (numberp | |
313 (hangul-character | |
314 (+ (aref hangul-queue 0) | |
315 (hangul-djamo | |
316 'cho | |
317 (aref hangul-queue 0) | |
318 (aref hangul-queue 1))) | |
319 (+ (aref hangul-queue 2) | |
320 (hangul-djamo | |
321 'jung | |
322 (aref hangul-queue 2) | |
323 (aref hangul-queue 3))) | |
324 (+ (aref hangul-queue 4) | |
325 (hangul-djamo | |
326 'jong | |
327 (aref hangul-queue 4) | |
328 char))))) | |
329 (aset hangul-queue 6 char))) | |
330 (hangul-insert-character hangul-queue) | |
331 (if (zerop (apply '+ (append hangul-queue nil))) | |
332 (hangul-insert-character (setq hangul-queue (vector 0 0 0 0 char 0))) | |
333 (hangul-insert-character hangul-queue | |
334 (setq hangul-queue (vector 0 0 0 0 char 0)))))) | |
335 | |
336 (defun hangul-delete-backward-char () | |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
337 "Delete the previous hangul character by jaso units." |
95500 | 338 (interactive) |
339 (let ((i 5)) | |
340 (while (and (> i 0) (zerop (aref hangul-queue i))) | |
341 (setq i (1- i))) | |
342 (aset hangul-queue i 0)) | |
343 (if (notzerop (apply '+ (append hangul-queue nil))) | |
344 (hangul-insert-character hangul-queue) | |
345 (delete-backward-char 1))) | |
346 | |
347 (defun hangul-to-hanja-conversion () | |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
348 "Convert the previous hangul character to the corresponding hanja character." |
95500 | 349 (interactive) |
350 (let ((echo-keystrokes 0) | |
351 delete-func | |
352 hanja-character) | |
353 (setq hanja-character (hangul-to-hanja-char (preceding-char))) | |
354 (when hanja-character | |
355 (delete-backward-char 1) | |
356 (insert hanja-character) | |
357 (setq hangul-queue (make-vector 6 0)) | |
358 (move-overlay quail-overlay (point) (point))))) | |
359 | |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
360 ;; Support function for `hangul2-input-method'. Actually, this |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
361 ;; function handles the Hangul 2-Bulsik. KEY is an entered key code |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
362 ;; used for looking up `hangul2-keymap'." |
95500 | 363 (defun hangul2-input-method-internal (key) |
364 (let ((char (+ (aref hangul2-keymap (1- (% key 32))) | |
365 (cond ((or (= key ?O) (= key ?P)) 2) | |
366 ((or (= key ?E) (= key ?Q) (= key ?R) | |
367 (= key ?T) (= key ?W)) 1) | |
368 (t 0))))) | |
369 (if (< char 31) | |
370 (hangul2-input-method-jaum char) | |
371 (hangul2-input-method-moum char)))) | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44421
diff
changeset
|
372 |
95500 | 373 (defun hangul2-input-method (key) |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
374 "2-Bulsik input method." |
95500 | 375 (if (or buffer-read-only (not (alphabetp key))) |
376 (list key) | |
377 (quail-setup-overlays nil) | |
378 (let ((input-method-function nil) | |
379 (echo-keystrokes 0) | |
380 (help-char nil)) | |
381 (setq hangul-queue (make-vector 6 0)) | |
382 (hangul2-input-method-internal key) | |
383 (unwind-protect | |
384 (catch 'exit-input-loop | |
385 (while t | |
386 (let* ((seq (read-key-sequence nil)) | |
387 (cmd (lookup-key hangul-im-keymap seq)) | |
388 key) | |
389 (cond ((and (stringp seq) | |
390 (= 1 (length seq)) | |
391 (setq key (aref seq 0)) | |
392 (alphabetp key)) | |
393 (hangul2-input-method-internal key)) | |
394 ((commandp cmd) | |
395 (call-interactively cmd)) | |
396 (t | |
397 (setq unread-command-events (listify-key-sequence seq)) | |
398 (throw 'exit-input-loop nil)))))) | |
399 (quail-delete-overlays))))) | |
400 | |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
401 ;; Support function for `hangul3-input-method'. Actually, this |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
402 ;; function handles the Hangul 3-Bulsik final. KEY is an entered key |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
403 ;; code used for looking up `hangul3-keymap'." |
95500 | 404 (defun hangul3-input-method-internal (key) |
405 (let ((char (aref hangul3-keymap (- key 33)))) | |
406 (cond ((and (> char 92) (< char 123)) | |
407 (hangul3-input-method-cho (- char 92))) | |
408 ((and (> char 65) (< char 87)) | |
409 (hangul3-input-method-jung (- char 35))) | |
410 ((< char 31) | |
411 (hangul3-input-method-jong char)) | |
412 (t | |
413 (setq hangul-queue (make-vector 6 0)) | |
414 (insert (decode-char 'ucs char)) | |
415 (move-overlay quail-overlay (point) (point)))))) | |
416 | |
417 (defun hangul3-input-method (key) | |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
418 "3-Bulsik final input method." |
95500 | 419 (if (or buffer-read-only (< key 33) (>= key 127)) |
420 (list key) | |
421 (quail-setup-overlays nil) | |
422 (let ((input-method-function nil) | |
423 (echo-keystrokes 0) | |
424 (help-char nil)) | |
425 (setq hangul-queue (make-vector 6 0)) | |
426 (hangul3-input-method-internal key) | |
427 (unwind-protect | |
428 (catch 'exit-input-loop | |
429 (while t | |
430 (let* ((seq (read-key-sequence nil)) | |
431 (cmd (lookup-key hangul-im-keymap seq)) | |
432 key) | |
433 (cond ((and (stringp seq) | |
434 (= 1 (length seq)) | |
435 (setq key (aref seq 0)) | |
436 (and (>= key 33) (< key 127))) | |
437 (hangul3-input-method-internal key)) | |
438 ((commandp cmd) | |
439 (call-interactively cmd)) | |
440 (t | |
441 (setq unread-command-events (listify-key-sequence seq)) | |
442 (throw 'exit-input-loop nil)))))) | |
443 (quail-delete-overlays))))) | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44421
diff
changeset
|
444 |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
445 ;; Support function for `hangul390-input-method'. Actually, this |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
446 ;; function handles the Hangul 3-Bulsik 390. KEY is an entered key |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
447 ;; code used for looking up `hangul390-keymap'." |
95500 | 448 (defun hangul390-input-method-internal (key) |
449 (let ((char (aref hangul390-keymap (- key 33)))) | |
450 (cond ((or (and (> char 86) (< char 91)) | |
451 (and (> char 96) (< char 123))) | |
452 (hangul3-input-method-cho (- char (if (< char 97) 86 92)))) | |
453 ((and (> char 64) (< char 86)) | |
454 (hangul3-input-method-jung (- char 34))) | |
455 ((< char 31) | |
456 (hangul3-input-method-jong char)) | |
457 (t | |
458 (setq hangul-queue (make-vector 6 0)) | |
459 (insert (decode-char 'ucs char)) | |
460 (move-overlay quail-overlay (point) (point)))))) | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
44421
diff
changeset
|
461 |
95500 | 462 (defun hangul390-input-method (key) |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
463 "3-Bulsik 390 input method." |
95500 | 464 (if (or buffer-read-only (< key 33) (>= key 127)) |
465 (list key) | |
466 (quail-setup-overlays nil) | |
467 (let ((input-method-function nil) | |
468 (echo-keystrokes 0) | |
469 (help-char nil)) | |
470 (setq hangul-queue (make-vector 6 0)) | |
471 (hangul390-input-method-internal key) | |
472 (unwind-protect | |
473 (catch 'exit-input-loop | |
474 (while t | |
475 (let* ((seq (read-key-sequence nil)) | |
476 (cmd (lookup-key hangul-im-keymap seq)) | |
477 key) | |
478 (cond ((and (stringp seq) | |
479 (= 1 (length seq)) | |
480 (setq key (aref seq 0)) | |
481 (and (>= key 33) (< key 127))) | |
482 (hangul390-input-method-internal key)) | |
483 ((commandp cmd) | |
484 (call-interactively cmd)) | |
485 (t | |
486 (setq unread-command-events (listify-key-sequence seq)) | |
487 (throw 'exit-input-loop nil)))))) | |
488 (quail-delete-overlays))))) | |
38453
519983161a46
Some fixes to follow lisp coding conventions and typo fixes.
Pavel Janík <Pavel@Janik.cz>
parents:
37396
diff
changeset
|
489 |
95500 | 490 ;; Text shown by describe-input-method. Set to a proper text by |
491 ;; hangul-input-method-activate. | |
492 (defvar hangul-input-method-help-text nil) | |
493 (make-variable-buffer-local 'hangul-input-method-help-text) | |
494 | |
495 (defun hangul-input-method-activate (input-method func help-text &rest args) | |
496 "Activate Hangul input method INPUT-METHOD. | |
497 FUNC is a function to handle input key. | |
498 HELP-TEXT is a text set in `hangul-input-method-help-text'." | |
499 (setq inactivate-current-input-method-function 'hangul-input-method-inactivate | |
95582
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
500 describe-current-input-method-function 'hangul-input-method-help |
4d17533ba12f
Docstrings and comments improved.
Kenichi Handa <handa@m17n.org>
parents:
95514
diff
changeset
|
501 hangul-input-method-help-text help-text) |
95500 | 502 (quail-delete-overlays) |
503 (if (eq (selected-window) (minibuffer-window)) | |
504 (add-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer)) | |
505 (set (make-local-variable 'input-method-function) func)) | |
506 | |
507 (defun hangul-input-method-inactivate () | |
508 "Inactivate the current Hangul input method." | |
509 (interactive) | |
510 (unwind-protect | |
511 (progn | |
512 (quail-hide-guidance) | |
513 (quail-delete-overlays) | |
514 (setq describe-current-input-method-function nil)) | |
515 (kill-local-variable 'input-method-function))) | |
516 | |
517 (defun hangul-input-method-help () | |
518 "Describe the current Hangul input method." | |
519 (interactive) | |
520 (with-output-to-temp-buffer "*Help*" | |
521 (princ hangul-input-method-help-text))) | |
522 | |
523 (provide 'hangul) | |
524 | |
95514 | 525 ;; arch-tag: 26bc93fc-64ee-4fb1-b26d-22220d132dbe |
38453
519983161a46
Some fixes to follow lisp coding conventions and typo fixes.
Pavel Janík <Pavel@Janik.cz>
parents:
37396
diff
changeset
|
526 ;;; hangul.el ends here |