diff options
| author | Kenichi Handa | 1997-06-18 12:55:07 +0000 |
|---|---|---|
| committer | Kenichi Handa | 1997-06-18 12:55:07 +0000 |
| commit | ff913e9291cb2fa8658f0e8b36edc51b894291ca (patch) | |
| tree | 9e8cb2b93767d919cc5a7231bdc53e2a792bec13 | |
| parent | fc3c34a837c07ae097608f836a97330dcb09ff8c (diff) | |
| download | emacs-ff913e9291cb2fa8658f0e8b36edc51b894291ca.tar.gz emacs-ff913e9291cb2fa8658f0e8b36edc51b894291ca.zip | |
(quail-current-data): New variable.
(quail-use-package): Do not reload a package already loaded.
(quail-define-package): Update TITLE field of input-method-alist.
(quail-map-p): TRANSLATION may be a cons.
(quail-define-rules): Add autoload cookie.
(quail-defrule): Add autoload cookie. Handle the case that TRANS
is a cons.
(quail-get-translation, quail-lookup-key, quail-translate-key,
quail-show-translations, quail-completion-list-translations,
quail-show-kbd-layout): Likewise.
(quail-hide-guidance-buf): Check if window WIN exists before
deleting it.
(quail-directory-name): New variable.
(quail-update-leim-list-file): New function.
| -rw-r--r-- | lisp/international/quail.el | 268 |
1 files changed, 195 insertions, 73 deletions
diff --git a/lisp/international/quail.el b/lisp/international/quail.el index 53901ceeaa9..945c970daed 100644 --- a/lisp/international/quail.el +++ b/lisp/international/quail.el | |||
| @@ -81,6 +81,13 @@ See the documentation of `quail-package-alist' for the format.") | |||
| 81 | (defvar quail-current-translations nil | 81 | (defvar quail-current-translations nil |
| 82 | "Cons of indices and vector of possible translations of the current key.") | 82 | "Cons of indices and vector of possible translations of the current key.") |
| 83 | 83 | ||
| 84 | (defvar quail-current-data nil | ||
| 85 | "Any Lisp object holding information of current translation status. | ||
| 86 | When a key sequence is mapped to TRANS and TRANS is a cons | ||
| 87 | of actual translation and some Lisp object to be refered | ||
| 88 | for translating the longer key sequence, this variable is set | ||
| 89 | to that Lisp object.") | ||
| 90 | |||
| 84 | ;; A flag to control conversion region. Normally nil, but if set to | 91 | ;; A flag to control conversion region. Normally nil, but if set to |
| 85 | ;; t, it means we must start the new conversion region if new key to | 92 | ;; t, it means we must start the new conversion region if new key to |
| 86 | ;; be translated is input. | 93 | ;; be translated is input. |
| @@ -185,27 +192,26 @@ Conversion keymap is a keymap used while conversion region is active | |||
| 185 | (defun quail-use-package (package-name &rest libraries) | 192 | (defun quail-use-package (package-name &rest libraries) |
| 186 | "Start using Quail package PACKAGE-NAME. | 193 | "Start using Quail package PACKAGE-NAME. |
| 187 | The remaining arguments are libraries to be loaded before using the package." | 194 | The remaining arguments are libraries to be loaded before using the package." |
| 188 | (while libraries | 195 | (let ((package (quail-package package-name))) |
| 189 | (if (not (load (car libraries) t)) | 196 | (if (null package) |
| 190 | (progn | 197 | ;; Perhaps we have not yet loaded necessary libraries. |
| 191 | (with-output-to-temp-buffer "*Help*" | 198 | (while libraries |
| 192 | (princ "Quail package \"") | 199 | (if (not (load (car libraries) t)) |
| 193 | (princ package-name) | 200 | (progn |
| 194 | (princ "\" can't be activated\n because library \"") | 201 | (with-output-to-temp-buffer "*Help*" |
| 195 | (princ (car libraries)) | 202 | (princ "Quail package \"") |
| 196 | (princ "\" is not in `load-path'. | 203 | (princ package-name) |
| 204 | (princ "\" can't be activated\n because library \"") | ||
| 205 | (princ (car libraries)) | ||
| 206 | (princ "\" is not in `load-path'. | ||
| 197 | 207 | ||
| 198 | The most common case is that you have not yet installed appropriate | 208 | The most common case is that you have not yet installed appropriate |
| 199 | libraries in LEIM (Libraries of Emacs Input Method) which is | 209 | libraries in LEIM (Libraries of Emacs Input Method) which is |
| 200 | distributed separately from Emacs. | 210 | distributed separately from Emacs. |
| 201 | 211 | ||
| 202 | Installation of LEIM for Quail is very simple, just copy Quail | ||
| 203 | packages (byte-compiled Emacs Lisp files) to somewhere in your | ||
| 204 | `load-path'. | ||
| 205 | |||
| 206 | LEIM is available from the same ftp directory as Emacs.")) | 212 | LEIM is available from the same ftp directory as Emacs.")) |
| 207 | (error "Can't use the Quail package `%s'" package-name)) | 213 | (error "Can't use the Quail package `%s'" package-name)) |
| 208 | (setq libraries (cdr libraries)))) | 214 | (setq libraries (cdr libraries)))))) |
| 209 | (quail-select-package package-name) | 215 | (quail-select-package package-name) |
| 210 | (setq current-input-method-title (quail-title)) | 216 | (setq current-input-method-title (quail-title)) |
| 211 | (quail-mode 1)) | 217 | (quail-mode 1)) |
| @@ -295,6 +301,7 @@ This map is activated while translation region is active.") | |||
| 295 | This map is activated while convesion region is active but translation | 301 | This map is activated while convesion region is active but translation |
| 296 | region is not active.") | 302 | region is not active.") |
| 297 | 303 | ||
| 304 | ;;;###autoload | ||
| 298 | (defun quail-define-package (name language title | 305 | (defun quail-define-package (name language title |
| 299 | &optional guidance docstring translation-keys | 306 | &optional guidance docstring translation-keys |
| 300 | forget-last-selection deterministic | 307 | forget-last-selection deterministic |
| @@ -393,8 +400,10 @@ vs. corresponding command to be called." | |||
| 393 | forget-last-selection deterministic kbd-translate show-layout | 400 | forget-last-selection deterministic kbd-translate show-layout |
| 394 | (if create-decode-map (list 'decode-map) nil) | 401 | (if create-decode-map (list 'decode-map) nil) |
| 395 | maximum-shortest overlay-plist update-translation-function | 402 | maximum-shortest overlay-plist update-translation-function |
| 396 | conversion-keymap))) | 403 | conversion-keymap)) |
| 397 | (register-input-method language (list name 'quail-use-package)) | 404 | ;; Update TITLE field. |
| 405 | (let ((slot (assoc name input-method-alist))) | ||
| 406 | (if slot (setcar (nthcdr 4 slot) docstring)))) | ||
| 398 | (quail-select-package name)) | 407 | (quail-select-package name)) |
| 399 | 408 | ||
| 400 | ;; Quail minor mode handlers. | 409 | ;; Quail minor mode handlers. |
| @@ -425,10 +434,9 @@ vs. corresponding command to be called." | |||
| 425 | (if (overlayp quail-conv-overlay) | 434 | (if (overlayp quail-conv-overlay) |
| 426 | (delete-overlay quail-conv-overlay))) | 435 | (delete-overlay quail-conv-overlay))) |
| 427 | 436 | ||
| 428 | ;; While translating and converting, we enter the recursive edit and | 437 | ;; While translating and converting, we enter and exit the recursive |
| 429 | ;; exit it frequently, which results in frequent and annoying change | 438 | ;; edit frequently, which results in frequent and annoying change of |
| 430 | ;; of and annoying in mode line. To avoid it, we use a modified | 439 | ;; mode line. To avoid it, we use a modified mode-line-format. |
| 431 | ;; mode-line-format. | ||
| 432 | (defvar quail-mode-line-format nil) | 440 | (defvar quail-mode-line-format nil) |
| 433 | 441 | ||
| 434 | ;; Return a modified mode-line-format which doesn't show the recursive | 442 | ;; Return a modified mode-line-format which doesn't show the recursive |
| @@ -658,12 +666,15 @@ the translation. These objects are transformed to cons cells in the | |||
| 658 | format \(INDEX . VECTOR), as described above." | 666 | format \(INDEX . VECTOR), as described above." |
| 659 | (and (consp object) | 667 | (and (consp object) |
| 660 | (let ((translation (car object))) | 668 | (let ((translation (car object))) |
| 661 | (or (integerp translation) (consp translation) (null translation) | 669 | (or (integerp translation) (null translation) |
| 662 | (vectorp translation) (stringp translation) | 670 | (vectorp translation) (stringp translation) |
| 663 | (symbolp translation))) | 671 | (symbolp translation) |
| 672 | (and (consp translation) (not (vectorp (cdr translation)))))) | ||
| 664 | (let ((alist (cdr object))) | 673 | (let ((alist (cdr object))) |
| 665 | (or (listp alist) (symbolp alist))))) | 674 | (or (and (listp alist) (consp (car alist))) |
| 675 | (symbolp alist))))) | ||
| 666 | 676 | ||
| 677 | ;;;###autoload | ||
| 667 | (defmacro quail-define-rules (&rest rules) | 678 | (defmacro quail-define-rules (&rest rules) |
| 668 | "Define translation rules of the current Quail package. | 679 | "Define translation rules of the current Quail package. |
| 669 | Each argument is a list of KEY and TRANSLATION. | 680 | Each argument is a list of KEY and TRANSLATION. |
| @@ -685,6 +696,7 @@ If TRANSLATION is a Quail map or a function symbol which returns a Quail map, | |||
| 685 | (setq l (cdr l))) | 696 | (setq l (cdr l))) |
| 686 | map))) | 697 | map))) |
| 687 | 698 | ||
| 699 | ;;;###autoload | ||
| 688 | (defun quail-install-map (map) | 700 | (defun quail-install-map (map) |
| 689 | "Install the Quail map MAP in the current Quail package. | 701 | "Install the Quail map MAP in the current Quail package. |
| 690 | The installed map can be referred by the function `quail-map'." | 702 | The installed map can be referred by the function `quail-map'." |
| @@ -694,14 +706,18 @@ The installed map can be referred by the function `quail-map'." | |||
| 694 | (error "Invalid Quail map `%s'" map)) | 706 | (error "Invalid Quail map `%s'" map)) |
| 695 | (setcar (cdr (cdr quail-current-package)) map)) | 707 | (setcar (cdr (cdr quail-current-package)) map)) |
| 696 | 708 | ||
| 709 | ;;;###autoload | ||
| 697 | (defun quail-defrule (key translation &optional name) | 710 | (defun quail-defrule (key translation &optional name) |
| 698 | "Add one translation rule, KEY to TRANSLATION, in the current Quail package. | 711 | "Add one translation rule, KEY to TRANSLATION, in the current Quail package. |
| 699 | KEY is a string meaning a sequence of keystrokes to be translated. | 712 | KEY is a string meaning a sequence of keystrokes to be translated. |
| 700 | TRANSLATION is a character, a string, a vector, a Quail map, or a function. | 713 | TRANSLATION is a character, a string, a vector, a Quail map, |
| 714 | a function, or a cons. | ||
| 701 | It it is a character, it is the sole translation of KEY. | 715 | It it is a character, it is the sole translation of KEY. |
| 702 | If it is a string, each character is a candidate for the translation. | 716 | If it is a string, each character is a candidate for the translation. |
| 703 | If it is a vector, each element (string or character) is a candidate | 717 | If it is a vector, each element (string or character) is a candidate |
| 704 | for the translation. | 718 | for the translation. |
| 719 | If it is a cons, the car is one of the above and the cdr is a function | ||
| 720 | to call when translating KEY. | ||
| 705 | In these cases, a key specific Quail map is generated and assigned to KEY. | 721 | In these cases, a key specific Quail map is generated and assigned to KEY. |
| 706 | 722 | ||
| 707 | If TRANSLATION is a Quail map or a function symbol which returns a Quail map, | 723 | If TRANSLATION is a Quail map or a function symbol which returns a Quail map, |
| @@ -717,10 +733,12 @@ current Quail package." | |||
| 717 | (quail-defrule-internal key translation (quail-map))) | 733 | (quail-defrule-internal key translation (quail-map))) |
| 718 | 734 | ||
| 719 | ;; Define KEY as TRANS in a Quail map MAP. | 735 | ;; Define KEY as TRANS in a Quail map MAP. |
| 736 | ;;;###autoload | ||
| 720 | (defun quail-defrule-internal (key trans map) | 737 | (defun quail-defrule-internal (key trans map) |
| 721 | (if (null (stringp key)) | 738 | (if (null (stringp key)) |
| 722 | "Invalid Quail key `%s'" key) | 739 | "Invalid Quail key `%s'" key) |
| 723 | (if (not (or (numberp trans) (stringp trans) (vectorp trans) | 740 | (if (not (or (numberp trans) (stringp trans) (vectorp trans) |
| 741 | (consp trans) | ||
| 724 | (symbolp trans) | 742 | (symbolp trans) |
| 725 | (quail-map-p trans))) | 743 | (quail-map-p trans))) |
| 726 | (error "Invalid Quail translation `%s'" trans)) | 744 | (error "Invalid Quail translation `%s'" trans)) |
| @@ -729,6 +747,7 @@ current Quail package." | |||
| 729 | (let ((len (length key)) | 747 | (let ((len (length key)) |
| 730 | (idx 0) | 748 | (idx 0) |
| 731 | ch entry) | 749 | ch entry) |
| 750 | ;; Make a map for registering TRANS if necessary. | ||
| 732 | (while (< idx len) | 751 | (while (< idx len) |
| 733 | (if (null (consp map)) | 752 | (if (null (consp map)) |
| 734 | ;; We come here, for example, when we try to define a rule | 753 | ;; We come here, for example, when we try to define a rule |
| @@ -766,41 +785,43 @@ current Quail package." | |||
| 766 | (setcdr entry (append trans (cdr map))))) | 785 | (setcdr entry (append trans (cdr map))))) |
| 767 | (setcar map trans))))) | 786 | (setcar map trans))))) |
| 768 | 787 | ||
| 769 | (defun quail-get-translation (map key len) | 788 | (defun quail-get-translation (def key len) |
| 770 | "Return the translation specified in Quail map MAP for KEY of length LEN. | 789 | "Return the translation specified as DEF for KEY of length LEN. |
| 771 | The translation is either a character or a cons of the form (INDEX . VECTOR), | 790 | The translation is either a character or a cons of the form (INDEX . VECTOR), |
| 772 | where VECTOR is a vector of candidates (character or string) for | 791 | where VECTOR is a vector of candidates (character or string) for |
| 773 | the translation, and INDEX points into VECTOR to specify the currently | 792 | the translation, and INDEX points into VECTOR to specify the currently |
| 774 | selected translation." | 793 | selected translation." |
| 775 | (let ((def (car map))) | 794 | (if (and def (symbolp def)) |
| 776 | (if (and def (symbolp def)) | 795 | ;; DEF is a symbol of a function which returns valid translation. |
| 777 | ;; DEF is a symbol of a function which returns valid translation. | 796 | (setq def (funcall def key len))) |
| 778 | (setq def (funcall def key len))) | 797 | (if (and (consp def) (not (vectorp (cdr def)))) |
| 779 | (cond | 798 | (setq def (car def))) |
| 780 | ((or (integerp def) (consp def)) | 799 | |
| 781 | def) | 800 | (cond |
| 782 | 801 | ((or (integerp def) (consp def)) | |
| 783 | ((null def) | 802 | def) |
| 784 | ;; No translation. | 803 | |
| 785 | nil) | 804 | ((null def) |
| 786 | 805 | ;; No translation. | |
| 787 | ((stringp def) | 806 | nil) |
| 788 | ;; Each character in DEF is a candidate of translation. Reform | 807 | |
| 789 | ;; it as (INDEX . VECTOR). | 808 | ((stringp def) |
| 790 | (setq def (string-to-vector def)) | 809 | ;; Each character in DEF is a candidate of translation. Reform |
| 791 | ;; But if the length is 1, we don't need vector but a single | 810 | ;; it as (INDEX . VECTOR). |
| 792 | ;; character as the translation. | 811 | (setq def (string-to-vector def)) |
| 793 | (if (= (length def) 1) | 812 | ;; But if the length is 1, we don't need vector but a single |
| 794 | (aref def 0) | 813 | ;; candidate as the translation. |
| 795 | (cons 0 def))) | 814 | (if (= (length def) 1) |
| 796 | 815 | (aref def 0) | |
| 797 | ((vectorp def) | 816 | (cons 0 def))) |
| 798 | ;; Each element (string or character) in DEF is a candidate of | 817 | |
| 799 | ;; translation. Reform it as (INDEX . VECTOR). | 818 | ((vectorp def) |
| 800 | (cons 0 def)) | 819 | ;; Each element (string or character) in DEF is a candidate of |
| 801 | 820 | ;; translation. Reform it as (INDEX . VECTOR). | |
| 802 | (t | 821 | (cons 0 def)) |
| 803 | (error "Invalid object in Quail map: %s" def))))) | 822 | |
| 823 | (t | ||
| 824 | (error "Invalid object in Quail map: %s" def)))) | ||
| 804 | 825 | ||
| 805 | (defun quail-lookup-key (key len) | 826 | (defun quail-lookup-key (key len) |
| 806 | "Lookup KEY of length LEN in the current Quail map and return the definition. | 827 | "Lookup KEY of length LEN in the current Quail map and return the definition. |
| @@ -808,7 +829,7 @@ The returned value is a Quail map specific to KEY." | |||
| 808 | (let ((idx 0) | 829 | (let ((idx 0) |
| 809 | (map (quail-map)) | 830 | (map (quail-map)) |
| 810 | (kbd-translate (quail-kbd-translate)) | 831 | (kbd-translate (quail-kbd-translate)) |
| 811 | slot ch translation) | 832 | slot ch translation def) |
| 812 | (while (and map (< idx len)) | 833 | (while (and map (< idx len)) |
| 813 | (setq ch (if kbd-translate (quail-keyboard-translate (aref key idx)) | 834 | (setq ch (if kbd-translate (quail-keyboard-translate (aref key idx)) |
| 814 | (aref key idx))) | 835 | (aref key idx))) |
| @@ -819,12 +840,22 @@ The returned value is a Quail map specific to KEY." | |||
| 819 | (if (and (cdr slot) (symbolp (cdr slot))) | 840 | (if (and (cdr slot) (symbolp (cdr slot))) |
| 820 | (setcdr slot (funcall (cdr slot) key idx))) | 841 | (setcdr slot (funcall (cdr slot) key idx))) |
| 821 | (setq map (cdr slot))) | 842 | (setq map (cdr slot))) |
| 822 | (if (and map (setq translation (quail-get-translation map key len))) | 843 | (setq def (car map)) |
| 844 | (if (and map (setq translation (quail-get-translation def key len))) | ||
| 823 | (progn | 845 | (progn |
| 824 | ;; We may have to reform car part of MAP. | 846 | (if (and (consp def) (not (vectorp (cdr def)))) |
| 825 | (if (not (equal (car map) translation)) | 847 | (progn |
| 826 | (setcar map translation)) | 848 | (if (not (equal (car def) translation)) |
| 827 | (if (consp translation) | 849 | ;; We must reflect TRANSLATION to car part of DEF. |
| 850 | (setcar def translation)) | ||
| 851 | (setq quail-current-data | ||
| 852 | (if (functionp (cdr def)) | ||
| 853 | (funcall (cdr def)) | ||
| 854 | (cdr def)))) | ||
| 855 | (if (not (equal def translation)) | ||
| 856 | ;; We must reflect TRANSLATION to car part of MAP. | ||
| 857 | (setcar map translation))) | ||
| 858 | (if (and (consp translation) (vectorp (cdr translation))) | ||
| 828 | (progn | 859 | (progn |
| 829 | (setq quail-current-translations translation) | 860 | (setq quail-current-translations translation) |
| 830 | (if (quail-forget-last-selection) | 861 | (if (quail-forget-last-selection) |
| @@ -1003,6 +1034,8 @@ sequence counting from the head." | |||
| 1003 | def ch) | 1034 | def ch) |
| 1004 | (if map | 1035 | (if map |
| 1005 | (let ((def (car map))) | 1036 | (let ((def (car map))) |
| 1037 | (if (and (consp def) (not (vectorp (cdr def)))) | ||
| 1038 | (setq def (car def))) | ||
| 1006 | (setq quail-current-str | 1039 | (setq quail-current-str |
| 1007 | (if (consp def) (aref (cdr def) (car def)) def)) | 1040 | (if (consp def) (aref (cdr def) (car def)) def)) |
| 1008 | ;; Return t only if we can terminate the current translation. | 1041 | ;; Return t only if we can terminate the current translation. |
| @@ -1024,6 +1057,8 @@ sequence counting from the head." | |||
| 1024 | (quail-maximum-shortest) | 1057 | (quail-maximum-shortest) |
| 1025 | (>= len 4) | 1058 | (>= len 4) |
| 1026 | (setq def (car (quail-lookup-key quail-current-key (- len 2)))) | 1059 | (setq def (car (quail-lookup-key quail-current-key (- len 2)))) |
| 1060 | (if (and (consp def) (not (vectorp (cdr def)))) | ||
| 1061 | (setq def (car def))) | ||
| 1027 | (quail-lookup-key (substring quail-current-key -2) 2)) | 1062 | (quail-lookup-key (substring quail-current-key -2) 2)) |
| 1028 | ;; Now the sequence is "...ABCD", which can be split into | 1063 | ;; Now the sequence is "...ABCD", which can be split into |
| 1029 | ;; "...AB" and "CD..." to get valid translation. | 1064 | ;; "...AB" and "CD..." to get valid translation. |
| @@ -1239,10 +1274,10 @@ the bottommost ordinary window." | |||
| 1239 | ;; Delete the window for guidance buffer. | 1274 | ;; Delete the window for guidance buffer. |
| 1240 | (if (or (null input-method-tersely-flag) | 1275 | (if (or (null input-method-tersely-flag) |
| 1241 | (not (eq (selected-window) (minibuffer-window)))) | 1276 | (not (eq (selected-window) (minibuffer-window)))) |
| 1242 | (progn | 1277 | (if (setq win (get-buffer-window quail-guidance-buf)) |
| 1243 | (setq win (get-buffer-window quail-guidance-buf)) | 1278 | (progn |
| 1244 | (set-window-dedicated-p win nil) | 1279 | (set-window-dedicated-p win nil) |
| 1245 | (delete-window win)))))) | 1280 | (delete-window win))))))) |
| 1246 | 1281 | ||
| 1247 | (defun quail-update-guidance () | 1282 | (defun quail-update-guidance () |
| 1248 | "Update the Quail guidance buffer and completion buffer (if displayed now)." | 1283 | "Update the Quail guidance buffer and completion buffer (if displayed now)." |
| @@ -1309,8 +1344,11 @@ the bottommost ordinary window." | |||
| 1309 | 1344 | ||
| 1310 | (defun quail-show-translations () | 1345 | (defun quail-show-translations () |
| 1311 | "Show the current possible translations." | 1346 | "Show the current possible translations." |
| 1312 | (let ((key quail-current-key) | 1347 | (let* ((key quail-current-key) |
| 1313 | (map (quail-lookup-key quail-current-key (length quail-current-key)))) | 1348 | (map (quail-lookup-key quail-current-key (length quail-current-key))) |
| 1349 | (def (car map))) | ||
| 1350 | (if (and (consp def) (not (vectorp (cdr def)))) | ||
| 1351 | (setq def (car def))) | ||
| 1314 | (save-excursion | 1352 | (save-excursion |
| 1315 | (set-buffer quail-guidance-buf) | 1353 | (set-buffer quail-guidance-buf) |
| 1316 | (erase-buffer) | 1354 | (erase-buffer) |
| @@ -1328,9 +1366,9 @@ the bottommost ordinary window." | |||
| 1328 | (insert "]"))) | 1366 | (insert "]"))) |
| 1329 | 1367 | ||
| 1330 | ;; Show list of translations. | 1368 | ;; Show list of translations. |
| 1331 | (if (consp (car map)) | 1369 | (if (and (not (quail-deterministic)) (consp def)) |
| 1332 | (let* ((idx (car (car map))) | 1370 | (let* ((idx (car def)) |
| 1333 | (translations (cdr (car map))) | 1371 | (translations (cdr def)) |
| 1334 | (from (* (/ idx 10) 10)) | 1372 | (from (* (/ idx 10) 10)) |
| 1335 | (to (min (+ from 10) (length translations)))) | 1373 | (to (min (+ from 10) (length translations)))) |
| 1336 | (indent-to 10) | 1374 | (indent-to 10) |
| @@ -1393,7 +1431,7 @@ All possible translations of the current key and whole possible longer keys | |||
| 1393 | ;; indentation INDENT. | 1431 | ;; indentation INDENT. |
| 1394 | (defun quail-completion-list-translations (map key indent) | 1432 | (defun quail-completion-list-translations (map key indent) |
| 1395 | (let ((translations | 1433 | (let ((translations |
| 1396 | (quail-get-translation map key (length key)))) | 1434 | (quail-get-translation (car map) key (length key)))) |
| 1397 | (if (integerp translations) | 1435 | (if (integerp translations) |
| 1398 | (insert "(1/1) 1." translations "\n") | 1436 | (insert "(1/1) 1." translations "\n") |
| 1399 | ;; We need only vector part. | 1437 | ;; We need only vector part. |
| @@ -1492,7 +1530,7 @@ key binding | |||
| 1492 | (insert ch) | 1530 | (insert ch) |
| 1493 | (let* ((map (cdr (assq ch (cdr (quail-map))))) | 1531 | (let* ((map (cdr (assq ch (cdr (quail-map))))) |
| 1494 | (translation (and map (quail-get-translation | 1532 | (translation (and map (quail-get-translation |
| 1495 | map (char-to-string ch) 1)))) | 1533 | (car map) (char-to-string ch) 1)))) |
| 1496 | (if (integerp translation) | 1534 | (if (integerp translation) |
| 1497 | (insert translation) | 1535 | (insert translation) |
| 1498 | (if (consp translation) | 1536 | (if (consp translation) |
| @@ -1545,6 +1583,90 @@ key binding | |||
| 1545 | (set-buffer-modified-p nil)) | 1583 | (set-buffer-modified-p nil)) |
| 1546 | (display-buffer buf))) | 1584 | (display-buffer buf))) |
| 1547 | 1585 | ||
| 1586 | |||
| 1587 | (defvar quail-directory-name "quail" | ||
| 1588 | "Name of Quail directory which cotains Quail packages. | ||
| 1589 | This is a sub-directory of LEIM directory.") | ||
| 1590 | |||
| 1591 | ;;;###autoload | ||
| 1592 | (defun quail-update-leim-list-file (dirname) | ||
| 1593 | "Update entries for Quail packages in LEIM list file of directory DIRNAME. | ||
| 1594 | LEIM is a library of Emacs input method." | ||
| 1595 | (interactive "FDirectory of LEIM: ") | ||
| 1596 | (setq dirname (file-name-as-directory (expand-file-name dirname))) | ||
| 1597 | (let ((quail-dir (concat dirname quail-directory-name)) | ||
| 1598 | (filename (concat dirname leim-list-file-name)) | ||
| 1599 | list-buf pkg-list pkg-buf pos) | ||
| 1600 | (if (not (file-exists-p quail-dir)) | ||
| 1601 | nil | ||
| 1602 | (if (not (file-readable-p quail-dir)) | ||
| 1603 | (message "Can't write to file \"%s\"" filename) | ||
| 1604 | (if (not (file-writable-p filename)) | ||
| 1605 | (message "Can't write to file \"%s\"" filename) | ||
| 1606 | (setq list-buf (find-file-noselect filename)) | ||
| 1607 | (setq pkg-list (directory-files quail-dir 'full ".*\\.el$" 'nosort)) | ||
| 1608 | (message "Updating %s ..." filename) | ||
| 1609 | |||
| 1610 | ;; At first, clean up the file. | ||
| 1611 | (save-excursion | ||
| 1612 | (set-buffer list-buf) | ||
| 1613 | (goto-char 1) | ||
| 1614 | |||
| 1615 | ;; Insert the correct header. | ||
| 1616 | (if (looking-at (regexp-quote leim-list-header)) | ||
| 1617 | (goto-char (match-end 0)) | ||
| 1618 | (insert leim-list-header)) | ||
| 1619 | (setq pos (point)) | ||
| 1620 | (if (not (re-search-forward leim-list-entry-regexp nil t)) | ||
| 1621 | nil | ||
| 1622 | |||
| 1623 | ;; Remove garbages after the header. | ||
| 1624 | (goto-char (match-beginning 0)) | ||
| 1625 | (if (< pos (point)) | ||
| 1626 | (delete-region pos (point))) | ||
| 1627 | |||
| 1628 | ;; Remove all entries for Quail. | ||
| 1629 | (while (re-search-forward leim-list-entry-regexp nil 'move) | ||
| 1630 | (goto-char (match-beginning 0)) | ||
| 1631 | (setq pos (point)) | ||
| 1632 | (let ((form (read list-buf))) | ||
| 1633 | (if (equal (nth 3 form) ''quail-use-package) | ||
| 1634 | (progn | ||
| 1635 | (if (eolp) (forward-line 1)) | ||
| 1636 | (delete-region pos (point)))))))) | ||
| 1637 | |||
| 1638 | ;; Insert entries for Quail. | ||
| 1639 | (while pkg-list | ||
| 1640 | (message "Checking %s ..." (car pkg-list)) | ||
| 1641 | (setq pkg-buf (find-file-noselect (car pkg-list))) | ||
| 1642 | (save-excursion | ||
| 1643 | (set-buffer pkg-buf) | ||
| 1644 | (while (search-forward "(quail-define-package" nil t) | ||
| 1645 | (goto-char (match-beginning 0)) | ||
| 1646 | (let ((form (read (current-buffer)))) | ||
| 1647 | (save-excursion | ||
| 1648 | (set-buffer list-buf) | ||
| 1649 | (insert (format "(register-input-method | ||
| 1650 | %S %S '%s | ||
| 1651 | %S %S | ||
| 1652 | %S)\n" (nth 1 form) ; PACKAGE-NAME | ||
| 1653 | (nth 2 form) ; LANGUAGE | ||
| 1654 | 'quail-use-package ; ACTIVATE-FUNC | ||
| 1655 | (nth 3 form) ; PACKAGE-TITLE | ||
| 1656 | (progn ; PACKAGE-DESCRIPTION (one line) | ||
| 1657 | (string-match ".*" (nth 5 form)) | ||
| 1658 | (match-string 0 (nth 5 form))) | ||
| 1659 | (file-relative-name ; PACKAGE-FILENAME | ||
| 1660 | (file-name-sans-extension (car pkg-list)) dirname) | ||
| 1661 | )))))) | ||
| 1662 | (kill-buffer pkg-buf) | ||
| 1663 | (setq pkg-list (cdr pkg-list))) | ||
| 1664 | (save-excursion | ||
| 1665 | (set-buffer list-buf) | ||
| 1666 | (setq buffer-file-coding-system 'iso-2022-7bit) | ||
| 1667 | (save-buffer)) | ||
| 1668 | (kill-buffer list-buf) | ||
| 1669 | (message "Updating %s ... done" (buffer-file-name list-buf))))))) | ||
| 1548 | ;; | 1670 | ;; |
| 1549 | (provide 'quail) | 1671 | (provide 'quail) |
| 1550 | 1672 | ||