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