Mercurial > emacs
comparison leim/quail/hangul.el @ 95637:572e23ede3f0
Docstrings improved.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Sat, 07 Jun 2008 12:42:33 +0000 |
parents | 4d17533ba12f |
children | 434f2e8f84e9 |
comparison
equal
deleted
inserted
replaced
95636:e8dc32485a80 | 95637:572e23ede3f0 |
---|---|
29 | 29 |
30 (require 'quail) | 30 (require 'quail) |
31 (require 'cl) | 31 (require 'cl) |
32 (require 'hanja-util) | 32 (require 'hanja-util) |
33 | 33 |
34 ;; Hangul double jamo table. | 34 ;; Hangul double Jamo table. |
35 ;; The format is an alist of JAMO-TYPE vs. DOUBLE-JAMO-TABLE. | 35 ;; The format is an alist of JAMO-TYPE vs. DOUBLE-JAMO-TABLE. |
36 ;; | 36 ;; |
37 ;; JAMO-TYPE is a symbol `cho' for Choseong, `jung' for Jungseong, and | 37 ;; JAMO-TYPE is a symbol `cho' for Choseong, `jung' for Jungseong, and |
38 ;; `jong' for Jongseong. | 38 ;; `jong' for Jongseong. |
39 ;; | 39 ;; |
40 ;; DOUBLE-JAMO-TABLE is an alist of jamo index vs. the vector of jamo | 40 ;; DOUBLE-JAMO-TABLE is an alist of Jamo index vs. the vector of Jamo |
41 ;; indies that can be combined with the car part. | 41 ;; indies that can be combined with the car part. |
42 ;; | 42 ;; |
43 ;; Jamo index is a relative index in `hangul Compatibility Jamo' area | 43 ;; Jamo index is a relative index in `hangul Compatibility Jamo' area |
44 ;; of the Unicode (i.e. 1 for U+3131). | 44 ;; of the Unicode (i.e. 1 for U+3131). |
45 | 45 |
58 (18 . [18 21]) | 58 (18 . [18 21]) |
59 (21 . [21]))))) | 59 (21 . [21]))))) |
60 | 60 |
61 ;; Hangul 2-Bulsik keymap. | 61 ;; Hangul 2-Bulsik keymap. |
62 ;; It converts an ASCII code A-Z, a-z, to the corresponding hangul | 62 ;; It converts an ASCII code A-Z, a-z, to the corresponding hangul |
63 ;; jamo index. | 63 ;; Jamo index. |
64 | 64 |
65 (defconst hangul2-keymap | 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]) | 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]) |
67 | 67 |
68 ;; Hangul 3-Bulsik final keymap. 3-Bulsik use full keyboard layout. | 68 ;; Hangul 3-Bulsik final keymap. 3-Bulsik use full keyboard layout. |
91 (define-key map [f9] 'hangul-to-hanja-conversion) | 91 (define-key map [f9] 'hangul-to-hanja-conversion) |
92 map) | 92 map) |
93 "Keymap for Hangul method. It is used by all Hangul input method.") | 93 "Keymap for Hangul method. It is used by all Hangul input method.") |
94 | 94 |
95 ;; Current input character buffer. Store separated hangul character. | 95 ;; Current input character buffer. Store separated hangul character. |
96 ;; First and second index of vector stored "Choseong". | 96 ;; The first and second are Choseong position. |
97 ;; Third and forth index of vector stored "Jungseong". | 97 ;; The third and forth are Jungseong position. |
98 ;; Fifth and sixth index of vector stored "Jongseong". | 98 ;; The fifth and sixth are Jongseong position. |
99 ;; The second, forth and sixth are double Jamo position. | |
99 (defvar hangul-queue | 100 (defvar hangul-queue |
100 (make-vector 6 0)) | 101 (make-vector 6 0)) |
101 | 102 |
102 (defsubst notzerop (number) | 103 (defsubst notzerop (number) |
103 (not (zerop number))) | 104 (not (zerop number))) |
126 (- jong | 127 (- jong |
127 (cond ((< jong 8) 0) | 128 (cond ((< jong 8) 0) |
128 ((< jong 19) 1) | 129 ((< jong 19) 1) |
129 ((< jong 25) 2) | 130 ((< jong 25) 2) |
130 (t 3)))) | 131 (t 3)))) |
131 (+ #x3130 | 132 (+ #x3130 |
132 (cond ((/= cho 0) cho) | 133 (cond ((/= cho 0) cho) |
133 ((/= jung 0) jung) | 134 ((/= jung 0) jung) |
134 ((/= jong 0) jong))))) | 135 ((/= jong 0) jong))))) |
135 "")) | 136 "")) |
136 | 137 |
137 (defun hangul-insert-character (&rest queues) | 138 (defun hangul-insert-character (&rest queues) |
138 "Insert characters generated from QUEUEs. | 139 "Insert characters generated from QUEUEs. |
139 Each QUEUE has the same form as `hangul-queue'. | 140 Each QUEUE has the same form as `hangul-queue'. |
157 (+ (aref queue 2) (hangul-djamo 'jung (aref queue 2) (aref queue 3))) | 158 (+ (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 (+ (aref queue 4) (hangul-djamo 'jong (aref queue 4) (aref queue 5))))) |
159 (move-overlay quail-overlay (1+ (overlay-start quail-overlay)) (point)))) | 160 (move-overlay quail-overlay (1+ (overlay-start quail-overlay)) (point)))) |
160 | 161 |
161 (defun hangul-djamo (jamo char1 char2) | 162 (defun hangul-djamo (jamo char1 char2) |
162 "Return the dobule jamo index calculated from the arguments. | 163 "Return the dobule Jamo index calculated from the arguments. |
163 JAMO is a type of Hangul jamo; `cho', `jung', or `jong'. | 164 JAMO is a type of Hangul Jamo; `cho', `jung', or `jong'. |
164 CHAR1 and CAHR2 are Hangul jamo indices. | 165 CHAR1 and CAHR2 are Hangul Jamo indices. |
165 Return nil if CHAR1 and CHAR2 can not combined." | 166 Return nil if CHAR1 and CHAR2 can not combined." |
166 (let* ((jamo (cdr (assoc jamo hangul-djamo-table))) | 167 (let* ((jamo (cdr (assoc jamo hangul-djamo-table))) |
167 (char1 (cdr (assoc char1 jamo)))) | 168 (char1 (cdr (assoc char1 jamo)))) |
168 (if char1 | 169 (if char1 |
169 (let ((i (length char1))) | 170 (let ((i (length char1))) |
171 (while (> i 0) | 172 (while (> i 0) |
172 (if (= char2 (aref char1 (1- i))) | 173 (if (= char2 (aref char1 (1- i))) |
173 (throw 'found i)) | 174 (throw 'found i)) |
174 (setf i (1- i)))) | 175 (setf i (1- i)))) |
175 0)) | 176 0)) |
176 0))) | 177 0))) |
177 | 178 |
178 (defsubst hangul2-input-method-jaum (char) | 179 (defsubst hangul2-input-method-jaum (char) |
179 "Store hangul jamo indice CHAR in `hangul-queue'. | 180 "Store Hangul Jamo indice CHAR in `hangul-queue'. |
180 Maybe, it is a Hangul 2-Bulsik jaum. | 181 It is a Hangul 2-Bulsik Jaum. |
181 This function processes a Hangul 2-Bulsik jaum. | 182 This function processes a Hangul 2-Bulsik Jaum. |
182 Unless the function inserts CHAR to current input queue, | 183 The Hangul 2-Bulsik is composed of a Jaum and a Moum. |
183 commit current character and then start next character. | 184 The Jaum can be located in a Choseong position and a Jongseong position. |
184 The Hangul 2-Bulsik is composed of `jaum' and `moum'." | 185 Unless the function inserts CHAR to `hangul-queue', |
186 commit current `hangul-queue' and then set a new `hangul-queue', | |
187 and insert CHAR to new `hangul-queue'." | |
185 (if (cond ((zerop (aref hangul-queue 0)) | 188 (if (cond ((zerop (aref hangul-queue 0)) |
186 (aset hangul-queue 0 char)) | 189 (aset hangul-queue 0 char)) |
187 ((and (zerop (aref hangul-queue 1)) | 190 ((and (zerop (aref hangul-queue 1)) |
188 (zerop (aref hangul-queue 2)) | 191 (zerop (aref hangul-queue 2)) |
189 (notzerop (hangul-djamo 'cho (aref hangul-queue 0) char))) | 192 (notzerop (hangul-djamo 'cho (aref hangul-queue 0) char))) |
226 'jong | 229 'jong |
227 (aref hangul-queue 4) | 230 (aref hangul-queue 4) |
228 char))))) | 231 char))))) |
229 (aset hangul-queue 5 char))) | 232 (aset hangul-queue 5 char))) |
230 (hangul-insert-character hangul-queue) | 233 (hangul-insert-character hangul-queue) |
231 (hangul-insert-character hangul-queue | 234 (hangul-insert-character hangul-queue |
232 (setq hangul-queue (vector char 0 0 0 0 0))))) | 235 (setq hangul-queue (vector char 0 0 0 0 0))))) |
233 | 236 |
234 (defsubst hangul2-input-method-moum (char) | 237 (defsubst hangul2-input-method-moum (char) |
235 "Store hangul jamo indice CHAR in `hangul-queue'. | 238 "Store Hangul Jamo indice CHAR in `hangul-queue'. |
236 Maybe, it is a Hangul 2-Bulsik moum. | 239 It is a Hangul 2-Bulsik Moum. |
237 This function process a Hangul 2-Bulsik moum. | 240 This function process a Hangul 2-Bulsik Moum. |
241 The Moum can be located in a Jungseong position. | |
238 Other parts are the same as a `hangul2-input-method-jaum'." | 242 Other parts are the same as a `hangul2-input-method-jaum'." |
239 (if (cond ((zerop (aref hangul-queue 2)) | 243 (if (cond ((zerop (aref hangul-queue 2)) |
240 (aset hangul-queue 2 char)) | 244 (aset hangul-queue 2 char)) |
241 ((and (zerop (aref hangul-queue 3)) | 245 ((and (zerop (aref hangul-queue 3)) |
242 (zerop (aref hangul-queue 4)) | 246 (zerop (aref hangul-queue 4)) |
243 (notzerop (hangul-djamo 'jung (aref hangul-queue 2) char))) | 247 (notzerop (hangul-djamo 'jung (aref hangul-queue 2) char))) |
244 (aset hangul-queue 3 char))) | 248 (aset hangul-queue 3 char))) |
245 (hangul-insert-character hangul-queue) | 249 (hangul-insert-character hangul-queue) |
246 (let ((next-char (vector 0 0 char 0 0 0))) | 250 (let ((next-char (vector 0 0 char 0 0 0))) |
247 (cond ((notzerop (aref hangul-queue 5)) | 251 (cond ((notzerop (aref hangul-queue 5)) |
248 (aset next-char 0 (aref hangul-queue 5)) | 252 (aset next-char 0 (aref hangul-queue 5)) |
249 (aset hangul-queue 5 0)) | 253 (aset hangul-queue 5 0)) |
250 ((notzerop (aref hangul-queue 4)) | 254 ((notzerop (aref hangul-queue 4)) |
251 (aset next-char 0 (aref hangul-queue 4)) | 255 (aset next-char 0 (aref hangul-queue 4)) |
252 (aset hangul-queue 4 0))) | 256 (aset hangul-queue 4 0))) |
253 (hangul-insert-character hangul-queue | 257 (hangul-insert-character hangul-queue |
254 (setq hangul-queue next-char))))) | 258 (setq hangul-queue next-char))))) |
255 | 259 |
256 (defsubst hangul3-input-method-cho (char) | 260 (defsubst hangul3-input-method-cho (char) |
257 "Store hangul jamo indice CHAR in `hangul-queue'. | 261 "Store Hangul Jamo indice CHAR in `hangul-queue'. |
258 Maybe, it is a Hangul 3-Bulsik choseong. | 262 It is a Hangul 3-Bulsik Choseong. |
259 This function process a Hangul 3-Bulsik choseong. | 263 This function process a Hangul 3-Bulsik Choseong. |
260 The Hangul 3-Bulsik is composed of `choseong', `jungseong' and `jongseong'. | 264 The Hangul 3-Bulsik is composed of a Choseong, a Jungseong and a Jongseong. |
265 The Choseong can be located in a Choseong position. | |
261 Other parts are the same as a `hangul2-input-method-jaum'." | 266 Other parts are the same as a `hangul2-input-method-jaum'." |
262 (if (cond ((and (zerop (aref hangul-queue 0)) | 267 (if (cond ((and (zerop (aref hangul-queue 0)) |
263 (zerop (aref hangul-queue 4))) | 268 (zerop (aref hangul-queue 4))) |
264 (aset hangul-queue 0 char)) | 269 (aset hangul-queue 0 char)) |
265 ((and (zerop (aref hangul-queue 1)) | 270 ((and (zerop (aref hangul-queue 1)) |
266 (zerop (aref hangul-queue 2)) | 271 (zerop (aref hangul-queue 2)) |
267 (notzerop (hangul-djamo 'cho (aref hangul-queue 0) char))) | 272 (notzerop (hangul-djamo 'cho (aref hangul-queue 0) char))) |
268 (aset hangul-queue 1 char))) | 273 (aset hangul-queue 1 char))) |
269 (hangul-insert-character hangul-queue) | 274 (hangul-insert-character hangul-queue) |
270 (hangul-insert-character hangul-queue | 275 (hangul-insert-character hangul-queue |
271 (setq hangul-queue (vector char 0 0 0 0 0))))) | 276 (setq hangul-queue (vector char 0 0 0 0 0))))) |
272 | 277 |
273 (defsubst hangul3-input-method-jung (char) | 278 (defsubst hangul3-input-method-jung (char) |
274 "Store hangul jamo indice CHAR in `hangul-queue'. | 279 "Store Hangul Jamo indice CHAR in `hangul-queue'. |
275 Maybe, it is a Hangul 3-Bulsik jungseong. | 280 It is a Hangul 3-Bulsik Jungseong. |
276 This function process a Hangul 3-Bulsik jungseong. | 281 This function process a Hangul 3-Bulsik Jungseong. |
282 The Jungseong can be located in a Jungseong position. | |
277 Other parts are the same as a `hangul3-input-method-cho'." | 283 Other parts are the same as a `hangul3-input-method-cho'." |
278 (if (cond ((and (zerop (aref hangul-queue 2)) | 284 (if (cond ((and (zerop (aref hangul-queue 2)) |
279 (zerop (aref hangul-queue 4))) | 285 (zerop (aref hangul-queue 4))) |
280 (aset hangul-queue 2 char)) | 286 (aset hangul-queue 2 char)) |
281 ((and (zerop (aref hangul-queue 3)) | 287 ((and (zerop (aref hangul-queue 3)) |
282 (notzerop (hangul-djamo 'jung (aref hangul-queue 2) char))) | 288 (notzerop (hangul-djamo 'jung (aref hangul-queue 2) char))) |
283 (aset hangul-queue 3 char))) | 289 (aset hangul-queue 3 char))) |
284 (hangul-insert-character hangul-queue) | 290 (hangul-insert-character hangul-queue) |
285 (hangul-insert-character hangul-queue | 291 (hangul-insert-character hangul-queue |
286 (setq hangul-queue (vector 0 0 char 0 0 0))))) | 292 (setq hangul-queue (vector 0 0 char 0 0 0))))) |
287 | 293 |
288 (defsubst hangul3-input-method-jong (char) | 294 (defsubst hangul3-input-method-jong (char) |
289 "Store hangul jamo indice CHAR in `hangul-queue'. | 295 "Store Hangul Jamo indice CHAR in `hangul-queue'. |
290 Maybe, it is a Hangul 3-Bulsik jongseong. | 296 It is a Hangul 3-Bulsik Jongseong. |
291 This function process a Hangul 3-Bulsik jongseong. | 297 This function process a Hangul 3-Bulsik Jongseong. |
298 The Jongseong can be located in a Jongseong position. | |
292 Other parts are the same as a `hangul3-input-method-cho'." | 299 Other parts are the same as a `hangul3-input-method-cho'." |
293 (if (cond ((and (zerop (aref hangul-queue 4)) | 300 (if (cond ((and (zerop (aref hangul-queue 4)) |
294 (notzerop (aref hangul-queue 0)) | 301 (notzerop (aref hangul-queue 0)) |
295 (notzerop (aref hangul-queue 2)) | 302 (notzerop (aref hangul-queue 2)) |
296 (numberp | 303 (numberp |
326 'jong | 333 'jong |
327 (aref hangul-queue 4) | 334 (aref hangul-queue 4) |
328 char))))) | 335 char))))) |
329 (aset hangul-queue 6 char))) | 336 (aset hangul-queue 6 char))) |
330 (hangul-insert-character hangul-queue) | 337 (hangul-insert-character hangul-queue) |
331 (if (zerop (apply '+ (append hangul-queue nil))) | 338 (if (zerop (apply '+ (append hangul-queue nil))) |
332 (hangul-insert-character (setq hangul-queue (vector 0 0 0 0 char 0))) | 339 (hangul-insert-character (setq hangul-queue (vector 0 0 0 0 char 0))) |
333 (hangul-insert-character hangul-queue | 340 (hangul-insert-character hangul-queue |
334 (setq hangul-queue (vector 0 0 0 0 char 0)))))) | 341 (setq hangul-queue (vector 0 0 0 0 char 0)))))) |
335 | 342 |
336 (defun hangul-delete-backward-char () | 343 (defun hangul-delete-backward-char () |
337 "Delete the previous hangul character by jaso units." | 344 "Delete the previous hangul character by Jaso units." |
338 (interactive) | 345 (interactive) |
339 (let ((i 5)) | 346 (let ((i 5)) |
340 (while (and (> i 0) (zerop (aref hangul-queue i))) | 347 (while (and (> i 0) (zerop (aref hangul-queue i))) |
341 (setq i (1- i))) | 348 (setq i (1- i))) |
342 (aset hangul-queue i 0)) | 349 (aset hangul-queue i 0)) |
343 (if (notzerop (apply '+ (append hangul-queue nil))) | 350 (if (notzerop (apply '+ (append hangul-queue nil))) |
344 (hangul-insert-character hangul-queue) | 351 (hangul-insert-character hangul-queue) |
345 (delete-backward-char 1))) | 352 (delete-backward-char 1))) |
346 | 353 |
347 (defun hangul-to-hanja-conversion () | 354 (defun hangul-to-hanja-conversion () |
348 "Convert the previous hangul character to the corresponding hanja character." | 355 "Convert the previous hangul character to the corresponding hanja character." |
349 (interactive) | 356 (interactive) |
350 (let ((echo-keystrokes 0) | 357 (let ((echo-keystrokes 0) |
366 ((or (= key ?E) (= key ?Q) (= key ?R) | 373 ((or (= key ?E) (= key ?Q) (= key ?R) |
367 (= key ?T) (= key ?W)) 1) | 374 (= key ?T) (= key ?W)) 1) |
368 (t 0))))) | 375 (t 0))))) |
369 (if (< char 31) | 376 (if (< char 31) |
370 (hangul2-input-method-jaum char) | 377 (hangul2-input-method-jaum char) |
371 (hangul2-input-method-moum char)))) | 378 (hangul2-input-method-moum char)))) |
372 | 379 |
373 (defun hangul2-input-method (key) | 380 (defun hangul2-input-method (key) |
374 "2-Bulsik input method." | 381 "2-Bulsik input method." |
375 (if (or buffer-read-only (not (alphabetp key))) | 382 (if (or buffer-read-only (not (alphabetp key))) |
376 (list key) | 383 (list key) |
377 (quail-setup-overlays nil) | 384 (quail-setup-overlays nil) |
378 (let ((input-method-function nil) | 385 (let ((input-method-function nil) |
379 (echo-keystrokes 0) | 386 (echo-keystrokes 0) |
380 (help-char nil)) | 387 (help-char nil)) |
381 (setq hangul-queue (make-vector 6 0)) | 388 (setq hangul-queue (make-vector 6 0)) |
382 (hangul2-input-method-internal key) | 389 (hangul2-input-method-internal key) |
383 (unwind-protect | 390 (unwind-protect |
384 (catch 'exit-input-loop | 391 (catch 'exit-input-loop |
385 (while t | 392 (while t |
386 (let* ((seq (read-key-sequence nil)) | 393 (let* ((seq (read-key-sequence nil)) |
387 (cmd (lookup-key hangul-im-keymap seq)) | 394 (cmd (lookup-key hangul-im-keymap seq)) |
388 key) | 395 key) |
389 (cond ((and (stringp seq) | 396 (cond ((and (stringp seq) |
390 (= 1 (length seq)) | 397 (= 1 (length seq)) |
391 (setq key (aref seq 0)) | 398 (setq key (aref seq 0)) |
392 (alphabetp key)) | 399 (alphabetp key)) |
393 (hangul2-input-method-internal key)) | 400 (hangul2-input-method-internal key)) |
394 ((commandp cmd) | 401 ((commandp cmd) |
395 (call-interactively cmd)) | 402 (call-interactively cmd)) |
396 (t | 403 (t |
397 (setq unread-command-events (listify-key-sequence seq)) | 404 (setq unread-command-events (listify-key-sequence seq)) |
398 (throw 'exit-input-loop nil)))))) | 405 (throw 'exit-input-loop nil)))))) |
399 (quail-delete-overlays))))) | 406 (quail-delete-overlays))))) |
400 | 407 |
401 ;; Support function for `hangul3-input-method'. Actually, this | 408 ;; Support function for `hangul3-input-method'. Actually, this |
402 ;; function handles the Hangul 3-Bulsik final. KEY is an entered key | 409 ;; function handles the Hangul 3-Bulsik final. KEY is an entered key |
403 ;; code used for looking up `hangul3-keymap'." | 410 ;; code used for looking up `hangul3-keymap'." |
404 (defun hangul3-input-method-internal (key) | 411 (defun hangul3-input-method-internal (key) |
416 | 423 |
417 (defun hangul3-input-method (key) | 424 (defun hangul3-input-method (key) |
418 "3-Bulsik final input method." | 425 "3-Bulsik final input method." |
419 (if (or buffer-read-only (< key 33) (>= key 127)) | 426 (if (or buffer-read-only (< key 33) (>= key 127)) |
420 (list key) | 427 (list key) |
421 (quail-setup-overlays nil) | 428 (quail-setup-overlays nil) |
422 (let ((input-method-function nil) | 429 (let ((input-method-function nil) |
423 (echo-keystrokes 0) | 430 (echo-keystrokes 0) |
424 (help-char nil)) | 431 (help-char nil)) |
425 (setq hangul-queue (make-vector 6 0)) | 432 (setq hangul-queue (make-vector 6 0)) |
426 (hangul3-input-method-internal key) | 433 (hangul3-input-method-internal key) |
427 (unwind-protect | 434 (unwind-protect |
428 (catch 'exit-input-loop | 435 (catch 'exit-input-loop |
429 (while t | 436 (while t |
430 (let* ((seq (read-key-sequence nil)) | 437 (let* ((seq (read-key-sequence nil)) |
431 (cmd (lookup-key hangul-im-keymap seq)) | 438 (cmd (lookup-key hangul-im-keymap seq)) |
432 key) | 439 key) |
433 (cond ((and (stringp seq) | 440 (cond ((and (stringp seq) |
434 (= 1 (length seq)) | 441 (= 1 (length seq)) |
435 (setq key (aref seq 0)) | 442 (setq key (aref seq 0)) |
436 (and (>= key 33) (< key 127))) | 443 (and (>= key 33) (< key 127))) |
437 (hangul3-input-method-internal key)) | 444 (hangul3-input-method-internal key)) |
438 ((commandp cmd) | 445 ((commandp cmd) |
439 (call-interactively cmd)) | 446 (call-interactively cmd)) |
440 (t | 447 (t |
441 (setq unread-command-events (listify-key-sequence seq)) | 448 (setq unread-command-events (listify-key-sequence seq)) |
442 (throw 'exit-input-loop nil)))))) | 449 (throw 'exit-input-loop nil)))))) |
443 (quail-delete-overlays))))) | 450 (quail-delete-overlays))))) |
444 | 451 |
445 ;; Support function for `hangul390-input-method'. Actually, this | 452 ;; Support function for `hangul390-input-method'. Actually, this |
446 ;; function handles the Hangul 3-Bulsik 390. KEY is an entered key | 453 ;; function handles the Hangul 3-Bulsik 390. KEY is an entered key |
447 ;; code used for looking up `hangul390-keymap'." | 454 ;; code used for looking up `hangul390-keymap'." |
448 (defun hangul390-input-method-internal (key) | 455 (defun hangul390-input-method-internal (key) |
461 | 468 |
462 (defun hangul390-input-method (key) | 469 (defun hangul390-input-method (key) |
463 "3-Bulsik 390 input method." | 470 "3-Bulsik 390 input method." |
464 (if (or buffer-read-only (< key 33) (>= key 127)) | 471 (if (or buffer-read-only (< key 33) (>= key 127)) |
465 (list key) | 472 (list key) |
466 (quail-setup-overlays nil) | 473 (quail-setup-overlays nil) |
467 (let ((input-method-function nil) | 474 (let ((input-method-function nil) |
468 (echo-keystrokes 0) | 475 (echo-keystrokes 0) |
469 (help-char nil)) | 476 (help-char nil)) |
470 (setq hangul-queue (make-vector 6 0)) | 477 (setq hangul-queue (make-vector 6 0)) |
471 (hangul390-input-method-internal key) | 478 (hangul390-input-method-internal key) |
472 (unwind-protect | 479 (unwind-protect |
473 (catch 'exit-input-loop | 480 (catch 'exit-input-loop |
474 (while t | 481 (while t |
475 (let* ((seq (read-key-sequence nil)) | 482 (let* ((seq (read-key-sequence nil)) |
476 (cmd (lookup-key hangul-im-keymap seq)) | 483 (cmd (lookup-key hangul-im-keymap seq)) |
477 key) | 484 key) |
478 (cond ((and (stringp seq) | 485 (cond ((and (stringp seq) |
479 (= 1 (length seq)) | 486 (= 1 (length seq)) |
480 (setq key (aref seq 0)) | 487 (setq key (aref seq 0)) |
481 (and (>= key 33) (< key 127))) | 488 (and (>= key 33) (< key 127))) |
482 (hangul390-input-method-internal key)) | 489 (hangul390-input-method-internal key)) |
483 ((commandp cmd) | 490 ((commandp cmd) |
484 (call-interactively cmd)) | 491 (call-interactively cmd)) |
485 (t | 492 (t |
486 (setq unread-command-events (listify-key-sequence seq)) | 493 (setq unread-command-events (listify-key-sequence seq)) |
487 (throw 'exit-input-loop nil)))))) | 494 (throw 'exit-input-loop nil)))))) |
488 (quail-delete-overlays))))) | 495 (quail-delete-overlays))))) |
489 | 496 |
490 ;; Text shown by describe-input-method. Set to a proper text by | 497 ;; Text shown by describe-input-method. Set to a proper text by |
491 ;; hangul-input-method-activate. | 498 ;; hangul-input-method-activate. |
492 (defvar hangul-input-method-help-text nil) | 499 (defvar hangul-input-method-help-text nil) |
493 (make-variable-buffer-local 'hangul-input-method-help-text) | 500 (make-variable-buffer-local 'hangul-input-method-help-text) |
495 (defun hangul-input-method-activate (input-method func help-text &rest args) | 502 (defun hangul-input-method-activate (input-method func help-text &rest args) |
496 "Activate Hangul input method INPUT-METHOD. | 503 "Activate Hangul input method INPUT-METHOD. |
497 FUNC is a function to handle input key. | 504 FUNC is a function to handle input key. |
498 HELP-TEXT is a text set in `hangul-input-method-help-text'." | 505 HELP-TEXT is a text set in `hangul-input-method-help-text'." |
499 (setq inactivate-current-input-method-function 'hangul-input-method-inactivate | 506 (setq inactivate-current-input-method-function 'hangul-input-method-inactivate |
500 describe-current-input-method-function 'hangul-input-method-help | 507 describe-current-input-method-function 'hangul-input-method-help |
501 hangul-input-method-help-text help-text) | 508 hangul-input-method-help-text help-text) |
502 (quail-delete-overlays) | 509 (quail-delete-overlays) |
503 (if (eq (selected-window) (minibuffer-window)) | 510 (if (eq (selected-window) (minibuffer-window)) |
504 (add-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer)) | 511 (add-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer)) |
505 (set (make-local-variable 'input-method-function) func)) | 512 (set (make-local-variable 'input-method-function) func)) |
506 | 513 |
507 (defun hangul-input-method-inactivate () | 514 (defun hangul-input-method-inactivate () |
508 "Inactivate the current Hangul input method." | 515 "Inactivate the current Hangul input method." |
509 (interactive) | 516 (interactive) |
510 (unwind-protect | 517 (unwind-protect |
511 (progn | 518 (progn |
512 (quail-hide-guidance) | 519 (quail-hide-guidance) |
513 (quail-delete-overlays) | 520 (quail-delete-overlays) |
514 (setq describe-current-input-method-function nil)) | 521 (setq describe-current-input-method-function nil)) |
515 (kill-local-variable 'input-method-function))) | 522 (kill-local-variable 'input-method-function))) |
516 | 523 |
517 (defun hangul-input-method-help () | 524 (defun hangul-input-method-help () |
518 "Describe the current Hangul input method." | 525 "Describe the current Hangul input method." |
519 (interactive) | 526 (interactive) |