1 ;;; quail.el --- Provides simple input method for multilingual text
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
4 ;; Licensed to the Free Software Foundation.
6 ;; Author: Kenichi HANDA <handa@etl.go.jp>
7 ;; Naoto TAKAHASHI <ntakahas@etl.go.jp>
8 ;; Maintainer: Kenichi HANDA <handa@etl.go.jp>
9 ;; Keywords: mule, multilingual, input method
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 ;; Boston, MA 02111-1307, USA.
30 ;; In Quail minor mode, you can input multilingual text easily. By
31 ;; defining a translation table (named Quail map) which maps ASCII key
32 ;; string to multilingual character or string, you can input any text
33 ;; from ASCII keyboard.
35 ;; We use words "translation" and "conversion" differently. The
36 ;; former is done by Quail package itself, the latter is the further
37 ;; process of converting a translated text to some more desirable
38 ;; text. For instance, Quail package for Japanese (`quail-jp')
39 ;; translates Roman text (transliteration of Japanese in Latin
40 ;; alphabets) to Hiragana text, which is then converted to
41 ;; Kanji-and-Kana mixed text or Katakana text by commands specified in
42 ;; CONVERSION-KEYS argument of the Quail package.
48 ;; Buffer local variables
50 (defvar quail-current-package nil
51 "The current Quail package, which depends on the current input method.
52 See the documentation of `quail-package-alist' for the format.")
53 (make-variable-buffer-local 'quail-current-package)
54 (put 'quail-current-package 'permanent-local t)
56 ;; Quail uses the following two buffers to assist users.
57 ;; A buffer to show available key sequence or translation list.
58 (defvar quail-guidance-buf nil)
59 ;; A buffer to show completion list of the current key sequence.
60 (defvar quail-completion-buf nil)
62 ;; Each buffer in which Quail is activated should use different
64 (make-variable-buffer-local 'quail-guidance-buf)
65 (put 'quail-guidance-buf 'permanent-local t)
67 ;; A main window showing Quail guidance buffer.
68 (defvar quail-guidance-win nil)
69 (make-variable-buffer-local 'quail-guidance-win)
71 (defvar quail-overlay nil
72 "Overlay which covers the current translation region of Quail.")
73 (make-variable-buffer-local 'quail-overlay)
75 (defvar quail-conv-overlay nil
76 "Overlay which covers the text to be converted in Quail mode.")
77 (make-variable-buffer-local 'quail-conv-overlay)
79 (defvar quail-current-key nil
80 "Current key for translation in Quail mode.")
81 (make-variable-buffer-local 'quail-current-key)
83 (defvar quail-current-str nil
84 "Currently selected translation of the current key.")
85 (make-variable-buffer-local 'quail-current-str)
87 (defvar quail-current-translations nil
88 "Cons of indices and vector of possible translations of the current key.
89 Indices is a list of (CURRENT START END BLOCK BLOCKS), where
90 CURRENT is an index of the current translation,
91 START and END are indices of the start and end of the current block,
92 BLOCK is the current block index,
93 BLOCKS is a number of blocks of translation.")
94 (make-variable-buffer-local 'quail-current-translations)
96 (defvar quail-current-data nil
97 "Any Lisp object holding information of current translation status.
98 When a key sequence is mapped to TRANS and TRANS is a cons
99 of actual translation and some Lisp object to be referred
100 for translating the longer key sequence, this variable is set
101 to that Lisp object.")
102 (make-variable-buffer-local 'quail-current-data)
104 ;; Quail package handlers.
106 (defvar quail-package-alist nil
107 "List of Quail packages.
108 A Quail package is a list of these elements:
109 NAME, TITLE, QUAIL-MAP, GUIDANCE, DOCSTRING, TRANSLATION-KEYS,
110 FORGET-LAST-SELECTION, DETERMINISTIC, KBD-TRANSLATE, SHOW-LAYOUT,
111 DECODE-MAP, MAXIMUM-SHORTEST, OVERLAY-PLIST, UPDATE-TRANSLATION-FUNCTION,
112 CONVERSION-KEYS, SIMPLE.
114 QUAIL-MAP is a data structure to map key strings to translations. For
115 the format, see the documentation of `quail-map-p'.
117 DECODE-MAP is an alist of translations and corresponding keys.
119 See the documentation of `quail-define-package' for the other elements.")
121 ;; Return various slots in the current quail-package.
123 (defsubst quail-name ()
124 "Return the name of the current Quail package."
125 (nth 0 quail-current-package))
126 (defsubst quail-title ()
127 "Return the title of the current Quail package."
128 (nth 1 quail-current-package))
129 (defsubst quail-map ()
130 "Return the translation map of the current Quail package."
131 (nth 2 quail-current-package))
132 (defsubst quail-guidance ()
133 "Return an object used for `guidance' feature of the current Quail package.
134 See also the documentation of `quail-define-package'."
135 (nth 3 quail-current-package))
136 (defsubst quail-docstring ()
137 "Return the documentation string of the current Quail package."
138 (nth 4 quail-current-package))
139 (defsubst quail-translation-keymap ()
140 "Return translation keymap in the current Quail package.
141 Translation keymap is a keymap used while translation region is active."
142 (nth 5 quail-current-package))
143 (defsubst quail-forget-last-selection ()
144 "Return `forget-last-selection' flag of the current Quail package.
145 See also the documentation of `quail-define-package'."
146 (nth 6 quail-current-package))
147 (defsubst quail-deterministic ()
148 "Return `deterministic' flag of the current Quail package.
149 See also the documentation of `quail-define-package'."
150 (nth 7 quail-current-package))
151 (defsubst quail-kbd-translate ()
152 "Return `kbd-translate' flag of the current Quail package.
153 See also the documentation of `quail-define-package'."
154 (nth 8 quail-current-package))
155 (defsubst quail-show-layout ()
156 "Return `show-layout' flag of the current Quail package.
157 See also the documentation of `quail-define-package'."
158 (nth 9 quail-current-package))
159 (defsubst quail-decode-map ()
160 "Return decode map of the current Quail package.
161 It is an alist of translations and corresponding keys."
162 (nth 10 quail-current-package))
163 (defsubst quail-maximum-shortest ()
164 "Return `maximum-shortest' flag of the current Quail package.
165 See also the documentation of `quail-define-package'."
166 (nth 11 quail-current-package))
167 (defsubst quail-overlay-plist ()
168 "Return property list of an overly used in the current Quail package."
169 (nth 12 quail-current-package))
170 (defsubst quail-update-translation-function ()
171 "Return a function for updating translation in the current Quail package."
172 (nth 13 quail-current-package))
173 (defsubst quail-conversion-keymap ()
174 "Return conversion keymap in the current Quail package.
175 Conversion keymap is a keymap used while conversion region is active
176 but translation region is not active."
177 (nth 14 quail-current-package))
178 (defsubst quail-simple ()
179 "Return t if the current Quail package is simple."
180 (nth 15 quail-current-package))
182 (defsubst quail-package (name)
183 "Return Quail package named NAME."
184 (assoc name quail-package-alist))
186 (defun quail-add-package (package)
187 "Add Quail package PACKAGE to `quail-package-alist'."
188 (let ((pac (quail-package (car package))))
190 (setcdr pac (cdr package))
191 (setq quail-package-alist (cons package quail-package-alist)))))
193 (defun quail-select-package (name)
194 "Select Quail package named NAME as the current Quail package."
195 (let ((package (quail-package name)))
197 (error "No Quail package `%s'" name))
198 (setq quail-current-package package)
199 (setq-default quail-current-package package)
203 (defun quail-use-package (package-name &rest libraries)
204 "Start using Quail package PACKAGE-NAME.
205 The remaining arguments are libraries to be loaded before using the package."
206 (let ((package (quail-package package-name)))
208 ;; Perhaps we have not yet loaded necessary libraries.
210 (if (not (load (car libraries) t))
212 (with-output-to-temp-buffer "*Help*"
213 (princ "Quail package \"")
215 (princ "\" can't be activated\n because library \"")
216 (princ (car libraries))
217 (princ "\" is not in `load-path'.
219 The most common case is that you have not yet installed appropriate
220 libraries in LEIM (Libraries of Emacs Input Method) which is
221 distributed separately from Emacs.
223 LEIM is available from the same ftp directory as Emacs."))
224 (error "Can't use the Quail package `%s'" package-name))
225 (setq libraries (cdr libraries))))))
226 (quail-select-package package-name)
227 (setq current-input-method-title (quail-title))
230 (defvar quail-translation-keymap
231 (let ((map (make-keymap))
234 (define-key map (char-to-string i) 'quail-other-command)
237 (define-key map (char-to-string i) 'quail-self-insert-command)
241 (define-key map (vector i) 'quail-self-insert-command)
243 (define-key map "\177" 'quail-delete-last-char)
244 (define-key map "\C-f" 'quail-next-translation)
245 (define-key map "\C-b" 'quail-prev-translation)
246 (define-key map "\C-n" 'quail-next-translation-block)
247 (define-key map "\C-p" 'quail-prev-translation-block)
248 (define-key map [right] 'quail-next-translation)
249 (define-key map [left] 'quail-prev-translation)
250 (define-key map [down] 'quail-next-translation-block)
251 (define-key map [up] 'quail-prev-translation-block)
252 (define-key map "\C-i" 'quail-completion)
253 (define-key map "\C-@" 'quail-select-current)
254 ;; Following simple.el, Enter key on numeric keypad selects the
255 ;; current translation just like `C-SPC', and `mouse-2' chooses
256 ;; any completion visible in the *Quail Completions* buffer.
257 (define-key map [kp-enter] 'quail-select-current)
258 (define-key map [mouse-2] 'quail-mouse-choose-completion)
259 (define-key map [down-mouse-2] nil)
260 (define-key map "\C-h" 'quail-translation-help)
261 (define-key map [?\C- ] 'quail-select-current)
262 (define-key map [tab] 'quail-completion)
263 (define-key map [delete] 'quail-delete-last-char)
264 (define-key map [backspace] 'quail-delete-last-char)
266 "Keymap used processing translation in complex Quail modes.
267 Only a few especially complex input methods use this map;
268 most use `quail-simple-translation-keymap' instead.
269 This map is activated while translation region is active.")
271 (defvar quail-simple-translation-keymap
272 (let ((map (make-keymap))
275 (define-key map (char-to-string i) 'quail-other-command)
278 (define-key map (char-to-string i) 'quail-self-insert-command)
280 (define-key map "\177" 'quail-delete-last-char)
281 (define-key map [delete] 'quail-delete-last-char)
282 (define-key map [backspace] 'quail-delete-last-char)
283 ;;(let ((meta-map (make-sparse-keymap)))
284 ;;(define-key map (char-to-string meta-prefix-char) meta-map)
285 ;;(define-key map [escape] meta-map))
287 "Keymap used while processing translation in simple Quail modes.
288 A few especially complex input methods use `quail-translation-keymap' instead.
289 This map is activated while translation region is active.")
291 (defvar quail-conversion-keymap
292 (let ((map (make-keymap))
295 (define-key map (char-to-string i) 'quail-self-insert-command)
299 (define-key map (vector i) 'quail-self-insert-command)
301 (define-key map "\C-b" 'quail-conversion-backward-char)
302 (define-key map "\C-f" 'quail-conversion-forward-char)
303 (define-key map "\C-a" 'quail-conversion-beginning-of-region)
304 (define-key map "\C-e" 'quail-conversion-end-of-region)
305 (define-key map "\C-d" 'quail-conversion-delete-char)
306 (define-key map "\C-k" 'quail-conversion-delete-tail)
307 (define-key map "\C-h" 'quail-translation-help)
308 (define-key map "\177" 'quail-conversion-backward-delete-char)
309 (define-key map [delete] 'quail-conversion-backward-delete-char)
310 (define-key map [backspace] 'quail-conversion-backward-delete-char)
312 "Keymap used for processing conversion in Quail mode.
313 This map is activated while conversion region is active but translation
314 region is not active.")
317 (defun quail-define-package (name language title
318 &optional guidance docstring translation-keys
319 forget-last-selection deterministic
320 kbd-translate show-layout create-decode-map
321 maximum-shortest overlay-plist
322 update-translation-function
323 conversion-keys simple)
324 "Define NAME as a new Quail package for input LANGUAGE.
325 TITLE is a string to be displayed at mode-line to indicate this package.
326 Optional arguments are GUIDANCE, DOCSTRING, TRANSLATION-KEYS,
327 FORGET-LAST-SELECTION, DETERMINISTIC, KBD-TRANSLATE, SHOW-LAYOUT,
328 CREATE-DECODE-MAP, MAXIMUM-SHORTEST, OVERLAY-PLIST,
329 UPDATE-TRANSLATION-FUNCTION, CONVERSION-KEYS and SIMPLE.
331 GUIDANCE specifies how a guidance string is shown in echo area.
332 If it is t, list of all possible translations for the current key is shown
333 with the currently selected translation being highlighted.
334 If it is an alist, the element has the form (CHAR . STRING). Each character
335 in the current key is searched in the list and the corresponding string is
337 If it is nil, the current key is shown.
339 DOCSTRING is the documentation string of this package.
341 TRANSLATION-KEYS specifies additional key bindings used while translation
342 region is active. It is an alist of single key character vs. corresponding
343 command to be called.
345 FORGET-LAST-SELECTION non-nil means a selected translation is not kept
346 for the future to translate the same key. If this flag is nil, a
347 translation selected for a key is remembered so that it can be the
348 first candidate when the same key is entered later.
350 DETERMINISTIC non-nil means the first candidate of translation is
351 selected automatically without allowing users to select another
352 translation for a key. In this case, unselected translations are of
353 no use for an interactive use of Quail but can be used by some other
354 programs. If this flag is non-nil, FORGET-LAST-SELECTION is also set
357 KBD-TRANSLATE non-nil means input characters are translated from a
358 user's keyboard layout to the standard keyboard layout. See the
359 documentation of `quail-keyboard-layout' and
360 `quail-keyboard-layout-standard' for more detail.
362 SHOW-LAYOUT non-nil means the `quail-help' command should show
363 the user's keyboard layout visually with translated characters.
364 If KBD-TRANSLATE is set, it is desirable to set also this flag unless
365 this package defines no translations for single character keys.
367 CREATE-DECODE-MAP non-nil means decode map is also created. A decode
368 map is an alist of translations and corresponding original keys.
369 Although this map is not used by Quail itself, it can be used by some
370 other programs. For instance, Vietnamese supporting needs this map to
371 convert Vietnamese text to VIQR format which uses only ASCII
372 characters to represent Vietnamese characters.
374 MAXIMUM-SHORTEST non-nil means break key sequence to get maximum
375 length of the shortest sequence. When we don't have a translation of
376 key \"..ABCD\" but have translations of \"..AB\" and \"CD..\", break
377 the key at \"..AB\" and start translation of \"CD..\". Hangul
378 packages, for instance, use this facility. If this flag is nil, we
379 break the key just at \"..ABC\" and start translation of \"D..\".
381 OVERLAY-PLIST if non-nil is a property list put on an overlay which
382 covers Quail translation region.
384 UPDATE-TRANSLATION-FUNCTION if non-nil is a function to call to update
385 the current translation region according to a new translation data. By
386 default, a translated text or a user's key sequence (if no translation
389 CONVERSION-KEYS specifies additional key bindings used while
390 conversion region is active. It is an alist of single key character
391 vs. corresponding command to be called.
393 If SIMPLE is non-nil, then we do not alter the meanings of
394 commands such as C-f, C-b, C-n, C-p and TAB; they are treated as
396 (let (translation-keymap conversion-keymap)
397 (if deterministic (setq forget-last-selection t))
400 (setq translation-keymap (copy-keymap
401 (if simple quail-simple-translation-keymap
402 quail-translation-keymap)))
403 (while translation-keys
404 (define-key translation-keymap
405 (car (car translation-keys)) (cdr (car translation-keys)))
406 (setq translation-keys (cdr translation-keys))))
407 (setq translation-keymap
408 (if simple quail-simple-translation-keymap
409 quail-translation-keymap)))
410 (when conversion-keys
411 (setq conversion-keymap (copy-keymap quail-conversion-keymap))
412 (while conversion-keys
413 (define-key conversion-keymap
414 (car (car conversion-keys)) (cdr (car conversion-keys)))
415 (setq conversion-keys (cdr conversion-keys))))
417 (list name title (list nil) guidance (or docstring "")
419 forget-last-selection deterministic kbd-translate show-layout
420 (if create-decode-map (list 'decode-map) nil)
421 maximum-shortest overlay-plist update-translation-function
422 conversion-keymap simple))
424 ;; Update input-method-alist.
425 (let ((slot (assoc name input-method-alist))
426 (val (list language 'quail-use-package title docstring)))
427 (if slot (setcdr slot val)
428 (setq input-method-alist (cons (cons name val) input-method-alist)))))
430 (quail-select-package name))
432 ;; Quail minor mode handlers.
434 ;; Setup overlays used in Quail mode.
435 (defun quail-setup-overlays (conversion-mode)
437 (if (overlayp quail-overlay)
438 (move-overlay quail-overlay pos pos)
439 (setq quail-overlay (make-overlay pos pos nil nil t))
440 (if input-method-highlight-flag
441 (overlay-put quail-overlay 'face 'underline))
442 (let ((l (quail-overlay-plist)))
444 (overlay-put quail-overlay (car l) (car (cdr l)))
445 (setq l (cdr (cdr l))))))
447 (if (overlayp quail-conv-overlay)
448 (if (not (overlay-start quail-conv-overlay))
449 (move-overlay quail-conv-overlay pos pos))
450 (setq quail-conv-overlay (make-overlay pos pos nil nil t))
451 (if input-method-highlight-flag
452 (overlay-put quail-conv-overlay 'face 'underline))))))
454 ;; Delete overlays used in Quail mode.
455 (defun quail-delete-overlays ()
456 (if (and (overlayp quail-overlay) (overlay-start quail-overlay))
457 (delete-overlay quail-overlay))
458 (if (and (overlayp quail-conv-overlay) (overlay-start quail-conv-overlay))
459 (delete-overlay quail-conv-overlay)))
461 ;; Kill Quail guidance buffer. Set in kill-buffer-hook.
462 (defun quail-kill-guidance-buf ()
463 (if (buffer-live-p quail-guidance-buf)
464 (kill-buffer quail-guidance-buf)))
466 (defun quail-inactivate ()
467 "Inactivate Quail input method."
471 (defun quail-activate (&optional arg)
472 "Activate Quail input method.
473 With arg, activate Quail input method if and only if arg is positive.
475 While this input method is active, the variable
476 `input-method-function' is bound to the function `quail-input-method'."
478 (< (prefix-numeric-value arg) 0))
479 ;; Let's inactivate Quail input method.
482 (quail-hide-guidance-buf)
483 (quail-delete-overlays)
484 (setq describe-current-input-method-function nil)
485 (run-hooks 'quail-inactivate-hook))
486 (kill-local-variable 'input-method-function))
487 ;; Let's active Quail input method.
488 (if (null quail-current-package)
489 ;; Quail package is not yet selected. Select one now.
491 (if quail-package-alist
492 (setq name (car (car quail-package-alist)))
493 (error "No Quail package loaded"))
494 (quail-select-package name)))
495 (setq inactivate-current-input-method-function 'quail-inactivate)
496 (setq describe-current-input-method-function 'quail-help)
497 (quail-delete-overlays)
498 (quail-show-guidance-buf)
499 ;; If we are in minibuffer, turn off the current input method
501 (if (eq (selected-window) (minibuffer-window))
502 (add-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer))
503 (make-local-hook 'kill-buffer-hook)
504 (add-hook 'kill-buffer-hook 'quail-kill-guidance-buf nil t)
505 (run-hooks 'quail-activate-hook)
506 (make-local-variable 'input-method-function)
507 (setq input-method-function 'quail-input-method)))
509 (defun quail-exit-from-minibuffer ()
510 (inactivate-input-method)
511 (if (<= (minibuffer-depth) 1)
512 (remove-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer)))
514 ;; Keyboard layout translation handlers.
516 ;; Some Quail packages provide localized keyboard simulation which
517 ;; requires a particular keyboard layout. In this case, what we need
518 ;; is locations of keys the user entered, not character codes
519 ;; generated by those keys. However, for the moment, there's no
520 ;; common way to get such information. So, we ask a user to give
521 ;; information of his own keyboard layout, then translate it to the
522 ;; standard layout which we defined so that all Quail packages depend
525 (defconst quail-keyboard-layout-standard
528 1!2@3#4$5%6^7&8*9(0)-_=+`~ \
529 qQwWeErRtTyYuUiIoOpP[{]} \
530 aAsSdDfFgGhHjJkKlL;:'\"\\| \
531 zZxXcCvVbBnNmM,<.>/? \
533 "Standard keyboard layout of printable characters Quail assumes.
534 See the documentation of `quail-keyboard-layout' for this format.
535 This layout is almost the same as that of VT100,
536 but the location of key \\ (backslash) is just right of key ' (single-quote),
537 not right of RETURN key.")
539 (defvar quail-keyboard-layout quail-keyboard-layout-standard
540 "A string which represents physical key layout of a particular keyboard.
541 We assume there are six rows and each row has 15 keys (columns),
542 the first row is above the `1' - `0' row,
543 the first column of the second row is left of key `1',
544 the first column of the third row is left of key `q',
545 the first column of the fourth row is left of key `a',
546 the first column of the fifth row is left of key `z',
547 the sixth row is below the `z' - `/' row.
548 Nth (N is even) and (N+1)th characters in the string are non-shifted
549 and shifted characters respectively at the same location.
550 The location of Nth character is row (N / 30) and column ((N mod 30) / 2).
551 The command `quail-set-keyboard-layout' usually sets this variable.")
553 (defconst quail-keyboard-layout-len 180)
555 ;; Here we provide several examples of famous keyboard layouts.
557 (defvar quail-keyboard-layout-alist
561 1!2@3#4$5%6^7&8*9(0)-_=+\\|`~\
562 qQwWeErRtTyYuUiIoOpP[{]} \
563 aAsSdDfFgGhHjJkKlL;:'\" \
564 zZxXcCvVbBnNmM,<.>/? \
566 '("atari-german" . "\
568 1!2\"3\2474$5%6&7/8(9)0=\337?'`#^ \
569 qQwWeErRtTzZuUiIoOpP\374\334+* \
570 aAsSdDfFgGhHjJkKlL\366\326\344\304~| \
571 <>yYxXcCvVbBnNmM,;.:-_ \
573 (cons "standard" quail-keyboard-layout-standard))
574 "Alist of keyboard names and corresponding layout strings.
575 See the documentation of `quail-keyboard-layout' for the format of
579 (defun quail-set-keyboard-layout (kbd-type)
580 "Set the current keyboard layout to the same as keyboard KBD-TYPE.
582 Since some Quail packages depends on a physical layout of keys (not
583 characters generated by them), those are created by assuming the
584 standard layout defined in `quail-keyboard-layout-standard'. This
585 function tells Quail system the layout of your keyboard so that what
586 you type is correctly handled."
588 (let* ((completing-ignore-case t)
589 (type (completing-read "Keyboard type: "
590 quail-keyboard-layout-alist)))
592 (let ((layout (assoc kbd-type quail-keyboard-layout-alist)))
594 ;; Here, we had better ask a user to define his own keyboard
595 ;; layout interactively.
596 (error "Unknown keyboard type `%s'" kbd-type))
597 (setq quail-keyboard-layout (cdr layout))))
599 (defun quail-keyboard-translate (ch)
600 "Translate CHAR according to `quail-keyboard-layout' and return the result."
601 (if (eq quail-keyboard-layout quail-keyboard-layout-standard)
602 ;; All Quail packages are designed based on
603 ;; `quail-keyboard-layout-standard'.
606 (while (and (< i quail-keyboard-layout-len)
607 (/= ch (aref quail-keyboard-layout i)))
609 (if (= i quail-keyboard-layout-len)
610 ;; CH is not in quail-keyboard-layout, which means that a
611 ;; user typed a key which generated a character code to be
612 ;; handled out of Quail. Just return CH and make
613 ;; quail-execute-non-quail-command handle it correctly.
615 (let ((char (aref quail-keyboard-layout-standard i)))
617 ;; A user typed a key at the location not converted by
618 ;; quail-keyboard-layout-standard. Just return CH as
625 (defsubst quail-map-p (object)
626 "Return t if OBJECT is a Quail map.
628 A Quail map holds information how a particular key should be translated.
629 Its format is (TRANSLATION . ALIST).
630 TRANSLATION is either a character, or a cons (INDEX . VECTOR).
631 In the latter case, each element of VECTOR is a candidate for the translation,
632 and INDEX points the currently selected translation.
634 ALIST is normally a list of elements that look like (CHAR . DEFN),
635 where DEFN is another Quail map for a longer key (CHAR added to the
636 current key). It may also be a symbol of a function which returns an
637 alist of the above format.
639 Just after a Quail package is read, TRANSLATION may be a string or a
640 vector. Then each element of the string or vector is a candidate for
641 the translation. These objects are transformed to cons cells in the
642 format \(INDEX . VECTOR), as described above."
644 (let ((translation (car object)))
645 (or (integerp translation) (null translation)
646 (vectorp translation) (stringp translation)
647 (symbolp translation)
648 (and (consp translation) (not (vectorp (cdr translation))))))
649 (let ((alist (cdr object)))
650 (or (and (listp alist) (consp (car alist)))
654 (defmacro quail-define-rules (&rest rules)
655 "Define translation rules of the current Quail package.
656 Each argument is a list of KEY and TRANSLATION.
657 KEY is a string meaning a sequence of keystrokes to be translated.
658 TRANSLATION is a character, a string, a vector, a Quail map, or a function.
659 It it is a character, it is the sole translation of KEY.
660 If it is a string, each character is a candidate for the translation.
661 If it is a vector, each element (string or character) is a candidate
663 In these cases, a key specific Quail map is generated and assigned to KEY.
665 If TRANSLATION is a Quail map or a function symbol which returns a Quail map,
666 it is used to handle KEY."
671 (quail-defrule-internal (car (car l)) (car (cdr (car l))) map t)
676 (defun quail-install-map (map)
677 "Install the Quail map MAP in the current Quail package.
678 The installed map can be referred by the function `quail-map'."
679 (if (null quail-current-package)
680 (error "No current Quail package"))
681 (if (null (quail-map-p map))
682 (error "Invalid Quail map `%s'" map))
683 (setcar (cdr (cdr quail-current-package)) map))
686 (defun quail-defrule (key translation &optional name append)
687 "Add one translation rule, KEY to TRANSLATION, in the current Quail package.
688 KEY is a string meaning a sequence of keystrokes to be translated.
689 TRANSLATION is a character, a string, a vector, a Quail map,
690 a function, or a cons.
691 It it is a character, it is the sole translation of KEY.
692 If it is a string, each character is a candidate for the translation.
693 If it is a vector, each element (string or character) is a candidate
695 If it is a cons, the car is one of the above and the cdr is a function
696 to call when translating KEY (the return value is assigned to the
697 variable `quail-current-data'). If the cdr part is not a function,
698 the value itself is assigned to `quail-current-data'.
699 In these cases, a key specific Quail map is generated and assigned to KEY.
701 If TRANSLATION is a Quail map or a function symbol which returns a Quail map,
702 it is used to handle KEY.
704 Optional 3rd argument NAME, if specified, says which Quail package
705 to define this translation rule in. The default is to define it in the
706 current Quail package.
708 Optional 4th argument APPEND, if non-nil, appends TRANSLATION
709 to the current translations for KEY instead of replacing them."
711 (let ((package (quail-package name)))
713 (error "No Quail package `%s'" name))
714 (setq quail-current-package package)))
715 (quail-defrule-internal key translation (quail-map) append))
718 (defun quail-defrule-internal (key trans map &optional append)
719 "Define KEY as TRANS in a Quail map MAP."
720 (if (null (stringp key))
721 "Invalid Quail key `%s'" key)
722 (if (not (or (numberp trans) (stringp trans) (vectorp trans)
725 (quail-map-p trans)))
726 (error "Invalid Quail translation `%s'" trans))
727 (if (null (quail-map-p map))
728 (error "Invalid Quail map `%s'" map))
729 (let ((len (length key))
732 ;; Make a map for registering TRANS if necessary.
734 (if (null (consp map))
735 ;; We come here, for example, when we try to define a rule
736 ;; for "ABC" but a rule for "AB" is already defined as a
738 (error "Quail key %s is too long" key))
739 (setq ch (aref key idx)
740 entry (assq ch (cdr map)))
743 (setq entry (cons ch (list nil)))
744 (setcdr map (cons entry (cdr map)))))
745 (setq map (cdr entry))
749 ;; We come here, for example, when we try to define a rule
750 ;; for "AB" as a symbol but a rule for "ABC" is already
752 (error "Quail key %s is too short" key)
753 (setcdr entry trans))
754 (if (quail-map-p trans)
755 (if (not (listp (cdr map)))
756 ;; We come here, for example, when we try to define a rule
757 ;; for "AB" as a symbol but a rule for "ABC" is already
759 (error "Quail key %s is too short" key)
760 (if (not (listp (cdr trans)))
762 ;; We come here, for example, when we try to
763 ;; define a rule for "AB" as a symbol but a rule
764 ;; for "ABC" is already defined.
765 (error "Quail key %s is too short" key)
766 (setcdr entry trans))
767 (setcdr entry (append trans (cdr map)))))
768 (if (and (car map) append)
769 (let ((prev (quail-get-translation (car map) key len)))
771 (setq prev (vector prev))
772 (setq prev (cdr prev)))
774 (setq trans (vector trans))
776 (setq trans (string-to-vector trans))))
778 (cons (list 0 0 0 0 nil)
779 (vconcat prev trans)))))
780 (setcar map trans)))))
782 (defun quail-get-translation (def key len)
783 "Return the translation specified as DEF for KEY of length LEN.
784 The translation is either a character or a cons of the form (INDEX . VECTOR),
785 where VECTOR is a vector of candidates (character or string) for
786 the translation, and INDEX points into VECTOR to specify the currently
787 selected translation."
788 (if (and def (symbolp def))
789 ;; DEF is a symbol of a function which returns valid translation.
790 (setq def (funcall def key len)))
791 (if (and (consp def) (not (vectorp (cdr def))))
792 (setq def (car def)))
795 ((or (integerp def) (consp def))
803 ;; Each character in DEF is a candidate of translation. Reform
804 ;; it as (INDICES . VECTOR).
805 (setq def (string-to-vector def))
806 ;; But if the length is 1, we don't need vector but a single
807 ;; candidate as the translation.
808 (if (= (length def) 1)
810 (cons (list 0 0 0 0 nil) def)))
813 ;; Each element (string or character) in DEF is a candidate of
814 ;; translation. Reform it as (INDICES . VECTOR).
815 (cons (list 0 0 0 0 nil) def))
818 (error "Invalid object in Quail map: %s" def))))
820 (defun quail-lookup-key (key &optional len)
821 "Lookup KEY of length LEN in the current Quail map and return the definition.
822 The returned value is a Quail map specific to KEY."
824 (setq len (length key)))
827 (kbd-translate (quail-kbd-translate))
828 slot ch translation def)
829 (while (and map (< idx len))
830 (setq ch (if kbd-translate (quail-keyboard-translate (aref key idx))
833 (if (and (cdr map) (symbolp (cdr map)))
834 (setcdr map (funcall (cdr map) key idx)))
835 (setq slot (assq ch (cdr map)))
836 (if (and (cdr slot) (symbolp (cdr slot)))
837 (setcdr slot (funcall (cdr slot) key idx)))
838 (setq map (cdr slot)))
840 (setq quail-current-translations nil)
841 (if (and map (setq translation (quail-get-translation def key len)))
843 (if (and (consp def) (not (vectorp (cdr def))))
845 (if (not (equal (car def) translation))
846 ;; We must reflect TRANSLATION to car part of DEF.
847 (setcar def translation))
848 (setq quail-current-data
849 (if (functionp (cdr def))
852 (if (not (equal def translation))
853 ;; We must reflect TRANSLATION to car part of MAP.
854 (setcar map translation)))
855 (if (and (consp translation) (vectorp (cdr translation)))
857 (setq quail-current-translations translation)
858 (if (quail-forget-last-selection)
859 (setcar (car quail-current-translations) 0))))
860 ;; We may have to reform cdr part of MAP.
861 (if (and (cdr map) (symbolp (cdr map)))
863 (setcdr map (funcall (cdr map) key len))))
867 (put 'quail-error 'error-conditions '(quail-error error))
868 (defun quail-error (&rest args)
869 (signal 'quail-error (apply 'format args)))
871 (defvar quail-translating nil)
872 (defvar quail-converting nil)
873 (defvar quail-conversion-str nil)
875 (defun quail-input-method (key)
876 (if (or buffer-read-only
877 overriding-terminal-local-map
878 overriding-local-map)
880 (quail-setup-overlays (quail-conversion-keymap))
881 (let ((modified-p (buffer-modified-p))
882 (buffer-undo-list t))
883 (or (and quail-guidance-win
884 (window-live-p quail-guidance-win)
885 (eq (window-buffer quail-guidance-win) quail-guidance-buf)
886 (not input-method-use-echo-area))
887 (quail-show-guidance-buf))
889 (if (quail-conversion-keymap)
890 (quail-start-conversion key)
891 (quail-start-translation key))
892 (quail-delete-overlays)
893 (if (buffer-live-p quail-guidance-buf)
895 (set-buffer quail-guidance-buf)
897 (if input-method-use-echo-area
898 (quail-hide-guidance-buf))
899 (set-buffer-modified-p modified-p)
900 ;; Run this hook only when the current input method doesn't require
901 ;; conversion. When conversion is required, the conversion function
902 ;; should run this hook at a proper timing.
903 (unless (quail-conversion-keymap)
904 (run-hooks 'input-method-after-insert-chunk-hook))))))
906 (defun quail-overlay-region-events (overlay)
907 (let ((start (overlay-start overlay))
908 (end (overlay-end overlay)))
911 (string-to-list (buffer-substring start end))
912 (delete-region start end)))))
914 (defsubst quail-delete-region ()
915 "Delete the text in the current translation region of Quail."
916 (if (overlay-start quail-overlay)
917 (delete-region (overlay-start quail-overlay)
918 (overlay-end quail-overlay))))
920 (defun quail-start-translation (key)
921 "Start translation of the typed character KEY by the current Quail package."
922 ;; Check the possibility of translating KEY.
923 ;; If KEY is nil, we can anyway start translation.
924 (if (or (and (integerp key)
925 (assq (if (quail-kbd-translate)
926 (quail-keyboard-translate key) key)
929 ;; OK, we can start translation.
930 (let* ((echo-keystrokes 0)
932 (overriding-terminal-local-map (quail-translation-keymap))
933 (generated-events nil)
934 (input-method-function nil))
935 (setq quail-current-key ""
939 (setq unread-command-events (cons key unread-command-events)))
940 (while quail-translating
941 (let* ((keyseq (read-key-sequence
942 (and input-method-use-echo-area
943 (concat input-method-previous-message
946 (cmd (lookup-key (quail-translation-keymap) keyseq)))
948 (and (commandp cmd) (not (eq cmd 'quail-other-command)))
949 (eq cmd 'quail-self-insert-command))
952 (setq last-command-event (aref keyseq (1- (length keyseq)))
953 last-command this-command
956 (call-interactively cmd)
957 (quail-error (message "%s" (cdr err)) (beep))))
958 ;; KEYSEQ is not defined in the translation keymap.
959 ;; Let's return the event(s) to the caller.
960 (setq generated-events
961 (string-to-list (this-single-command-raw-keys)))
962 (setq quail-translating nil))))
963 (quail-delete-region)
964 (if (and quail-current-str (> (length quail-current-str) 0))
965 (setq generated-events
966 (append (string-to-list
967 (if enable-multibyte-characters
969 (string-make-unibyte quail-current-str)))
971 (if (and input-method-exit-on-first-char generated-events)
972 (list (car generated-events))
975 ;; Since KEY doesn't start any translation, just return it.
978 (defun quail-start-conversion (key)
979 "Start conversion of the typed character KEY by the current Quail package."
980 ;; Check the possibility of translating KEY.
981 ;; If KEY is nil, we can anyway start translation.
982 (if (or (and (integerp key)
983 (assq (if (quail-kbd-translate)
984 (quail-keyboard-translate key) key)
987 ;; Ok, we can start translation and conversion.
988 (let* ((echo-keystrokes 0)
990 (overriding-terminal-local-map (quail-conversion-keymap))
991 (generated-events nil)
992 (input-method-function nil))
993 (setq quail-current-key ""
997 quail-conversion-str "")
999 (setq unread-command-events (cons key unread-command-events)))
1000 (while quail-converting
1001 (or quail-translating
1003 (setq quail-current-key ""
1004 quail-current-str ""
1005 quail-translating t)
1006 (quail-setup-overlays nil)))
1007 (let* ((keyseq (read-key-sequence
1008 (and input-method-use-echo-area
1009 (concat input-method-previous-message
1010 quail-conversion-str
1013 (cmd (lookup-key (quail-conversion-keymap) keyseq)))
1014 (if (if key (commandp cmd) (eq cmd 'quail-self-insert-command))
1017 (setq last-command-event (aref keyseq (1- (length keyseq)))
1018 last-command this-command
1021 (call-interactively cmd)
1022 (quail-error (message "%s" (cdr err)) (beep)))
1023 (or quail-translating
1025 (if quail-current-str
1026 (setq quail-conversion-str
1027 (concat quail-conversion-str
1028 (if (stringp quail-current-str)
1030 (char-to-string quail-current-str)))))
1031 (if input-method-exit-on-first-char
1032 (setq quail-converting nil)))))
1033 ;; KEYSEQ is not defined in the conversion keymap.
1034 ;; Let's return the event(s) to the caller.
1035 (setq generated-events
1036 (string-to-list (this-single-command-raw-keys)))
1037 (setq quail-converting nil))))
1038 (if (overlay-start quail-conv-overlay)
1039 (delete-region (overlay-start quail-conv-overlay)
1040 (overlay-end quail-conv-overlay)))
1041 (if (> (length quail-conversion-str) 0)
1042 (setq generated-events
1043 (append (string-to-list
1044 (if enable-multibyte-characters
1045 quail-conversion-str
1046 (string-make-unibyte quail-conversion-str)))
1048 (if (and input-method-exit-on-first-char generated-events)
1049 (list (car generated-events))
1052 ;; Since KEY doesn't start any translation, just return it.
1055 (defun quail-terminate-translation ()
1056 "Terminate the translation of the current key."
1057 (setq quail-translating nil)
1058 (if (buffer-live-p quail-guidance-buf)
1060 (set-buffer quail-guidance-buf)
1063 (defun quail-select-current ()
1064 "Select the current text shown in Quail translation region."
1066 (quail-terminate-translation))
1068 ;; Update the current translation status according to CONTROL-FLAG.
1069 ;; If CONTROL-FLAG is integer value, it is the number of keys in the
1070 ;; head quail-current-key which can be translated. The remaining keys
1071 ;; are put back to unread-command-events to be handled again. If
1072 ;; CONTROL-FLAG is t, terminate the translation for the whole keys in
1073 ;; quail-current-key. If CONTROL-FLAG is nil, proceed the translation
1076 (defun quail-update-translation (control-flag)
1077 (let ((func (quail-update-translation-function)))
1079 (setq control-flag (funcall func control-flag))
1080 (if (numberp control-flag)
1081 (let ((len (length quail-current-key)))
1083 (setq control-flag t
1084 quail-current-str quail-current-key)
1085 (if input-method-exit-on-first-char
1086 (setq len control-flag)
1087 (while (> len control-flag)
1089 (setq unread-command-events
1090 (cons (aref quail-current-key len)
1091 unread-command-events))))
1092 (if quail-current-str
1093 (if input-method-exit-on-first-char
1094 (setq control-flag t))
1095 (setq quail-current-str
1096 (substring quail-current-key 0 len)))))
1097 (if quail-current-str
1098 (if (and input-method-exit-on-first-char
1100 (setq control-flag t))
1101 (setq quail-current-str quail-current-key)))))
1102 (or input-method-use-echo-area
1104 (quail-delete-region)
1105 (insert quail-current-str)))
1106 (let (quail-current-str)
1107 (quail-update-guidance))
1108 (or (stringp quail-current-str)
1109 (setq quail-current-str (char-to-string quail-current-str)))
1111 (quail-terminate-translation)))
1113 (defun quail-self-insert-command ()
1114 "Add the typed character to the key for translation."
1116 (setq quail-current-key
1117 (concat quail-current-key (char-to-string last-command-event)))
1118 (or (catch 'quail-tag
1119 (quail-update-translation (quail-translate-key))
1121 ;; If someone throws for `quail-tag' by value nil, we exit from
1122 ;; translation mode.
1123 (setq quail-translating nil)))
1125 ;; Return the actual definition part of Quail map MAP.
1126 (defun quail-map-definition (map)
1127 (let ((def (car map)))
1128 (if (and (consp def) (not (vectorp (cdr def))))
1129 (setq def (car def)))
1132 ;; Return a string to be shown as the current translation of key
1133 ;; sequence of length LEN. DEF is a definition part of Quail map for
1135 (defun quail-get-current-str (len def)
1136 (or (and (consp def) (aref (cdr def) (car (car def))))
1139 (let ((str (quail-get-current-str
1141 (quail-map-definition (quail-lookup-key
1142 quail-current-key (1- len))))))
1144 (concat (if (stringp str) str (char-to-string str))
1145 (substring quail-current-key (1- len) len)))))))
1147 (defvar quail-guidance-translations-starting-column 20)
1149 ;; Update `quail-current-translations' to make RELATIVE-INDEX the
1150 ;; current translation.
1151 (defun quail-update-current-translations (&optional relative-index)
1152 (let* ((indices (car quail-current-translations))
1154 (start (nth 1 indices))
1155 (end (nth 2 indices)))
1156 ;; Validate the index number of current translation.
1158 (setcar indices (setq cur 0))
1159 (if (>= cur (length (cdr quail-current-translations)))
1161 (setq cur (1- (length (cdr quail-current-translations)))))))
1163 (if (or (null end) ; We have not yet calculated END.
1164 (< cur start) ; We moved to the previous block.
1165 (>= cur end)) ; We moved to the next block.
1166 (let ((len (length (cdr quail-current-translations)))
1167 (maxcol (- (window-width quail-guidance-win)
1168 quail-guidance-translations-starting-column))
1169 (block (nth 3 indices))
1170 col idx width trans num-items blocks)
1172 ;; We must calculate from the head.
1173 (setq start 0 block 0)
1174 (if end ; i.e. (>= cur end)
1176 (setq idx start col 0 end start num-items 0)
1177 ;; Loop until we hit the tail, or reach the block of CUR.
1178 (while (and (< idx len) (>= cur end))
1180 (setq start idx col 0 block (1+ block)))
1181 (setq trans (aref (cdr quail-current-translations) idx))
1182 (setq width (if (integerp trans) (char-width trans)
1183 (string-width trans)))
1184 (setq col (+ col width 3) num-items (1+ num-items))
1185 (if (and (> num-items 0)
1186 (or (>= col maxcol) (> num-items 10)))
1187 (setq end idx num-items 0)
1188 (setq idx (1+ idx))))
1189 (setcar (nthcdr 3 indices) block)
1192 ;; We hit the tail before reaching MAXCOL.
1194 (setcar (nthcdr 4 indices) block)))
1195 (setcar (cdr indices) start)
1196 (setcar (nthcdr 2 indices) end)))
1198 (if (>= (+ start relative-index) end)
1199 (setcar indices end)
1200 (setcar indices (+ start relative-index))))
1201 (setq quail-current-str
1202 (aref (cdr quail-current-translations) (car indices)))
1203 (or (stringp quail-current-str)
1204 (setq quail-current-str (char-to-string quail-current-str)))))
1206 (defun quail-translate-key ()
1207 "Translate the current key sequence according to the current Quail map.
1208 Return t if we can terminate the translation.
1209 Return nil if the current key sequence may be followed by more keys.
1210 Return number if we can't find any translation for the current key
1211 sequence. The number is the count of valid keys in the current
1212 sequence counting from the head."
1213 (let* ((len (length quail-current-key))
1214 (map (quail-lookup-key quail-current-key len))
1217 (let ((def (quail-map-definition map)))
1218 (setq quail-current-str (quail-get-current-str len def))
1219 ;; Return t only if we can terminate the current translation.
1221 ;; No alternative translations.
1222 (or (null (consp def)) (= (length (cdr def)) 1))
1223 ;; No translation for the longer key.
1225 ;; No shorter breaking point.
1226 (or (null (quail-maximum-shortest))
1228 (null (quail-lookup-key quail-current-key (1- len)))
1229 (null (quail-lookup-key
1230 (substring quail-current-key -2 -1) 1)))))
1232 ;; There's no translation for the current key sequence. Before
1233 ;; giving up, we must check two possibilities.
1235 (quail-maximum-shortest)
1237 (setq def (quail-map-definition
1238 (quail-lookup-key quail-current-key (- len 2))))
1239 (quail-lookup-key (substring quail-current-key -2) 2))
1240 ;; Now the sequence is "...ABCD", which can be split into
1241 ;; "...AB" and "CD..." to get valid translation.
1242 ;; At first, get translation of "...AB".
1243 (setq quail-current-str (quail-get-current-str (- len 2) def))
1244 ;; Then, return the length of "...AB".
1248 (quail-lookup-key (substring quail-current-key 0 -1))
1249 quail-current-translations
1250 (not (quail-deterministic))
1251 (setq ch (aref quail-current-key (1- len)))
1252 (>= ch ?0) (<= ch ?9))
1253 ;; A numeric key is entered to select a desirable translation.
1254 (setq quail-current-key (substring quail-current-key 0 -1))
1255 ;; We treat key 1,2..,9,0 as specifying 0,1,..8,9.
1256 (setq ch (if (= ch ?0) 9 (- ch ?1)))
1257 (quail-update-current-translations ch)
1258 ;; And, we can terminate the current translation.
1262 ;; No way to handle the last character in this context.
1265 (defun quail-next-translation ()
1266 "Select next translation in the current batch of candidates."
1268 (if quail-current-translations
1269 (let ((indices (car quail-current-translations)))
1270 (if (= (1+ (car indices)) (length (cdr quail-current-translations)))
1271 ;; We are already at the tail.
1273 (setcar indices (1+ (car indices)))
1274 (quail-update-current-translations)
1275 (quail-update-translation nil)))
1276 (setq unread-command-events
1277 (cons last-command-event unread-command-events))
1278 (quail-terminate-translation)))
1280 (defun quail-prev-translation ()
1281 "Select previous translation in the current batch of candidates."
1283 (if quail-current-translations
1284 (let ((indices (car quail-current-translations)))
1285 (if (= (car indices) 0)
1286 ;; We are already at the head.
1288 (setcar indices (1- (car indices)))
1289 (quail-update-current-translations)
1290 (quail-update-translation nil)))
1291 (setq unread-command-events
1292 (cons last-command-event unread-command-events))
1293 (quail-terminate-translation)))
1295 (defun quail-next-translation-block ()
1296 "Select from the next block of translations."
1298 (if quail-current-translations
1299 (let* ((indices (car quail-current-translations))
1300 (offset (- (car indices) (nth 1 indices))))
1301 (if (>= (nth 2 indices) (length (cdr quail-current-translations)))
1302 ;; We are already at the last block.
1304 (setcar indices (+ (nth 2 indices) offset))
1305 (quail-update-current-translations)
1306 (quail-update-translation nil)))
1307 (setq unread-command-events
1308 (cons last-command-event unread-command-events))
1309 (quail-terminate-translation)))
1311 (defun quail-prev-translation-block ()
1312 "Select the previous batch of 10 translation candidates."
1314 (if quail-current-translations
1315 (let* ((indices (car quail-current-translations))
1316 (offset (- (car indices) (nth 1 indices))))
1317 (if (= (nth 1 indices) 0)
1318 ;; We are already at the first block.
1320 (setcar indices (1- (nth 1 indices)))
1321 (quail-update-current-translations)
1322 (if (< (+ (nth 1 indices) offset) (nth 2 indices))
1324 (setcar indices (+ (nth 1 indices) offset))
1325 (quail-update-current-translations)))
1326 (quail-update-translation nil)))
1327 (setq unread-command-events
1328 (cons last-command-event unread-command-events))
1329 (quail-terminate-translation)))
1331 (defun quail-abort-translation ()
1332 "Abort translation and delete the current Quail key sequence."
1334 (quail-delete-region)
1335 (setq quail-current-str nil)
1336 (quail-terminate-translation))
1338 (defun quail-delete-last-char ()
1339 "Delete the last input character from the current Quail key sequence."
1341 (if (= (length quail-current-key) 1)
1342 (quail-abort-translation)
1343 (setq quail-current-key (substring quail-current-key 0 -1))
1344 (quail-update-translation (quail-translate-key))))
1346 ;; For conversion mode.
1348 (defsubst quail-point-in-conversion-region ()
1349 "Return non-nil value if the point is in conversion region of Quail mode."
1351 (and (setq start (overlay-start quail-conv-overlay))
1352 (>= (setq pos (point)) start)
1353 (<= pos (overlay-end quail-conv-overlay)))))
1355 (defun quail-conversion-backward-char ()
1357 (if (<= (point) (overlay-start quail-conv-overlay))
1358 (quail-error "Beginning of conversion region"))
1359 (setq quail-translating nil)
1362 (defun quail-conversion-forward-char ()
1364 (if (>= (point) (overlay-end quail-conv-overlay))
1365 (quail-error "End of conversion region"))
1366 (setq quail-translating nil)
1369 (defun quail-conversion-beginning-of-region ()
1371 (setq quail-translating nil)
1372 (goto-char (overlay-start quail-conv-overlay)))
1374 (defun quail-conversion-end-of-region ()
1376 (setq quail-translating nil)
1377 (goto-char (overlay-end quail-conv-overlay)))
1379 (defun quail-conversion-delete-char ()
1381 (setq quail-translating nil)
1382 (if (>= (point) (overlay-end quail-conv-overlay))
1383 (quail-error "End of conversion region"))
1385 (let ((start (overlay-start quail-conv-overlay))
1386 (end (overlay-end quail-conv-overlay)))
1387 (setq quail-conversion-str (buffer-substring start end))
1389 (setq quail-converting nil))))
1391 (defun quail-conversion-delete-tail ()
1393 (if (>= (point) (overlay-end quail-conv-overlay))
1394 (quail-error "End of conversion region"))
1395 (delete-region (point) (overlay-end quail-conv-overlay))
1396 (let ((start (overlay-start quail-conv-overlay))
1397 (end (overlay-end quail-conv-overlay)))
1398 (setq quail-conversion-str (buffer-substring start end))
1400 (setq quail-converting nil))))
1402 (defun quail-conversion-backward-delete-char ()
1404 (if (> (length quail-current-key) 0)
1405 (quail-delete-last-char)
1406 (if (<= (point) (overlay-start quail-conv-overlay))
1407 (quail-error "Beginning of conversion region"))
1409 (let ((start (overlay-start quail-conv-overlay))
1410 (end (overlay-end quail-conv-overlay)))
1411 (setq quail-conversion-str (buffer-substring start end))
1413 (setq quail-converting nil)))))
1415 (defun quail-do-conversion (func &rest args)
1416 "Call FUNC to convert text in the current conversion region of Quail.
1417 Remaining args are for FUNC."
1418 (delete-overlay quail-overlay)
1421 (defun quail-no-conversion ()
1422 "Do no conversion of the current conversion region of Quail."
1424 (setq quail-converting nil))
1426 ;; Guidance, Completion, and Help buffer handlers.
1428 ;; Make a new one-line frame for Quail guidance buffer.
1429 (defun quail-make-guidance-frame (buf)
1430 (let* ((fparam (frame-parameters))
1431 (top (cdr (assq 'top fparam)))
1432 (border (cdr (assq 'border-width fparam)))
1433 (internal-border (cdr (assq 'internal-border-width fparam)))
1435 (frame-char-height) (* internal-border 2) (* border 2))))
1437 (setq newtop (+ top (frame-pixel-height))))
1438 (let* ((frame (make-frame (append '((user-position . t) (height . 1)
1439 (minibuffer) (menu-bar-lines . 0))
1440 (cons (cons 'top newtop) fparam))))
1441 (win (frame-first-window frame)))
1442 (set-window-buffer win buf)
1443 ;;(set-window-dedicated-p win t)
1446 ;; Setup Quail completion buffer.
1447 (defun quail-setup-completion-buf ()
1448 (unless (buffer-live-p quail-completion-buf)
1449 (setq quail-completion-buf (get-buffer-create "*Quail Completions*"))
1451 (set-buffer quail-completion-buf)
1452 (setq quail-overlay (make-overlay 1 1))
1453 (overlay-put quail-overlay 'face 'highlight))))
1455 ;; Return t iff the current Quail package requires showing guidance
1457 (defun quail-require-guidance-buf ()
1458 (and input-method-verbose-flag
1459 (if (eq input-method-verbose-flag 'default)
1460 (not (and (eq (selected-window) (minibuffer-window))
1462 (if (eq input-method-verbose-flag 'complex-only)
1463 (not (quail-simple))
1466 (defun quail-show-guidance-buf ()
1467 "Display a guidance buffer for Quail input method in some window.
1468 Create the buffer if it does not exist yet.
1469 The buffer is normally displayed at the echo area,
1470 but if the current buffer is a minibuffer, it is shown in
1471 the bottom-most ordinary window of the same frame,
1472 or in a newly created frame (if the selected frame has no other windows)."
1473 (when (quail-require-guidance-buf)
1474 ;; At first, setup a guidance buffer.
1475 (or (buffer-live-p quail-guidance-buf)
1476 (setq quail-guidance-buf (generate-new-buffer " *Quail-guidance*")))
1477 (let ((title (quail-title)))
1479 (set-buffer quail-guidance-buf)
1480 ;; To show the title of Quail package.
1481 (setq current-input-method t
1482 current-input-method-title title)
1484 (or (overlayp quail-overlay)
1486 (setq quail-overlay (make-overlay 1 1))
1487 (overlay-put quail-overlay 'face 'highlight)))
1488 (delete-overlay quail-overlay)
1489 (set-buffer-modified-p nil)))
1490 (bury-buffer quail-guidance-buf)
1492 ;; Assign the buffer " *Minibuf-N*" to all windows which are now
1493 ;; displaying quail-guidance-buf.
1494 (let ((win-list (get-buffer-window-list quail-guidance-buf t t)))
1496 (set-window-buffer (car win-list)
1497 (format " *Minibuf-%d*" (minibuffer-depth)))
1498 (setq win-list (cdr win-list))))
1500 ;; Then, display it in an appropriate window.
1501 (let ((win (minibuffer-window)))
1502 (if (or (eq (selected-window) win)
1503 input-method-use-echo-area)
1504 ;; Since we are in minibuffer, we can't use it for guidance.
1505 (if (eq win (frame-root-window))
1506 ;; Create a frame. It is sure that we are using some
1508 (quail-make-guidance-frame quail-guidance-buf)
1509 ;; Find the bottom window and split it if necessary.
1511 (setq win (window-at 0 (- (frame-height) 2)))
1512 (setq height (window-height win))
1513 ;; If WIN is tall enough, split it vertically and use
1516 (let ((window-min-height 2))
1517 ;; Here, `split-window' returns a lower window
1518 ;; which is what we wanted.
1519 (setq win (split-window win (- height 2)))))
1520 (set-window-buffer win quail-guidance-buf)
1521 ;;(set-window-dedicated-p win t)
1523 (set-window-buffer win quail-guidance-buf)
1524 (set-minibuffer-window win))
1525 (setq quail-guidance-win win)))
1527 ;; And, create a buffer for completion.
1528 (quail-setup-completion-buf)
1529 (bury-buffer quail-completion-buf))
1531 (defun quail-hide-guidance-buf ()
1532 "Hide the Quail guidance buffer."
1533 (if (buffer-live-p quail-guidance-buf)
1534 (let ((win-list (get-buffer-window-list quail-guidance-buf t t))
1537 (setq win (car win-list) win-list (cdr win-list))
1538 (if (window-minibuffer-p win)
1539 ;; We are using echo area for the guidance buffer.
1540 ;; Vacate it to the deepest minibuffer.
1541 (set-window-buffer win
1542 (format " *Minibuf-%d*" (minibuffer-depth)))
1543 (if (eq win (frame-root-window (window-frame win)))
1545 ;; We are using a separate frame for guidance buffer.
1546 ;;(set-window-dedicated-p win nil)
1547 (delete-frame (window-frame win)))
1548 ;;(set-window-dedicated-p win nil)
1549 (delete-window win))))
1550 (setq quail-guidance-win nil))))
1552 (defun quail-update-guidance ()
1553 "Update the Quail guidance buffer and completion buffer (if displayed now)."
1554 ;; Update guidance buffer.
1555 (if (quail-require-guidance-buf)
1556 (let ((guidance (quail-guidance)))
1557 (or (and (eq (selected-frame) (window-frame (minibuffer-window)))
1558 (eq (selected-frame) (window-frame quail-guidance-win)))
1559 (quail-show-guidance-buf))
1560 (cond ((or (eq guidance t)
1562 ;; Show the current possible translations.
1563 (quail-show-translations))
1565 ;; Show the current input keys.
1566 (let ((key quail-current-key))
1568 (set-buffer quail-guidance-buf)
1572 ;; Update completion buffer if displayed now. We highlight the
1573 ;; selected candidate string in *Completion* buffer if any.
1574 (let ((win (get-buffer-window quail-completion-buf))
1578 (setq str (if (stringp quail-current-str)
1580 (if (numberp quail-current-str)
1581 (char-to-string quail-current-str)))
1582 key quail-current-key)
1583 (set-buffer quail-completion-buf)
1584 (goto-char (point-min))
1585 (if (null (search-forward (concat " " key ":") nil t))
1586 (delete-overlay quail-overlay)
1588 (if (and str (search-forward (concat "." str) nil t))
1589 (move-overlay quail-overlay (1+ (match-beginning 0)) (point))
1590 (move-overlay quail-overlay (match-beginning 0) (point)))
1591 ;; Now POS points end of KEY and (point) points end of STR.
1592 (if (pos-visible-in-window-p (point) win)
1593 ;; STR is already visible.
1595 ;; We want to make both KEY and STR visible, but if the
1596 ;; window is too short, make at least STR visible.
1597 (setq pos (progn (point) (goto-char pos)))
1599 (set-window-start win (point))
1600 (if (not (pos-visible-in-window-p pos win))
1601 (set-window-start win pos))
1604 (defun quail-show-translations ()
1605 "Show the current possible translations."
1606 (let* ((key quail-current-key)
1607 (map (quail-lookup-key quail-current-key))
1608 (current-translations quail-current-translations))
1609 (if quail-current-translations
1610 (quail-update-current-translations))
1612 (set-buffer quail-guidance-buf)
1615 ;; Show the current key.
1616 (let ((guidance (quail-guidance)))
1617 (if (listp guidance)
1618 ;; We must show the specified PROMPTKEY instead of the
1619 ;; actual typed keys.
1624 (setq prompt-key (cdr (assoc (aref key i) guidance)))
1625 (insert (or prompt-key (aref key i)))
1629 ;; Show followable keys.
1630 (if (and (> (length key) 0) (cdr map))
1631 (let ((keys (mapcar (function (lambda (x) (car x)))
1633 (setq keys (sort keys '<))
1637 (setq keys (cdr keys)))
1640 ;; Show list of translations.
1641 (if current-translations
1642 (let* ((indices (car current-translations))
1644 (start (nth 1 indices))
1645 (end (nth 2 indices))
1647 (indent-to (- quail-guidance-translations-starting-column 7))
1648 (insert (format "(%02d/"(nth 3 indices))
1650 (format "%02d)" (nth 4 indices))
1653 (insert (format " %d." (if (= (- idx start) 9) 0
1654 (1+ (- idx start)))))
1655 (let ((pos (point)))
1656 (insert (aref (cdr current-translations) idx))
1658 (move-overlay quail-overlay pos (point))))
1659 (setq idx (1+ idx)))))
1662 (defun quail-completion ()
1663 "List all completions for the current key.
1664 All possible translations of the current key and whole possible longer keys
1667 (quail-setup-completion-buf)
1668 (let ((win (get-buffer-window quail-completion-buf 'visible))
1669 (key quail-current-key)
1670 (map (quail-lookup-key quail-current-key))
1671 (require-update nil))
1673 (set-buffer quail-completion-buf)
1675 (equal key quail-current-key)
1676 (eq last-command 'quail-completion))
1677 ;; The window for Quail completion buffer has already been
1678 ;; shown. We just scroll it appropriately.
1679 (if (pos-visible-in-window-p (point-max) win)
1680 (set-window-start win (point-min))
1681 (let ((other-window-scroll-buffer quail-completion-buf))
1682 (scroll-other-window)))
1683 (setq quail-current-key key)
1685 (insert "Possible completion and corresponding translations are:\n")
1686 (quail-completion-1 key map 1)
1687 (goto-char (point-min))
1688 (display-buffer (current-buffer))
1689 (setq require-update t)))
1691 (quail-update-guidance)))
1692 (setq this-command 'quail-completion))
1694 ;; List all completions of KEY in MAP with indentation INDENT.
1695 (defun quail-completion-1 (key map indent)
1696 (let ((len (length key)))
1699 (if (and (symbolp map) (fboundp map))
1700 (setq map (funcall map key len)))
1702 (quail-completion-list-translations map key (+ indent len 1))
1704 (setq indent (+ indent 2))
1707 (newkey (make-string (1+ len) 0))
1709 ;; Set KEY in the first LEN characters of NEWKEY.
1711 (aset newkey i (aref key i))
1713 (while l ; L = ((CHAR . DEFN) ....) ;
1714 (aset newkey len (car (car l)))
1715 (quail-completion-1 newkey (cdr (car l)) indent)
1716 (setq l (cdr l)))))))
1718 ;; List all possible translations of KEY in Quail map MAP with
1719 ;; indentation INDENT.
1720 (defun quail-completion-list-translations (map key indent)
1721 (let (beg (translations
1722 (quail-get-translation (car map) key (length key))))
1723 (if (integerp translations)
1726 ;; Endow the character `translations' with `mouse-face' text
1727 ;; property to enable `mouse-2' completion.
1729 (insert translations)
1730 (put-text-property beg (point) 'mouse-face 'highlight)
1732 ;; We need only vector part.
1733 (setq translations (cdr translations))
1734 ;; Insert every 10 elements with indices in a line.
1735 (let ((len (length translations))
1739 (when (zerop (% i 10))
1743 (insert (format "(%d/%d)" (1+ (/ i 10)) (1+ (/ len 10)))))
1744 ;; We show the last digit of FROM while converting
1745 ;; 0,1,..,9 to 1,2,..,0.
1746 (insert (format " %d." (% (1+ i) 10)))
1748 (insert (aref translations i))
1749 ;; Passing the mouse over a character will highlight.
1750 (put-text-property beg (point) 'mouse-face 'highlight)
1754 ;; Choose a completion in *Quail Completions* buffer with mouse-2.
1756 (defun quail-mouse-choose-completion (event)
1757 "Click on an alternative in the `*Quail Completions*' buffer to choose it."
1759 ;; This function is an exact copy of the mouse.el function
1760 ;; `mouse-choose-completion' except that we:
1761 ;; 1) add two lines from `choose-completion' in simple.el to give
1762 ;; the `mouse-2' click a little more leeway.
1763 ;; 2) don't bury *Quail Completions* buffer so comment a section, and
1764 ;; 3) delete/terminate the current quail selection here.
1765 ;; Give temporary modes such as isearch a chance to turn off.
1766 (run-hooks 'mouse-leave-buffer-hook)
1767 (let ((buffer (window-buffer))
1771 (set-buffer (window-buffer (posn-window (event-start event))))
1772 (if completion-reference-buffer
1773 (setq buffer completion-reference-buffer))
1774 (setq base-size completion-base-size)
1776 (goto-char (posn-point (event-start event)))
1778 (if (and (not (eobp)) (get-text-property (point) 'mouse-face))
1779 (setq end (point) beg (1+ (point))))
1780 (if (and (not (bobp)) (get-text-property (1- (point)) 'mouse-face))
1781 (setq end (1- (point)) beg (point)))
1783 (quail-error "No completion here"))
1784 (setq beg (previous-single-property-change beg 'mouse-face))
1785 (setq end (or (next-single-property-change end 'mouse-face)
1787 (setq choice (buffer-substring beg end)))))
1788 ; (let ((owindow (selected-window)))
1789 ; (select-window (posn-window (event-start event)))
1790 ; (if (and (one-window-p t 'selected-frame)
1791 ; (window-dedicated-p (selected-window)))
1792 ; ;; This is a special buffer's frame
1793 ; (iconify-frame (selected-frame))
1794 ; (or (window-dedicated-p (selected-window))
1796 ; (select-window owindow))
1797 (quail-delete-region)
1798 (quail-choose-completion-string choice buffer base-size)
1799 (quail-terminate-translation)))
1801 ;; Modify the simple.el function `choose-completion-string', because
1802 ;; the simple.el function `choose-completion-delete-max-match' breaks
1803 ;; on Mule data, since the semantics of `forward-char' have changed.
1805 (defun quail-choose-completion-string (choice &optional buffer base-size)
1806 (let ((buffer (or buffer completion-reference-buffer)))
1807 ;; If BUFFER is a minibuffer, barf unless it's the currently
1808 ;; active minibuffer.
1809 (if (and (string-match "\\` \\*Minibuf-[0-9]+\\*\\'" (buffer-name buffer))
1810 (or (not (active-minibuffer-window))
1812 (window-buffer (active-minibuffer-window))))))
1813 (quail-error "Minibuffer is not active for completion")
1814 ;; Store the completion in `quail-current-str', which will later
1815 ;; be converted to a character event list, then inserted into
1816 ;; the buffer where completion was requested.
1819 ; (delete-region (+ base-size (point-min)) (point))
1820 ; (choose-completion-delete-max-match choice))
1821 (setq quail-current-str choice)
1822 ;; Update point in the window that BUFFER is showing in.
1823 (let ((window (get-buffer-window buffer t)))
1824 (set-window-point window (point)))
1825 ;; If completing for the minibuffer, exit it with this choice.
1826 (and (not completion-no-auto-exit)
1827 (equal buffer (window-buffer (minibuffer-window)))
1828 minibuffer-completion-table
1829 ;; If this is reading a file name, and the file name chosen
1830 ;; is a directory, don't exit the minibuffer.
1831 (if (and (eq minibuffer-completion-table 'read-file-name-internal)
1832 (file-directory-p (buffer-string)))
1833 (select-window (active-minibuffer-window))
1834 (exit-minibuffer))))))
1836 (defun quail-help ()
1837 "Show brief description of the current Quail package."
1839 (let ((package quail-current-package))
1840 (with-output-to-temp-buffer "*Quail-Help*"
1842 (set-buffer standard-output)
1843 (let ((quail-current-package package))
1844 (insert "Quail input method (name:"
1846 ", mode line indicator:["
1848 "])\n---- Documentation ----\n"
1851 (if (quail-show-layout) (quail-show-kbd-layout))
1852 (quail-help-insert-keymap-description
1853 (quail-translation-keymap)
1854 "--- Key bindings (while translating) ---
1857 (if (quail-conversion-keymap)
1858 (quail-help-insert-keymap-description
1859 (quail-conversion-keymap)
1860 "--- Key bindings (while converting) ---
1865 (defun quail-help-insert-keymap-description (keymap &optional header)
1870 (save-window-excursion
1871 (let ((overriding-terminal-local-map keymap))
1872 (describe-bindings))
1873 (set-buffer "*Help*")
1874 (goto-char (point-min))
1877 (search-forward "Global Bindings:" nil 'move)
1880 (insert-buffer-substring "*Help*" from to)))
1882 (defun quail-show-kbd-layout ()
1883 "Show keyboard layout with key tops of multilingual characters."
1884 (insert "--- Keyboard layout ---\n")
1886 (while (< i quail-keyboard-layout-len)
1890 (indent-to (/ i 30)))
1893 (setq ch (aref quail-keyboard-layout i))
1894 (when (and (quail-kbd-translate)
1896 ;; This is the case that the current input method simulates
1897 ;; some keyboard layout (which means it requires keyboard
1898 ;; translation) and a key at location `i' exists on users
1899 ;; keyboard. We must translate that key by
1900 ;; `quail-keyboard-layout-standard'. But if if there's no
1901 ;; corresponding key in that standard layout, we must simulate
1902 ;; what is inserted if that key is pressed by setting CH a
1904 (setq ch (aref quail-keyboard-layout-standard i))
1906 (setq ch (- (aref quail-keyboard-layout i)))))
1908 (let ((last-command-event (- ch)))
1909 (self-insert-command 1))
1912 (let* ((map (cdr (assq ch (cdr (quail-map)))))
1913 (translation (and map (quail-get-translation
1914 (car map) (char-to-string ch) 1))))
1915 (if (integerp translation)
1916 (insert translation)
1917 (if (consp translation)
1918 (insert (aref (cdr translation) (car (car translation))))
1919 (let ((last-command-event ch))
1920 (self-insert-command 1)))))))
1924 (defun quail-translation-help ()
1925 "Show help message while translating in Quail input method."
1927 (if (not (eq this-command last-command))
1928 (let (state-msg keymap)
1929 (if (and quail-converting (= (length quail-current-key) 0))
1931 (format "Converting string %S by input method %S.\n"
1932 quail-conversion-str (quail-name))
1933 keymap (quail-conversion-keymap))
1935 (format "Translating key sequence %S by input method %S.\n"
1936 quail-current-key (quail-name))
1937 keymap (quail-translation-keymap)))
1938 (with-output-to-temp-buffer "*Quail-Help*"
1940 (set-buffer standard-output)
1942 (quail-help-insert-keymap-description
1944 "-----------------------
1949 (save-selected-window
1950 (select-window (get-buffer-window "*Quail-Help*"))
1951 (if (eq this-command last-command)
1952 (if (< (window-end) (point-max))
1954 (if (> (window-start) (point-min))
1955 (set-window-start (selected-window) (point-min)))))
1957 (if (< (window-end (selected-window) 'up-to-date) (point-max))
1958 "Type \\[quail-translation-help] to scroll up the help"
1959 (if (> (window-start) (point-min))
1960 "Type \\[quail-translation-help] to see the head of help"))))
1963 (message "%s" (substitute-command-keys scroll-help))
1966 (quail-update-guidance)
1970 (defvar quail-directory-name "quail"
1971 "Name of Quail directory which contains Quail packages.
1972 This is a sub-directory of LEIM directory.")
1975 (defun quail-update-leim-list-file (dirname &rest dirnames)
1976 "Update entries for Quail packages in `LEIM' list file in directory DIRNAME.
1977 DIRNAME is a directory containing Emacs input methods;
1978 normally, it should specify the `leim' subdirectory
1979 of the Emacs source tree.
1981 It searches for Quail packages under `quail' subdirectory of DIRNAME,
1982 and update the file \"leim-list.el\" in DIRNAME.
1984 When called from a program, the remaining arguments are additional
1985 directory names to search for Quail packages under `quail' subdirectory
1987 (interactive "FDirectory of LEIM: ")
1988 (setq dirname (expand-file-name dirname))
1989 (let ((leim-list (expand-file-name leim-list-file-name dirname))
1990 quail-dirs list-buf pkg-list pkg-buf pos)
1991 (if (not (file-writable-p leim-list))
1992 (error "Can't write to file \"%s\"" leim-list))
1993 (message "Updating %s ..." leim-list)
1994 (setq list-buf (find-file-noselect leim-list))
1996 ;; At first, clean up the file.
1998 (set-buffer list-buf)
2001 ;; Insert the correct header.
2002 (if (looking-at (regexp-quote leim-list-header))
2003 (goto-char (match-end 0))
2004 (insert leim-list-header))
2006 (if (not (re-search-forward leim-list-entry-regexp nil t))
2009 ;; Remove garbages after the header.
2010 (goto-char (match-beginning 0))
2012 (delete-region pos (point)))
2014 ;; Remove all entries for Quail.
2015 (while (re-search-forward leim-list-entry-regexp nil 'move)
2016 (goto-char (match-beginning 0))
2019 (let ((form (read list-buf)))
2020 (when (equal (nth 3 form) ''quail-use-package)
2021 (if (eolp) (forward-line 1))
2022 (delete-region pos (point))))
2024 ;; Delete the remaining contents because it seems that
2025 ;; this file is broken.
2026 (message "Garbage in %s deleted" leim-list)
2027 (delete-region pos (point-max)))))))
2029 ;; Search for `quail' subdirectory under each DIRNAMES.
2030 (setq dirnames (cons dirname dirnames))
2033 (setcar l (expand-file-name (car l)))
2034 (setq dirname (expand-file-name quail-directory-name (car l)))
2035 (if (file-readable-p dirname)
2036 (setq quail-dirs (cons dirname quail-dirs))
2037 (message "%s doesn't have `%s' subdirectory, just ignored"
2038 (car l) quail-directory-name)
2039 (setq quail-dirs (cons nil quail-dirs)))
2041 (setq quail-dirs (nreverse quail-dirs)))
2043 ;; Insert input method registering forms.
2045 (setq dirname (car quail-dirs))
2047 (setq pkg-list (directory-files dirname 'full "\\.el$" 'nosort))
2049 (message "Checking %s ..." (car pkg-list))
2051 (insert-file-contents (car pkg-list))
2052 (goto-char (point-min))
2053 (while (search-forward "(quail-define-package" nil t)
2054 (goto-char (match-beginning 0))
2056 (let ((form (read (current-buffer))))
2058 (set-buffer list-buf)
2060 (format "(register-input-method
2064 (nth 1 form) ; PACKAGE-NAME
2065 (nth 2 form) ; LANGUAGE
2066 'quail-use-package ; ACTIVATE-FUNC
2067 (nth 3 form) ; PACKAGE-TITLE
2068 (progn ; PACKAGE-DESCRIPTION (one line)
2069 (string-match ".*" (nth 5 form))
2070 (match-string 0 (nth 5 form)))
2071 (file-relative-name ; PACKAGE-FILENAME
2072 (file-name-sans-extension (car pkg-list))
2075 ;; Ignore the remaining contents of this file.
2076 (goto-char (point-max))
2077 (message "Some part of \"%s\" is broken" dirname)))))
2078 (setq pkg-list (cdr pkg-list)))
2079 (setq quail-dirs (cdr quail-dirs) dirnames (cdr dirnames))))
2081 ;; At last, write out LEIM list file.
2083 (set-buffer list-buf)
2084 (setq buffer-file-coding-system 'iso-2022-7bit)
2086 (kill-buffer list-buf)
2087 (message "Updating %s ... done" leim-list)))
2091 ;;; quail.el ends here