Mercurial > emacs
comparison lisp/international/quail.el @ 18556:99e8ae18137f
(quail-guidance-buf): Make it buffer
local.
(quail-guidance-win): New variable. Make it buffer local.
(quail-current-translations): Doc-string modified.
(quail-current-data): Make it buffer local.
(quail-define-package): Update input-method-alist.
(quail-defrule): Doc-string modified.
(quail-defrule-internal): Document it.
(quail-get-translation): Change the format of DEF part.
(quail-lookup-key): Make the second argument LEN optional. Reset
quail-current-translations to nil.
(quail-map-definition): New funtion.
(quail-get-current-str): New function.
(quail-guidance-translations-starting-column): New variable.
(quail-update-current-translations): New function.
(quail-translate-key): Adjusted for the change of DEF format.
Call quail-update-current-translations
(quail-next-translation): Call quail-update-current-translations.
(quail-prev-translation): Likewise.
(quail-next-translation-block): Likewise.
(quail-prev-translation-block): Likewise.
(quail-select-translation): Deleted.
(quail-make-guidance-frame): New function.
(quail-show-guidance-buf): Handle the case that minibuffer is in a
separate frame.
(quail-hide-guidance-buf): Likewise.
(quail-show-translations): Call
quail-update-current-translations. Check width of a frame to be
used.
(quail-completion): Do not supply LEN argument to
quail-lookup-key.
(quail-help): Use with-output-to-temp-buffer.
(quail-translation-help): Likewise.
(quail-conversion-help): Likewise.
(quail-update-leim-list-file): Save buffer without making a backup
file.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Wed, 02 Jul 1997 12:59:37 +0000 |
parents | 8b4a66c66dd6 |
children | 0fc832264117 |
comparison
equal
deleted
inserted
replaced
18555:39589a3b1b20 | 18556:99e8ae18137f |
---|---|
57 ;; A buffer to show available key sequence or translation list. | 57 ;; A buffer to show available key sequence or translation list. |
58 (defvar quail-guidance-buf nil) | 58 (defvar quail-guidance-buf nil) |
59 ;; A buffer to show completion list of the current key sequence. | 59 ;; A buffer to show completion list of the current key sequence. |
60 (defvar quail-completion-buf nil) | 60 (defvar quail-completion-buf nil) |
61 | 61 |
62 ;; Each buffer in which Quail is activated should use different | |
63 ;; guidance buffers. | |
64 (make-variable-buffer-local 'quail-guidance-buf) | |
65 | |
66 ;; A main window showing Quail guidance buffer. | |
67 (defvar quail-guidance-win nil) | |
68 (make-variable-buffer-local 'quail-guidance-win) | |
69 | |
62 (defvar quail-mode nil | 70 (defvar quail-mode nil |
63 "Non-nil if in Quail minor mode.") | 71 "Non-nil if in Quail minor mode.") |
64 (make-variable-buffer-local 'quail-mode) | 72 (make-variable-buffer-local 'quail-mode) |
65 (put 'quail-mode 'permanent-local t) | 73 (put 'quail-mode 'permanent-local t) |
66 | 74 |
77 | 85 |
78 (defvar quail-current-str nil | 86 (defvar quail-current-str nil |
79 "Currently selected translation of the current key.") | 87 "Currently selected translation of the current key.") |
80 | 88 |
81 (defvar quail-current-translations nil | 89 (defvar quail-current-translations nil |
82 "Cons of indices and vector of possible translations of the current key.") | 90 "Cons of indices and vector of possible translations of the current key. |
91 Indices is a list of (CURRENT START END BLOCK BLOCKS), where | |
92 CURRENT is an index of the current translation, | |
93 START and END are indices of the start and end of the current block, | |
94 BLOCK is the current block index, | |
95 BLOCKS is a number of blocks of translation.") | |
83 | 96 |
84 (defvar quail-current-data nil | 97 (defvar quail-current-data nil |
85 "Any Lisp object holding information of current translation status. | 98 "Any Lisp object holding information of current translation status. |
86 When a key sequence is mapped to TRANS and TRANS is a cons | 99 When a key sequence is mapped to TRANS and TRANS is a cons |
87 of actual translation and some Lisp object to be refered | 100 of actual translation and some Lisp object to be refered |
88 for translating the longer key sequence, this variable is set | 101 for translating the longer key sequence, this variable is set |
89 to that Lisp object.") | 102 to that Lisp object.") |
103 (make-variable-buffer-local 'quail-current-data) | |
90 | 104 |
91 ;; A flag to control conversion region. Normally nil, but if set to | 105 ;; A flag to control conversion region. Normally nil, but if set to |
92 ;; t, it means we must start the new conversion region if new key to | 106 ;; t, it means we must start the new conversion region if new key to |
93 ;; be translated is input. | 107 ;; be translated is input. |
94 (defvar quail-reset-conversion-region nil) | 108 (defvar quail-reset-conversion-region nil) |
399 translation-keymap | 413 translation-keymap |
400 forget-last-selection deterministic kbd-translate show-layout | 414 forget-last-selection deterministic kbd-translate show-layout |
401 (if create-decode-map (list 'decode-map) nil) | 415 (if create-decode-map (list 'decode-map) nil) |
402 maximum-shortest overlay-plist update-translation-function | 416 maximum-shortest overlay-plist update-translation-function |
403 conversion-keymap)) | 417 conversion-keymap)) |
404 ;; Update TITLE field. | 418 |
405 (let ((slot (assoc name input-method-alist))) | 419 ;; Update input-method-alist. |
406 (if slot (setcar (nthcdr 4 slot) docstring)))) | 420 (let ((slot (assoc name input-method-alist)) |
421 (val (list language 'quail-use-package title docstring))) | |
422 (if slot (setcdr slot val) | |
423 (setq input-method-alist (cons (cons name val) input-method-alist))))) | |
424 | |
407 (quail-select-package name)) | 425 (quail-select-package name)) |
408 | 426 |
409 ;; Quail minor mode handlers. | 427 ;; Quail minor mode handlers. |
410 | 428 |
411 ;; Setup overlays used in Quail mode. | 429 ;; Setup overlays used in Quail mode. |
709 ;;;###autoload | 727 ;;;###autoload |
710 (defun quail-defrule (key translation &optional name) | 728 (defun quail-defrule (key translation &optional name) |
711 "Add one translation rule, KEY to TRANSLATION, in the current Quail package. | 729 "Add one translation rule, KEY to TRANSLATION, in the current Quail package. |
712 KEY is a string meaning a sequence of keystrokes to be translated. | 730 KEY is a string meaning a sequence of keystrokes to be translated. |
713 TRANSLATION is a character, a string, a vector, a Quail map, | 731 TRANSLATION is a character, a string, a vector, a Quail map, |
714 a function, or a cons. | 732 a function, or a cons. |
715 It it is a character, it is the sole translation of KEY. | 733 It it is a character, it is the sole translation of KEY. |
716 If it is a string, each character is a candidate for the translation. | 734 If it is a string, each character is a candidate for the translation. |
717 If it is a vector, each element (string or character) is a candidate | 735 If it is a vector, each element (string or character) is a candidate |
718 for the translation. | 736 for the translation. |
719 If it is a cons, the car is one of the above and the cdr is a function | 737 If it is a cons, the car is one of the above and the cdr is a function |
720 to call when translating KEY. | 738 to call when translating KEY (the return value is assigned to the |
739 variable `quail-current-data'). If the cdr part is not a function, | |
740 the value itself is assigned to `quail-current-data'. | |
721 In these cases, a key specific Quail map is generated and assigned to KEY. | 741 In these cases, a key specific Quail map is generated and assigned to KEY. |
722 | 742 |
723 If TRANSLATION is a Quail map or a function symbol which returns a Quail map, | 743 If TRANSLATION is a Quail map or a function symbol which returns a Quail map, |
724 it is used to handle KEY. | 744 it is used to handle KEY. |
725 Optional argument NAME, if specified, says which Quail package | 745 Optional argument NAME, if specified, says which Quail package |
730 (if (null package) | 750 (if (null package) |
731 (error "No Quail package `%s'" name)) | 751 (error "No Quail package `%s'" name)) |
732 (setq quail-current-package package))) | 752 (setq quail-current-package package))) |
733 (quail-defrule-internal key translation (quail-map))) | 753 (quail-defrule-internal key translation (quail-map))) |
734 | 754 |
735 ;; Define KEY as TRANS in a Quail map MAP. | |
736 ;;;###autoload | 755 ;;;###autoload |
737 (defun quail-defrule-internal (key trans map) | 756 (defun quail-defrule-internal (key trans map) |
757 "Define KEY as TRANS in a Quail map MAP." | |
738 (if (null (stringp key)) | 758 (if (null (stringp key)) |
739 "Invalid Quail key `%s'" key) | 759 "Invalid Quail key `%s'" key) |
740 (if (not (or (numberp trans) (stringp trans) (vectorp trans) | 760 (if (not (or (numberp trans) (stringp trans) (vectorp trans) |
741 (consp trans) | 761 (consp trans) |
742 (symbolp trans) | 762 (symbolp trans) |
805 ;; No translation. | 825 ;; No translation. |
806 nil) | 826 nil) |
807 | 827 |
808 ((stringp def) | 828 ((stringp def) |
809 ;; Each character in DEF is a candidate of translation. Reform | 829 ;; Each character in DEF is a candidate of translation. Reform |
810 ;; it as (INDEX . VECTOR). | 830 ;; it as (INDICES . VECTOR). |
811 (setq def (string-to-vector def)) | 831 (setq def (string-to-vector def)) |
812 ;; But if the length is 1, we don't need vector but a single | 832 ;; But if the length is 1, we don't need vector but a single |
813 ;; candidate as the translation. | 833 ;; candidate as the translation. |
814 (if (= (length def) 1) | 834 (if (= (length def) 1) |
815 (aref def 0) | 835 (aref def 0) |
816 (cons 0 def))) | 836 (cons (list 0 0 0 0 nil) def))) |
817 | 837 |
818 ((vectorp def) | 838 ((vectorp def) |
819 ;; Each element (string or character) in DEF is a candidate of | 839 ;; Each element (string or character) in DEF is a candidate of |
820 ;; translation. Reform it as (INDEX . VECTOR). | 840 ;; translation. Reform it as (INDICES . VECTOR). |
821 (cons 0 def)) | 841 (cons (list 0 0 0 0 nil) def)) |
822 | 842 |
823 (t | 843 (t |
824 (error "Invalid object in Quail map: %s" def)))) | 844 (error "Invalid object in Quail map: %s" def)))) |
825 | 845 |
826 (defun quail-lookup-key (key len) | 846 (defun quail-lookup-key (key &optional len) |
827 "Lookup KEY of length LEN in the current Quail map and return the definition. | 847 "Lookup KEY of length LEN in the current Quail map and return the definition. |
828 The returned value is a Quail map specific to KEY." | 848 The returned value is a Quail map specific to KEY." |
849 (or len | |
850 (setq len (length key))) | |
829 (let ((idx 0) | 851 (let ((idx 0) |
830 (map (quail-map)) | 852 (map (quail-map)) |
831 (kbd-translate (quail-kbd-translate)) | 853 (kbd-translate (quail-kbd-translate)) |
832 slot ch translation def) | 854 slot ch translation def) |
833 (while (and map (< idx len)) | 855 (while (and map (< idx len)) |
839 (setq slot (assq ch (cdr map))) | 861 (setq slot (assq ch (cdr map))) |
840 (if (and (cdr slot) (symbolp (cdr slot))) | 862 (if (and (cdr slot) (symbolp (cdr slot))) |
841 (setcdr slot (funcall (cdr slot) key idx))) | 863 (setcdr slot (funcall (cdr slot) key idx))) |
842 (setq map (cdr slot))) | 864 (setq map (cdr slot))) |
843 (setq def (car map)) | 865 (setq def (car map)) |
866 (setq quail-current-translations nil) | |
844 (if (and map (setq translation (quail-get-translation def key len))) | 867 (if (and map (setq translation (quail-get-translation def key len))) |
845 (progn | 868 (progn |
846 (if (and (consp def) (not (vectorp (cdr def)))) | 869 (if (and (consp def) (not (vectorp (cdr def)))) |
847 (progn | 870 (progn |
848 (if (not (equal (car def) translation)) | 871 (if (not (equal (car def) translation)) |
857 (setcar map translation))) | 880 (setcar map translation))) |
858 (if (and (consp translation) (vectorp (cdr translation))) | 881 (if (and (consp translation) (vectorp (cdr translation))) |
859 (progn | 882 (progn |
860 (setq quail-current-translations translation) | 883 (setq quail-current-translations translation) |
861 (if (quail-forget-last-selection) | 884 (if (quail-forget-last-selection) |
862 (setcar quail-current-translations 0)))) | 885 (setcar (car quail-current-translations) 0)))) |
863 ;; We may have to reform cdr part of MAP. | 886 ;; We may have to reform cdr part of MAP. |
864 (if (and (cdr map) (symbolp (cdr map))) | 887 (if (and (cdr map) (symbolp (cdr map))) |
865 (progn | 888 (progn |
866 (setcdr map (funcall (cdr map) key len)))) | 889 (setcdr map (funcall (cdr map) key len)))) |
867 )) | 890 )) |
1020 (interactive "*") | 1043 (interactive "*") |
1021 (setq quail-current-key | 1044 (setq quail-current-key |
1022 (concat quail-current-key (char-to-string last-command-event))) | 1045 (concat quail-current-key (char-to-string last-command-event))) |
1023 (quail-update-translation (quail-translate-key))) | 1046 (quail-update-translation (quail-translate-key))) |
1024 | 1047 |
1048 ;; Return the actual definition part of Quail map MAP. | |
1049 (defun quail-map-definition (map) | |
1050 (let ((def (car map))) | |
1051 (if (and (consp def) (not (vectorp (cdr def)))) | |
1052 (setq def (car def))) | |
1053 def)) | |
1054 | |
1055 ;; Return a string to be shown as the current translation of key | |
1056 ;; sequence of length LEN. DEF is a definition part of Quail map for | |
1057 ;; the sequence. | |
1058 (defun quail-get-current-str (len def) | |
1059 (or (and (consp def) (aref (cdr def) (car (car def)))) | |
1060 def | |
1061 (and (> len 1) | |
1062 (let ((str (quail-get-current-str | |
1063 (1- len) | |
1064 (quail-map-definition (quail-lookup-key | |
1065 quail-current-key (1- len)))))) | |
1066 (if str | |
1067 (concat (if (stringp str) str (char-to-string str)) | |
1068 (substring quail-current-key (1- len) len))))))) | |
1069 | |
1070 (defvar quail-guidance-translations-starting-column 20) | |
1071 | |
1072 ;; Update `quail-current-translations' to make RELATIVE-INDEX the | |
1073 ;; current translation. | |
1074 (defun quail-update-current-translations (&optional relative-index) | |
1075 (let* ((indices (car quail-current-translations)) | |
1076 (cur (car indices)) | |
1077 (start (nth 1 indices)) | |
1078 (end (nth 2 indices))) | |
1079 ;; Validate the index number of current translation. | |
1080 (if (< cur 0) | |
1081 (setcar indices (setq cur 0)) | |
1082 (if (>= cur (length (cdr quail-current-translations))) | |
1083 (setcar indices | |
1084 (setq cur (1- (length (cdr quail-current-translations))))))) | |
1085 | |
1086 (if (or (null end) ; We have not yet calculated END. | |
1087 (< cur start) ; We moved to the previous block. | |
1088 (>= cur end)) ; We moved to the next block. | |
1089 (let ((len (length (cdr quail-current-translations))) | |
1090 (maxcol (- (window-width quail-guidance-win) | |
1091 quail-guidance-translations-starting-column)) | |
1092 (block (nth 3 indices)) | |
1093 col idx width trans num-items blocks) | |
1094 (if (< cur start) | |
1095 ;; We must calculate from the head. | |
1096 (setq start 0 block 0) | |
1097 (if end ; i.e. (>= cur end) | |
1098 (setq start end))) | |
1099 (setq idx start col 0 end start num-items 0) | |
1100 ;; Loop until we hit the tail, or reach the block of CUR. | |
1101 (while (and (< idx len) (>= cur end)) | |
1102 (if (= num-items 0) | |
1103 (setq start idx col 0 block (1+ block))) | |
1104 (setq trans (aref (cdr quail-current-translations) idx)) | |
1105 (setq width (if (integerp trans) (char-width trans) | |
1106 (string-width trans))) | |
1107 (setq col (+ col width 3) num-items (1+ num-items)) | |
1108 (if (and (> num-items 0) | |
1109 (or (>= col maxcol) (> num-items 10))) | |
1110 (setq end idx num-items 0) | |
1111 (setq idx (1+ idx)))) | |
1112 (setcar (nthcdr 3 indices) block) | |
1113 (if (>= idx len) | |
1114 (progn | |
1115 ;; We hit the tail before reaching MAXCOL. | |
1116 (setq end idx) | |
1117 (setcar (nthcdr 4 indices) block))) | |
1118 (setcar (cdr indices) start) | |
1119 (setcar (nthcdr 2 indices) end))) | |
1120 (if relative-index | |
1121 (if (>= (+ start relative-index) end) | |
1122 (setcar indices end) | |
1123 (setcar indices (+ start relative-index)))) | |
1124 (setq quail-current-str | |
1125 (aref (cdr quail-current-translations) (car indices))))) | |
1126 | |
1025 (defun quail-translate-key () | 1127 (defun quail-translate-key () |
1026 "Translate the current key sequence according to the current Quail map. | 1128 "Translate the current key sequence according to the current Quail map. |
1027 Return t if we can terminate the translation. | 1129 Return t if we can terminate the translation. |
1028 Return nil if the current key sequence may be followed by more keys. | 1130 Return nil if the current key sequence may be followed by more keys. |
1029 Return number if we can't find any translation for the current key | 1131 Return number if we can't find any translation for the current key |
1031 sequence counting from the head." | 1133 sequence counting from the head." |
1032 (let* ((len (length quail-current-key)) | 1134 (let* ((len (length quail-current-key)) |
1033 (map (quail-lookup-key quail-current-key len)) | 1135 (map (quail-lookup-key quail-current-key len)) |
1034 def ch) | 1136 def ch) |
1035 (if map | 1137 (if map |
1036 (let ((def (car map))) | 1138 (let ((def (quail-map-definition map))) |
1037 (if (and (consp def) (not (vectorp (cdr def)))) | 1139 (setq quail-current-str (quail-get-current-str len def)) |
1038 (setq def (car def))) | |
1039 (setq quail-current-str | |
1040 (if (consp def) (aref (cdr def) (car def)) def)) | |
1041 ;; Return t only if we can terminate the current translation. | 1140 ;; Return t only if we can terminate the current translation. |
1042 (and | 1141 (and |
1043 ;; No alternative translations. | 1142 ;; No alternative translations. |
1044 (or (null (consp def)) (= (length (cdr def)) 1)) | 1143 (or (null (consp def)) (= (length (cdr def)) 1)) |
1045 ;; No translation for the longer key. | 1144 ;; No translation for the longer key. |
1054 ;; There's no translation for the current key sequence. Before | 1153 ;; There's no translation for the current key sequence. Before |
1055 ;; giving up, we must check two possibilities. | 1154 ;; giving up, we must check two possibilities. |
1056 (cond ((and | 1155 (cond ((and |
1057 (quail-maximum-shortest) | 1156 (quail-maximum-shortest) |
1058 (>= len 4) | 1157 (>= len 4) |
1059 (setq def (car (quail-lookup-key quail-current-key (- len 2)))) | 1158 (setq def (quail-map-definition |
1060 (if (and (consp def) (not (vectorp (cdr def)))) | 1159 (quail-lookup-key quail-current-key (- len 2)))) |
1061 (setq def (car def))) | |
1062 (quail-lookup-key (substring quail-current-key -2) 2)) | 1160 (quail-lookup-key (substring quail-current-key -2) 2)) |
1063 ;; Now the sequence is "...ABCD", which can be split into | 1161 ;; Now the sequence is "...ABCD", which can be split into |
1064 ;; "...AB" and "CD..." to get valid translation. | 1162 ;; "...AB" and "CD..." to get valid translation. |
1065 ;; At first, get translation of "...AB". | 1163 ;; At first, get translation of "...AB". |
1066 (setq quail-current-str | 1164 (setq quail-current-str (quail-get-current-str (- len 2) def)) |
1067 (if (consp def) (aref (cdr def) (car def)) def)) | |
1068 ;; Then, return the length of "...AB". | 1165 ;; Then, return the length of "...AB". |
1069 (- len 2)) | 1166 (- len 2)) |
1070 | 1167 |
1071 ((and quail-current-translations | 1168 ((and quail-current-translations |
1072 (not (quail-deterministic)) | 1169 (not (quail-deterministic)) |
1073 (setq ch (aref quail-current-key (1- len))) | 1170 (setq ch (aref quail-current-key (1- len))) |
1074 (>= ch ?0) (<= ch ?9)) | 1171 (>= ch ?0) (<= ch ?9)) |
1075 ;; A numeric key is entered to select a desirable translation. | 1172 ;; A numeric key is entered to select a desirable translation. |
1076 (setq quail-current-key (substring quail-current-key 0 -1)) | 1173 (setq quail-current-key (substring quail-current-key 0 -1)) |
1077 (quail-select-translation | 1174 ;; We treat key 1,2..,9,0 as specifying 0,1,..8,9. |
1078 (+ (* (/ (car quail-current-translations) 10) 10) | 1175 (setq ch (if (= ch ?0) 9 (- ch ?1))) |
1079 ;; We treat key 1,2..,9,0 as specifying 0,1,..8,9. | 1176 (quail-update-current-translations ch) |
1080 (if (= ch ?0) 9 (- ch ?1)))) | |
1081 ;; And, we can terminate the current translation. | 1177 ;; And, we can terminate the current translation. |
1082 t) | 1178 t) |
1083 | 1179 |
1084 (t | 1180 (t |
1085 ;; No way to handle the last character in this context. | 1181 ;; No way to handle the last character in this context. |
1087 | 1183 |
1088 (defun quail-next-translation () | 1184 (defun quail-next-translation () |
1089 "Select next translation in the current batch of candidates." | 1185 "Select next translation in the current batch of candidates." |
1090 (interactive) | 1186 (interactive) |
1091 (if quail-current-translations | 1187 (if quail-current-translations |
1092 (progn | 1188 (let ((indices (car quail-current-translations))) |
1093 (quail-select-translation (1+ (car quail-current-translations))) | 1189 (if (= (1+ (car indices)) (length (cdr quail-current-translations))) |
1094 (quail-update-translation nil)) | 1190 ;; We are alread at the tail. |
1191 (beep) | |
1192 (setcar indices (1+ (car indices))) | |
1193 (quail-update-current-translations) | |
1194 (quail-update-translation nil))) | |
1095 (beep))) | 1195 (beep))) |
1096 | 1196 |
1097 (defun quail-prev-translation () | 1197 (defun quail-prev-translation () |
1098 "Select previous translation in the current batch of candidates." | 1198 "Select previous translation in the current batch of candidates." |
1099 (interactive) | 1199 (interactive) |
1100 (if quail-current-translations | 1200 (if quail-current-translations |
1101 (progn | 1201 (let ((indices (car quail-current-translations))) |
1102 (quail-select-translation (1- (car quail-current-translations))) | 1202 (if (= (car indices) 0) |
1103 (quail-update-translation nil)) | 1203 ;; We are already at the head. |
1204 (beep) | |
1205 (setcar indices (1- (car indices))) | |
1206 (quail-update-current-translations) | |
1207 (quail-update-translation nil))) | |
1104 (beep))) | 1208 (beep))) |
1105 | 1209 |
1106 (defun quail-next-translation-block () | 1210 (defun quail-next-translation-block () |
1107 "Select the next batch of 10 translation candidates." | 1211 "Select from the next block of translations." |
1108 (interactive) | 1212 (interactive) |
1109 (if quail-current-translations | 1213 (if quail-current-translations |
1110 (let ((limit (1- (length (cdr quail-current-translations)))) | 1214 (let* ((indices (car quail-current-translations)) |
1111 (n (car quail-current-translations))) | 1215 (offset (- (car indices) (nth 1 indices)))) |
1112 (if (< (/ n 10) (/ limit 10)) | 1216 (if (>= (nth 2 indices) (length (cdr quail-current-translations))) |
1113 (progn | 1217 ;; We are already at the last block. |
1114 (quail-select-translation (min (+ n 10) limit)) | 1218 (beep) |
1115 (quail-update-translation nil)) | 1219 (setcar indices (+ (nth 2 indices) offset)) |
1116 ;; We are already at the last block. | 1220 (quail-update-current-translations) |
1117 (beep))) | 1221 (quail-update-translation nil))) |
1118 (beep))) | 1222 (beep))) |
1119 | 1223 |
1120 (defun quail-prev-translation-block () | 1224 (defun quail-prev-translation-block () |
1121 "Select the previous batch of 10 translation candidates." | 1225 "Select the previous batch of 10 translation candidates." |
1122 (interactive) | 1226 (interactive) |
1123 (if (and quail-current-translations | 1227 (if quail-current-translations |
1124 (>= (car quail-current-translations) 10)) | 1228 (let* ((indices (car quail-current-translations)) |
1125 (progn | 1229 (offset (- (car indices) (nth 1 indices)))) |
1126 (quail-select-translation (- (car quail-current-translations) 10)) | 1230 (if (= (nth 1 indices) 0) |
1127 (quail-update-translation nil)) | 1231 ;; We are already at the first block. |
1232 (beep) | |
1233 (setcar indices (1- (nth 1 indices))) | |
1234 (quail-update-current-translations) | |
1235 (if (< (+ (nth 1 indices) offset) (nth 2 indices)) | |
1236 (progn | |
1237 (setcar indices (+ (nth 1 indices) offset)) | |
1238 (quail-update-current-translations))) | |
1239 (quail-update-translation nil))) | |
1128 (beep))) | 1240 (beep))) |
1129 | |
1130 (defun quail-select-translation (n) | |
1131 "Select Nth translation in the current batch of translation candidates." | |
1132 (if (or (< n 0) (>= n (length (cdr quail-current-translations)))) | |
1133 (beep) | |
1134 (setcar quail-current-translations n) | |
1135 (setq quail-current-str (aref (cdr quail-current-translations) n)))) | |
1136 | 1241 |
1137 (defun quail-abort-translation () | 1242 (defun quail-abort-translation () |
1138 "Abort translation and delete the current Quail key sequence." | 1243 "Abort translation and delete the current Quail key sequence." |
1139 (interactive) | 1244 (interactive) |
1140 (quail-delete-region) | 1245 (quail-delete-region) |
1199 (interactive) | 1304 (interactive) |
1200 (throw 'exit nil)) | 1305 (throw 'exit nil)) |
1201 | 1306 |
1202 ;; Guidance, Completion, and Help buffer handlers. | 1307 ;; Guidance, Completion, and Help buffer handlers. |
1203 | 1308 |
1309 ;; Make a new one-line frame for Quail guidance buffer. | |
1310 (defun quail-make-guidance-frame (buf) | |
1311 (let* ((fparam (frame-parameters)) | |
1312 (top (cdr (assq 'top fparam))) | |
1313 (border (cdr (assq 'border-width fparam))) | |
1314 (internal-border (cdr (assq 'internal-border-width fparam))) | |
1315 (newtop (- top | |
1316 (frame-char-height) (* internal-border 2) (* border 2)))) | |
1317 (if (< newtop 0) | |
1318 (setq newtop (+ top (frame-pixel-height)))) | |
1319 (let* ((frame (make-frame (append '((user-position . t) (height . 1) | |
1320 (minibuffer) (menu-bar-lines . 0)) | |
1321 (cons (cons 'top newtop) fparam)))) | |
1322 (win (frame-first-window frame))) | |
1323 (set-window-buffer win buf) | |
1324 (set-window-dedicated-p win t)))) | |
1325 | |
1204 (defun quail-show-guidance-buf () | 1326 (defun quail-show-guidance-buf () |
1205 "Display a Quail guidance buffer in some window. | 1327 "Display a guidance buffer for Quail input method in some window. |
1206 Create the buffer if it does not exist yet. | 1328 Create the buffer if it does not exist yet. |
1207 The window is normally shown in a minibuffer, | 1329 The buffer is normally displayed at the echo area, |
1208 but if the selected window is a minibuffer, it is shown in | 1330 but if the current buffer is a minibuffer, it is shown in |
1209 the bottommost ordinary window." | 1331 the bottom-most ordinary window of the same frame, |
1210 | 1332 or in a newly created frame (if the selected frame has no other windows)." |
1211 (if (or (null input-method-tersely-flag) | 1333 (if (and input-method-tersely-flag |
1212 (not (eq (selected-window) (minibuffer-window)))) | 1334 (eq (selected-window) (minibuffer-window))) |
1213 (progn | 1335 ;; We don't need the guidance buffer. |
1214 ;; At first, setup a guidance buffer. | 1336 nil |
1215 (or (buffer-live-p quail-guidance-buf) | 1337 ;; At first, setup a guidance buffer. |
1216 (setq quail-guidance-buf | 1338 (or (buffer-live-p quail-guidance-buf) |
1217 (get-buffer-create " *Quail-guidance*"))) | 1339 (setq quail-guidance-buf (generate-new-buffer " *Quail-guidance*"))) |
1218 (save-excursion | 1340 (let ((title (quail-title))) |
1219 (let ((title (quail-title))) | 1341 (save-excursion |
1220 (set-buffer quail-guidance-buf) | 1342 (set-buffer quail-guidance-buf) |
1221 ;; Show the title of Quail package in the left of mode-line. | 1343 ;; To show the title of Quail package. |
1222 (setq current-input-method nil) | 1344 (setq current-input-method t |
1223 (setq current-input-method-title title) | 1345 current-input-method-title title) |
1224 (setq mode-line-format (cons '("[" current-input-method-title "]") | 1346 (erase-buffer) |
1225 default-mode-line-format)) | 1347 (or (overlayp quail-overlay) |
1226 (erase-buffer) | 1348 (progn |
1227 (or (overlayp quail-overlay) | 1349 (setq quail-overlay (make-overlay 1 1)) |
1228 (progn | 1350 (overlay-put quail-overlay 'face 'highlight))) |
1229 (setq quail-overlay (make-overlay 1 1)) | 1351 (delete-overlay quail-overlay) |
1230 (overlay-put quail-overlay 'face 'highlight))) | 1352 (set-buffer-modified-p nil))) |
1231 (delete-overlay quail-overlay) | 1353 (bury-buffer quail-guidance-buf) |
1232 (set-buffer-modified-p nil))) | 1354 |
1233 (bury-buffer quail-guidance-buf) | 1355 ;; Then, display it in an appropriate window. |
1234 | 1356 (let ((win (minibuffer-window))) |
1235 ;; Then, display it in an appropriate window. | 1357 (if (eq (selected-window) win) |
1236 (if (not (get-buffer-window quail-guidance-buf)) | 1358 ;; Since we are in minibuffer, we can't use it for guidance. |
1237 ;; Guidance buffer is not yet shown in any window. | 1359 (if (eq win (frame-root-window)) |
1238 (let ((win (minibuffer-window))) | 1360 ;; Create a frame. It is sure that we are using some |
1239 (if (eq (selected-window) win) | 1361 ;; window system. |
1240 ;; Since we are in minibuffer, we can't use it for guidance. | 1362 (quail-make-guidance-frame quail-guidance-buf) |
1241 ;; Let's find the bottom window. | 1363 ;; Find the bottom window and split it if necessary. |
1242 (let (height) | 1364 (let (height) |
1243 (setq win (window-at 0 (- (frame-height) 2))) | 1365 (setq win (window-at 0 (- (frame-height) 2))) |
1244 (setq height (window-height win)) | 1366 (setq height (window-height win)) |
1245 ;; If WIN is too tall, split it vertically and use | 1367 ;; If WIN is tall enough, split it vertically and use |
1246 ;; the lower one. | 1368 ;; the lower one. |
1247 (if (>= height 4) | 1369 (if (>= height 4) |
1248 (let ((window-min-height 2)) | 1370 (let ((window-min-height 2)) |
1249 ;; Here, `split-window' returns a lower window | 1371 ;; Here, `split-window' returns a lower window |
1250 ;; which is what we wanted. | 1372 ;; which is what we wanted. |
1251 (setq win (split-window win (- height 2))))) | 1373 (setq win (split-window win (- height 2))))) |
1252 (set-window-buffer win quail-guidance-buf) | 1374 (set-window-buffer win quail-guidance-buf) |
1253 (set-window-dedicated-p win t)) | 1375 (set-window-dedicated-p win t))) |
1254 (set-window-buffer win quail-guidance-buf)))))) | 1376 (set-window-buffer win quail-guidance-buf)) |
1377 (setq quail-guidance-win win))) | |
1255 | 1378 |
1256 ;; And, create a buffer for completion. | 1379 ;; And, create a buffer for completion. |
1257 (or (buffer-live-p quail-completion-buf) | 1380 (or (buffer-live-p quail-completion-buf) |
1258 (progn | 1381 (progn |
1259 (setq quail-completion-buf (get-buffer-create "*Quail Completions*")) | 1382 (setq quail-completion-buf (get-buffer-create "*Quail Completions*")) |
1263 (overlay-put quail-overlay 'face 'highlight)))) | 1386 (overlay-put quail-overlay 'face 'highlight)))) |
1264 (bury-buffer quail-completion-buf)) | 1387 (bury-buffer quail-completion-buf)) |
1265 | 1388 |
1266 (defun quail-hide-guidance-buf () | 1389 (defun quail-hide-guidance-buf () |
1267 "Hide the Quail guidance buffer." | 1390 "Hide the Quail guidance buffer." |
1268 (let* ((win (minibuffer-window)) | 1391 (if (buffer-live-p quail-guidance-buf) |
1269 (buf (window-buffer win))) | 1392 (let ((win-list (get-buffer-window-list quail-guidance-buf t t)) |
1270 (if (eq buf quail-guidance-buf) | 1393 win) |
1271 ;; Quail guidance buffer is at echo area. Vacate it to the | 1394 (while win-list |
1272 ;; deepest minibuffer. | 1395 (setq win (car win-list) win-list (cdr win-list)) |
1273 (set-window-buffer win (format " *Minibuf-%d*" (minibuffer-depth))) | 1396 (if (eq win (minibuffer-window)) |
1274 ;; Delete the window for guidance buffer. | 1397 ;; We are using echo area for the guidance buffer. |
1275 (if (or (null input-method-tersely-flag) | 1398 ;; Vacate it to the deepest minibuffer. |
1276 (not (eq (selected-window) (minibuffer-window)))) | 1399 (set-window-buffer win |
1277 (if (setq win (get-buffer-window quail-guidance-buf)) | 1400 (format " *Minibuf-%d*" (minibuffer-depth))) |
1278 (progn | 1401 (if (eq win (frame-root-window (window-frame win))) |
1279 (set-window-dedicated-p win nil) | 1402 (progn |
1280 (delete-window win))))))) | 1403 ;; We are using a separate frame for guidance buffer. |
1404 ;;(set-window-dedicated-p win nil) | |
1405 (delete-frame (window-frame win))) | |
1406 (set-window-dedicated-p win nil) | |
1407 (delete-window win))))))) | |
1281 | 1408 |
1282 (defun quail-update-guidance () | 1409 (defun quail-update-guidance () |
1283 "Update the Quail guidance buffer and completion buffer (if displayed now)." | 1410 "Update the Quail guidance buffer and completion buffer (if displayed now)." |
1284 ;; Update guidance buffer. | 1411 ;; Update guidance buffer. |
1285 (if (or (null input-method-tersely-flag) | 1412 (if (or (null input-method-tersely-flag) |
1343 )))))) | 1470 )))))) |
1344 | 1471 |
1345 (defun quail-show-translations () | 1472 (defun quail-show-translations () |
1346 "Show the current possible translations." | 1473 "Show the current possible translations." |
1347 (let* ((key quail-current-key) | 1474 (let* ((key quail-current-key) |
1348 (map (quail-lookup-key quail-current-key (length quail-current-key))) | 1475 (map (quail-lookup-key quail-current-key))) |
1349 (def (car map))) | 1476 (if quail-current-translations |
1350 (if (and (consp def) (not (vectorp (cdr def)))) | 1477 (quail-update-current-translations)) |
1351 (setq def (car def))) | |
1352 (save-excursion | 1478 (save-excursion |
1353 (set-buffer quail-guidance-buf) | 1479 (set-buffer quail-guidance-buf) |
1354 (erase-buffer) | 1480 (erase-buffer) |
1355 | 1481 |
1356 ;; Show the current key. | 1482 ;; Show the current key. |
1357 (insert key) | 1483 (insert key) |
1358 | 1484 |
1359 ;; Show possible following keys. | 1485 ;; Show followable keys. |
1360 (if (cdr map) | 1486 (if (cdr map) |
1361 (let ((l (cdr map))) | 1487 (let ((l (cdr map))) |
1362 (insert "[") | 1488 (insert "[") |
1363 (while l | 1489 (while l |
1364 (insert (car (car l))) | 1490 (insert (car (car l))) |
1365 (setq l (cdr l))) | 1491 (setq l (cdr l))) |
1366 (insert "]"))) | 1492 (insert "]"))) |
1367 | 1493 |
1368 ;; Show list of translations. | 1494 ;; Show list of translations. |
1369 (if (and (not (quail-deterministic)) (consp def)) | 1495 (if quail-current-translations |
1370 (let* ((idx (car def)) | 1496 (let* ((indices (car quail-current-translations)) |
1371 (translations (cdr def)) | 1497 (cur (car indices)) |
1372 (from (* (/ idx 10) 10)) | 1498 (start (nth 1 indices)) |
1373 (to (min (+ from 10) (length translations)))) | 1499 (end (nth 2 indices)) |
1374 (indent-to 10) | 1500 (idx start)) |
1375 (insert (format "(%d/%d)" | 1501 (indent-to (- quail-guidance-translations-starting-column 7)) |
1376 (1+ (/ from 10)) | 1502 (insert (format "(%02d/"(nth 3 indices)) |
1377 (1+ (/ (length translations) 10)))) | 1503 (if (nth 4 indices) |
1378 (while (< from to) | 1504 (format "%02d)" (nth 4 indices)) |
1379 ;; We show the last digit of FROM, but by changing | 1505 "??)")) |
1380 ;; 0,1,..,9 to 1,2,..,0. | 1506 (while (< idx end) |
1381 (insert (format " %d." | 1507 (insert (format " %d." (if (= (- idx start) 9) 0 |
1382 (if (= (% from 10) 9) 0 (1+ (% from 10))))) | 1508 (1+ (- idx start))))) |
1383 (let ((pos (point))) | 1509 (let ((pos (point))) |
1384 (insert (aref translations from)) | 1510 (insert (aref (cdr quail-current-translations) idx)) |
1385 (if (= idx from) | 1511 (if (= idx cur) |
1386 (move-overlay quail-overlay pos (point)))) | 1512 (move-overlay quail-overlay pos (point)))) |
1387 (setq from (1+ from))))) | 1513 (setq idx (1+ idx))))) |
1388 ))) | 1514 ))) |
1389 | 1515 |
1390 (defun quail-completion () | 1516 (defun quail-completion () |
1391 "List all completions for the current key. | 1517 "List all completions for the current key. |
1392 All possible translations of the current key and whole possible longer keys | 1518 All possible translations of the current key and whole possible longer keys |
1393 are shown." | 1519 are shown." |
1394 (interactive) | 1520 (interactive) |
1395 (let ((key quail-current-key) | 1521 (let ((key quail-current-key) |
1396 (map (quail-lookup-key quail-current-key (length quail-current-key)))) | 1522 (map (quail-lookup-key quail-current-key))) |
1397 (save-excursion | 1523 (save-excursion |
1398 (set-buffer quail-completion-buf) | 1524 (set-buffer quail-completion-buf) |
1399 (erase-buffer) | 1525 (erase-buffer) |
1400 (insert "Possible completion and corresponding translations are:\n") | 1526 (insert "Possible completion and corresponding translations are:\n") |
1401 (quail-completion-1 key map 1) | 1527 (quail-completion-1 key map 1) |
1490 "--- Key bindings (while converting) --- | 1616 "--- Key bindings (while converting) --- |
1491 key binding | 1617 key binding |
1492 --- -------\n")) | 1618 --- -------\n")) |
1493 (help-mode)))))) | 1619 (help-mode)))))) |
1494 | 1620 |
1495 | |
1496 (defun quail-help-insert-keymap-description (keymap &optional header) | 1621 (defun quail-help-insert-keymap-description (keymap &optional header) |
1497 (let (from to) | 1622 (let (from to) |
1498 (if header | 1623 (if header |
1499 (insert header)) | 1624 (insert header)) |
1500 (save-excursion | 1625 (save-excursion |
1653 (kill-buffer pkg-buf) | 1778 (kill-buffer pkg-buf) |
1654 (setq pkg-list (cdr pkg-list))) | 1779 (setq pkg-list (cdr pkg-list))) |
1655 (save-excursion | 1780 (save-excursion |
1656 (set-buffer list-buf) | 1781 (set-buffer list-buf) |
1657 (setq buffer-file-coding-system 'iso-2022-7bit) | 1782 (setq buffer-file-coding-system 'iso-2022-7bit) |
1658 (save-buffer)) | 1783 (save-buffer 0)) |
1659 (kill-buffer list-buf) | 1784 (kill-buffer list-buf) |
1660 (message "Updating %s ... done" (buffer-file-name list-buf))))))) | 1785 (message "Updating %s ... done" (buffer-file-name list-buf))))))) |
1661 ;; | 1786 ;; |
1662 (provide 'quail) | 1787 (provide 'quail) |
1663 | 1788 |