Mercurial > emacs
comparison lisp/international/quail.el @ 22917:00f3497854c4
(quail-translation-keymap): Declare it as
variable instead of constant. Bind all keys less than 32 to
quail-other-command. Don't bind the key meta-prefix-char and
escape.
(quail-simple-translation-keymap): Likewise.
(quail-conversion-keymap): Bind the key C-h to
quail-translation-keymap.
(quail-define-package): Fix typo in doc-string.
(quail-conversion-str): New variable.
(quail-input-method): Bind buffer-undo-list to t. Show Quail
guidance buffer if necessary.
(quail-delete-region): Move the definintion before the first
calling place.
(quail-start-translation): Handle the case the arg KEY is nil.
Bind echo-keystrokes and help-char. Initialize quail-current-str
to "". If input-method-use-echo-area is non-nil, call
read-key-sequence with appropriate PROMPT arg. Setup
last-command-event by local variable `keyseq'. Generate an event
list form quail-current-str. If input-methodd-exit-on-first-char
is non-nil, return only the first event.
(quail-start-conversion): Likewise. Initialize
quail-conversion-str to "". Generate an event list form
quail-conversion-str.
(quail-update-translation): Expect that the function given by
(quail-update-translation-function) returns a new control-flag.
Handle the case the length of quail-current-key is 1. Use
string-as-unibyte if enable-multibyte-characters is nil. Always
assures that quail-current-str is Lisp string.
(quail-self-insert-command): Use `or' instead of `unless'.
(quail-update-current-translations): Always assures that
quail-current-str is Lisp string.
(quail-next-translation-block): Update unread-command-events
correctly.
(quail-abort-translation): Set quail-current-str to nil.
(quail-conversion-delete-char): Update quail-conversion-str.
(quail-conversion-delete-tail): Likewise.
(quail-conversion-backward-delete-char): Likewise.
(quail-show-guidance-buf): Show Quail guidance buffer not in echo
area if input-method-use-echo-area is non-nil.
(quail-show-translations): Bind current-translations locally to
quail-current-translations to get this value across different
buffers. Handle the case that the length quail-current-key is 0.
(quail-translation-help): If this command is invoked repeatedly,
scroll the already shown help window. Handle the case that this
command is called while converting (not translating).
(quail-conversion-help): This function deleted and the
functionality is merged to quail-translation-help.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Thu, 06 Aug 1998 05:38:11 +0000 |
parents | 69bbe5cb5400 |
children | 72582ab5369d |
comparison
equal
deleted
inserted
replaced
22916:596fa4fbae13 | 22917:00f3497854c4 |
---|---|
225 (setq libraries (cdr libraries)))))) | 225 (setq libraries (cdr libraries)))))) |
226 (quail-select-package package-name) | 226 (quail-select-package package-name) |
227 (setq current-input-method-title (quail-title)) | 227 (setq current-input-method-title (quail-title)) |
228 (quail-activate)) | 228 (quail-activate)) |
229 | 229 |
230 (defconst quail-translation-keymap | 230 (defvar quail-translation-keymap |
231 (let ((map (make-keymap)) | 231 (let ((map (make-keymap)) |
232 (i ?\ )) | 232 (i 0)) |
233 (while (< i ?\ ) | |
234 (define-key map (char-to-string i) 'quail-other-command) | |
235 (setq i (1+ i))) | |
233 (while (< i 127) | 236 (while (< i 127) |
234 (define-key map (char-to-string i) 'quail-self-insert-command) | 237 (define-key map (char-to-string i) 'quail-self-insert-command) |
235 (setq i (1+ i))) | 238 (setq i (1+ i))) |
236 (setq i 128) | 239 (setq i 128) |
237 (while (< i 256) | 240 (while (< i 256) |
257 (define-key map "\C-h" 'quail-translation-help) | 260 (define-key map "\C-h" 'quail-translation-help) |
258 (define-key map [?\C- ] 'quail-select-current) | 261 (define-key map [?\C- ] 'quail-select-current) |
259 (define-key map [tab] 'quail-completion) | 262 (define-key map [tab] 'quail-completion) |
260 (define-key map [delete] 'quail-delete-last-char) | 263 (define-key map [delete] 'quail-delete-last-char) |
261 (define-key map [backspace] 'quail-delete-last-char) | 264 (define-key map [backspace] 'quail-delete-last-char) |
262 (let ((meta-map (make-sparse-keymap))) | |
263 (define-key map (char-to-string meta-prefix-char) meta-map) | |
264 (define-key map [escape] meta-map)) | |
265 map) | 265 map) |
266 "Keymap used processing translation in complex Quail modes. | 266 "Keymap used processing translation in complex Quail modes. |
267 Only a few especially complex input methods use this map; | 267 Only a few especially complex input methods use this map; |
268 most use `quail-simple-translation-keymap' instead. | 268 most use `quail-simple-translation-keymap' instead. |
269 This map is activated while translation region is active.") | 269 This map is activated while translation region is active.") |
270 | 270 |
271 (defconst quail-simple-translation-keymap | 271 (defvar quail-simple-translation-keymap |
272 (let ((map (make-keymap)) | 272 (let ((map (make-keymap)) |
273 (i ?\ )) | 273 (i 0)) |
274 (while (< i ?\ ) | |
275 (define-key map (char-to-string i) 'quail-other-command) | |
276 (setq i (1+ i))) | |
274 (while (< i 127) | 277 (while (< i 127) |
275 (define-key map (char-to-string i) 'quail-self-insert-command) | 278 (define-key map (char-to-string i) 'quail-self-insert-command) |
276 (setq i (1+ i))) | 279 (setq i (1+ i))) |
277 (define-key map "\177" 'quail-delete-last-char) | 280 (define-key map "\177" 'quail-delete-last-char) |
278 (define-key map [delete] 'quail-delete-last-char) | 281 (define-key map [delete] 'quail-delete-last-char) |
279 (define-key map [backspace] 'quail-delete-last-char) | 282 (define-key map [backspace] 'quail-delete-last-char) |
280 (let ((meta-map (make-sparse-keymap))) | 283 ;;(let ((meta-map (make-sparse-keymap))) |
281 (define-key map (char-to-string meta-prefix-char) meta-map) | 284 ;;(define-key map (char-to-string meta-prefix-char) meta-map) |
282 (define-key map [escape] meta-map)) | 285 ;;(define-key map [escape] meta-map)) |
283 map) | 286 map) |
284 "Keymap used while processing translation in simple Quail modes. | 287 "Keymap used while processing translation in simple Quail modes. |
285 A few especially complex input methods use `quail-translation-keymap' instead. | 288 A few especially complex input methods use `quail-translation-keymap' instead. |
286 This map is activated while translation region is active.") | 289 This map is activated while translation region is active.") |
287 | 290 |
288 (defconst quail-conversion-keymap | 291 (defvar quail-conversion-keymap |
289 (let ((map (make-keymap)) | 292 (let ((map (make-keymap)) |
290 (i ?\ )) | 293 (i ?\ )) |
291 (while (< i 127) | 294 (while (< i 127) |
292 (define-key map (char-to-string i) 'quail-self-insert-command) | 295 (define-key map (char-to-string i) 'quail-self-insert-command) |
293 (setq i (1+ i))) | 296 (setq i (1+ i))) |
299 (define-key map "\C-f" 'quail-conversion-forward-char) | 302 (define-key map "\C-f" 'quail-conversion-forward-char) |
300 (define-key map "\C-a" 'quail-conversion-beginning-of-region) | 303 (define-key map "\C-a" 'quail-conversion-beginning-of-region) |
301 (define-key map "\C-e" 'quail-conversion-end-of-region) | 304 (define-key map "\C-e" 'quail-conversion-end-of-region) |
302 (define-key map "\C-d" 'quail-conversion-delete-char) | 305 (define-key map "\C-d" 'quail-conversion-delete-char) |
303 (define-key map "\C-k" 'quail-conversion-delete-tail) | 306 (define-key map "\C-k" 'quail-conversion-delete-tail) |
304 (define-key map "\C-h" 'quail-conversion-help) | 307 (define-key map "\C-h" 'quail-translation-help) |
305 (define-key map "\177" 'quail-conversion-backward-delete-char) | 308 (define-key map "\177" 'quail-conversion-backward-delete-char) |
306 (define-key map [delete] 'quail-conversion-backward-delete-char) | 309 (define-key map [delete] 'quail-conversion-backward-delete-char) |
307 (define-key map [backspace] 'quail-conversion-backward-delete-char) | 310 (define-key map [backspace] 'quail-conversion-backward-delete-char) |
308 map) | 311 map) |
309 "Keymap used for processing conversion in Quail mode. | 312 "Keymap used for processing conversion in Quail mode. |
318 maximum-shortest overlay-plist | 321 maximum-shortest overlay-plist |
319 update-translation-function | 322 update-translation-function |
320 conversion-keys simple) | 323 conversion-keys simple) |
321 "Define NAME as a new Quail package for input LANGUAGE. | 324 "Define NAME as a new Quail package for input LANGUAGE. |
322 TITLE is a string to be displayed at mode-line to indicate this package. | 325 TITLE is a string to be displayed at mode-line to indicate this package. |
323 Optional arguments are GUIDANCE, DOCSTRING, TRANLSATION-KEYS, | 326 Optional arguments are GUIDANCE, DOCSTRING, TRANSLATION-KEYS, |
324 FORGET-LAST-SELECTION, DETERMINISTIC, KBD-TRANSLATE, SHOW-LAYOUT, | 327 FORGET-LAST-SELECTION, DETERMINISTIC, KBD-TRANSLATE, SHOW-LAYOUT, |
325 CREATE-DECODE-MAP, MAXIMUM-SHORTEST, OVERLAY-PLIST, | 328 CREATE-DECODE-MAP, MAXIMUM-SHORTEST, OVERLAY-PLIST, |
326 UPDATE-TRANSLATION-FUNCTION, CONVERSION-KEYS and SIMPLE. | 329 UPDATE-TRANSLATION-FUNCTION, CONVERSION-KEYS and SIMPLE. |
327 | 330 |
328 GUIDANCE specifies how a guidance string is shown in echo area. | 331 GUIDANCE specifies how a guidance string is shown in echo area. |
378 OVERLAY-PLIST if non-nil is a property list put on an overlay which | 381 OVERLAY-PLIST if non-nil is a property list put on an overlay which |
379 covers Quail translation region. | 382 covers Quail translation region. |
380 | 383 |
381 UPDATE-TRANSLATION-FUNCTION if non-nil is a function to call to update | 384 UPDATE-TRANSLATION-FUNCTION if non-nil is a function to call to update |
382 the current translation region accoding to a new translation data. By | 385 the current translation region accoding to a new translation data. By |
383 default, a tranlated text or a user's key sequence (if no transltion | 386 default, a translated text or a user's key sequence (if no transltion |
384 for it) is inserted. | 387 for it) is inserted. |
385 | 388 |
386 CONVERSION-KEYS specifies additional key bindings used while | 389 CONVERSION-KEYS specifies additional key bindings used while |
387 conversion region is active. It is an alist of single key character | 390 conversion region is active. It is an alist of single key character |
388 vs. corresponding command to be called. | 391 vs. corresponding command to be called. |
851 (defun quail-error (&rest args) | 854 (defun quail-error (&rest args) |
852 (signal 'quail-error (apply 'format args))) | 855 (signal 'quail-error (apply 'format args))) |
853 | 856 |
854 (defvar quail-translating nil) | 857 (defvar quail-translating nil) |
855 (defvar quail-converting nil) | 858 (defvar quail-converting nil) |
859 (defvar quail-conversion-str nil) | |
856 | 860 |
857 (defun quail-input-method (key) | 861 (defun quail-input-method (key) |
858 (if (or buffer-read-only | 862 (if (or buffer-read-only |
859 overriding-terminal-local-map | 863 overriding-terminal-local-map |
860 overriding-local-map) | 864 overriding-local-map) |
861 (list key) | 865 (list key) |
862 (quail-setup-overlays (quail-conversion-keymap)) | 866 (quail-setup-overlays (quail-conversion-keymap)) |
863 (let ((modified-p (buffer-modified-p))) | 867 (let ((modified-p (buffer-modified-p)) |
868 (buffer-undo-list t)) | |
869 (or (and quail-guidance-win | |
870 (window-live-p quail-guidance-win) | |
871 (eq (window-buffer quail-guidance-win) quail-guidance-buf) | |
872 (not input-method-use-echo-area)) | |
873 (quail-show-guidance-buf)) | |
864 (unwind-protect | 874 (unwind-protect |
865 (if (quail-conversion-keymap) | 875 (if (quail-conversion-keymap) |
866 (quail-start-conversion key) | 876 (quail-start-conversion key) |
867 (quail-start-translation key)) | 877 (quail-start-translation key)) |
868 (quail-delete-overlays) | 878 (quail-delete-overlays) |
869 (if (buffer-live-p quail-guidance-buf) | 879 (if (buffer-live-p quail-guidance-buf) |
870 (save-excursion | 880 (save-excursion |
871 (set-buffer quail-guidance-buf) | 881 (set-buffer quail-guidance-buf) |
872 (erase-buffer))) | 882 (erase-buffer))) |
883 (if input-method-use-echo-area | |
884 (quail-hide-guidance-buf)) | |
873 (set-buffer-modified-p modified-p) | 885 (set-buffer-modified-p modified-p) |
874 ;; Run this hook only when the current input method doesn't require | 886 ;; Run this hook only when the current input method doesn't require |
875 ;; conversion. When conversion is required, the conversion function | 887 ;; conversion. When conversion is required, the conversion function |
876 ;; should run this hook at a proper timing. | 888 ;; should run this hook at a proper timing. |
877 (unless (quail-conversion-keymap) | 889 (unless (quail-conversion-keymap) |
883 (if (< start end) | 895 (if (< start end) |
884 (prog1 | 896 (prog1 |
885 (string-to-list (buffer-substring start end)) | 897 (string-to-list (buffer-substring start end)) |
886 (delete-region start end))))) | 898 (delete-region start end))))) |
887 | 899 |
900 (defsubst quail-delete-region () | |
901 "Delete the text in the current translation region of Quail." | |
902 (if (overlay-start quail-overlay) | |
903 (delete-region (overlay-start quail-overlay) | |
904 (overlay-end quail-overlay)))) | |
905 | |
888 (defun quail-start-translation (key) | 906 (defun quail-start-translation (key) |
889 "Start translation of the typed character KEY by the current Quail package." | 907 "Start translation of the typed character KEY by the current Quail package." |
890 ;; Check the possibility of translating KEY. | 908 ;; Check the possibility of translating KEY. |
891 (if (and (integerp key) | 909 ;; If KEY is nil, we can anyway start translation. |
892 (assq (if (quail-kbd-translate) (quail-keyboard-translate key) key) | 910 (if (or (and (integerp key) |
893 (cdr (quail-map)))) | 911 (assq (if (quail-kbd-translate) |
912 (quail-keyboard-translate key) key) | |
913 (cdr (quail-map)))) | |
914 (null key)) | |
894 ;; Ok, we can start translation. | 915 ;; Ok, we can start translation. |
895 (let* ((translation-keymap (quail-translation-keymap)) | 916 (let* ((echo-keystrokes 0) |
896 (overriding-terminal-local-map translation-keymap) | 917 (help-char nil) |
918 (overriding-terminal-local-map (quail-translation-keymap)) | |
897 (generated-events nil) | 919 (generated-events nil) |
898 (input-method-function nil)) | 920 (input-method-function nil)) |
899 (setq quail-current-key "" | 921 (setq quail-current-key "" |
900 quail-current-str nil | 922 quail-current-str "" |
901 quail-translating t | 923 quail-translating t) |
902 unread-command-events (cons key unread-command-events)) | 924 (if key |
925 (setq unread-command-events (cons key unread-command-events))) | |
903 (while quail-translating | 926 (while quail-translating |
904 (let* ((echo-keystrokes 0) | 927 (let* ((keyseq (read-key-sequence |
905 (help-char nil) | 928 (and input-method-use-echo-area |
906 (keyseq (read-key-sequence nil)) | 929 (concat input-method-previous-message |
907 (events (this-single-command-raw-keys)) | 930 quail-current-str)))) |
908 (cmd (lookup-key translation-keymap keyseq))) | 931 (cmd (lookup-key (quail-translation-keymap) keyseq))) |
909 (if (commandp cmd) | 932 (if (if key |
933 (and (commandp cmd) (not (eq cmd 'quail-other-command))) | |
934 (eq cmd 'quail-self-insert-command)) | |
910 (progn | 935 (progn |
911 (setq last-command-event (aref events (1- (length events))) | 936 (setq key t) |
937 (setq last-command-event (aref keyseq (1- (length keyseq))) | |
912 last-command this-command | 938 last-command this-command |
913 this-command cmd) | 939 this-command cmd) |
914 (condition-case err | 940 (condition-case err |
915 (call-interactively cmd) | 941 (call-interactively cmd) |
916 (quail-error (message "%s" (cdr err)) (beep)))) | 942 (quail-error (message "%s" (cdr err)) (beep)))) |
917 ;; KEYSEQ is not defined in the translation keymap. | 943 ;; KEYSEQ is not defined in the translation keymap. |
918 ;; Let's return the event(s) to the caller. | 944 ;; Let's return the event(s) to the caller. |
919 (setq generated-events (string-to-list events) | 945 (setq generated-events |
920 quail-translating nil)))) | 946 (string-to-list (this-single-command-raw-keys))) |
921 (if (overlay-start quail-overlay) | 947 (setq quail-translating nil)))) |
948 (quail-delete-region) | |
949 (if (and quail-current-str (> (length quail-current-str) 0)) | |
922 (setq generated-events | 950 (setq generated-events |
923 (append (quail-overlay-region-events quail-overlay) | 951 (if (stringp quail-current-str) |
924 generated-events))) | 952 (append (string-to-list quail-current-str) |
925 generated-events) | 953 generated-events) |
954 (cons quail-current-str generated-events)))) | |
955 (if (and input-method-exit-on-first-char generated-events) | |
956 (list (car generated-events)) | |
957 generated-events)) | |
926 | 958 |
927 ;; Since KEY doesn't start any translation, just return it. | 959 ;; Since KEY doesn't start any translation, just return it. |
928 (list key))) | 960 (list key))) |
929 | 961 |
930 (defun quail-start-conversion (key) | 962 (defun quail-start-conversion (key) |
931 "Start conversion of the typed character KEY by the current Quail package." | 963 "Start conversion of the typed character KEY by the current Quail package." |
932 ;; Check the possibility of translating KEY. | 964 ;; Check the possibility of translating KEY. |
933 (if (and (integerp key) | 965 ;; If KEY is nil, we can anyway start translation. |
934 (assq (if (quail-kbd-translate) (quail-keyboard-translate key) key) | 966 (if (or (and (integerp key) |
935 (cdr (quail-map)))) | 967 (assq (if (quail-kbd-translate) |
968 (quail-keyboard-translate key) key) | |
969 (cdr (quail-map)))) | |
970 (null key)) | |
936 ;; Ok, we can start translation and conversion. | 971 ;; Ok, we can start translation and conversion. |
937 (let* ((conversion-keymap (quail-conversion-keymap)) | 972 (let* ((echo-keystrokes 0) |
938 (overriding-terminal-local-map conversion-keymap) | 973 (help-char nil) |
974 (overriding-terminal-local-map (quail-conversion-keymap)) | |
939 (generated-events nil) | 975 (generated-events nil) |
940 (input-method-function nil)) | 976 (input-method-function nil)) |
941 (setq quail-current-key "" | 977 (setq quail-current-key "" |
942 quail-current-str nil | 978 quail-current-str "" |
979 quail-translating t | |
943 quail-converting t | 980 quail-converting t |
944 quail-translating t | 981 quail-conversion-str "") |
945 unread-command-events (cons key unread-command-events)) | 982 (if key |
983 (setq unread-command-events (cons key unread-command-events))) | |
946 (while quail-converting | 984 (while quail-converting |
947 (or quail-translating | 985 (or quail-translating |
948 (progn | 986 (progn |
949 (setq quail-current-key "" | 987 (setq quail-current-key "" |
950 quail-current-str nil | 988 quail-current-str "" |
951 quail-translating t) | 989 quail-translating t) |
952 (quail-setup-overlays nil))) | 990 (quail-setup-overlays nil))) |
953 (let* ((echo-keystrokes 0) | 991 (let* ((keyseq (read-key-sequence |
954 (keyseq (read-key-sequence nil)) | 992 (and input-method-use-echo-area |
955 (events (this-single-command-raw-keys)) | 993 (concat input-method-previous-message |
956 (cmd (lookup-key conversion-keymap keyseq))) | 994 quail-conversion-str |
957 (if (commandp cmd) | 995 quail-current-str)))) |
996 (cmd (lookup-key (quail-conversion-keymap) keyseq))) | |
997 (if (if key (commandp cmd) (eq cmd 'quail-self-insert-command)) | |
958 (progn | 998 (progn |
959 (setq last-command-event (aref events (1- (length events))) | 999 (setq key t) |
1000 (setq last-command-event (aref keyseq (1- (length keyseq))) | |
960 last-command this-command | 1001 last-command this-command |
961 this-command cmd) | 1002 this-command cmd) |
962 (condition-case err | 1003 (condition-case err |
963 (call-interactively cmd) | 1004 (call-interactively cmd) |
964 (quail-error (message "%s" (cdr err)) (beep)))) | 1005 (quail-error (message "%s" (cdr err)) (beep))) |
1006 (or quail-translating | |
1007 (progn | |
1008 (if quail-current-str | |
1009 (setq quail-conversion-str | |
1010 (concat quail-conversion-str | |
1011 (if (stringp quail-current-str) | |
1012 quail-current-str | |
1013 (char-to-string quail-current-str))))) | |
1014 (if input-method-exit-on-first-char | |
1015 (setq quail-converting nil))))) | |
965 ;; KEYSEQ is not defined in the conversion keymap. | 1016 ;; KEYSEQ is not defined in the conversion keymap. |
966 ;; Let's return the event(s) to the caller. | 1017 ;; Let's return the event(s) to the caller. |
967 (setq generated-events (string-to-list events) | 1018 (setq generated-events |
968 quail-converting nil)))) | 1019 (string-to-list (this-single-command-raw-keys))) |
1020 (setq quail-converting nil)))) | |
969 (if (overlay-start quail-conv-overlay) | 1021 (if (overlay-start quail-conv-overlay) |
1022 (delete-region (overlay-start quail-conv-overlay) | |
1023 (overlay-end quail-conv-overlay))) | |
1024 (if (> (length quail-conversion-str) 0) | |
970 (setq generated-events | 1025 (setq generated-events |
971 (append (quail-overlay-region-events quail-conv-overlay) | 1026 (append (string-to-list quail-conversion-str) |
972 generated-events))) | 1027 generated-events))) |
973 generated-events) | 1028 (if (and input-method-exit-on-first-char generated-events) |
1029 (list (car generated-events)) | |
1030 generated-events)) | |
974 | 1031 |
975 ;; Since KEY doesn't start any translation, just return it. | 1032 ;; Since KEY doesn't start any translation, just return it. |
976 (list key))) | 1033 (list key))) |
977 | |
978 (defsubst quail-delete-region () | |
979 "Delete the text in the current translation region of Quail." | |
980 (if (overlay-start quail-overlay) | |
981 (delete-region (overlay-start quail-overlay) | |
982 (overlay-end quail-overlay)))) | |
983 | 1034 |
984 (defun quail-terminate-translation () | 1035 (defun quail-terminate-translation () |
985 "Terminate the translation of the current key." | 1036 "Terminate the translation of the current key." |
986 (setq quail-translating nil) | 1037 (setq quail-translating nil) |
987 (if (buffer-live-p quail-guidance-buf) | 1038 (if (buffer-live-p quail-guidance-buf) |
995 (quail-terminate-translation)) | 1046 (quail-terminate-translation)) |
996 | 1047 |
997 ;; Update the current translation status according to CONTROL-FLAG. | 1048 ;; Update the current translation status according to CONTROL-FLAG. |
998 ;; If CONTROL-FLAG is integer value, it is the number of keys in the | 1049 ;; If CONTROL-FLAG is integer value, it is the number of keys in the |
999 ;; head quail-current-key which can be translated. The remaining keys | 1050 ;; head quail-current-key which can be translated. The remaining keys |
1000 ;; are put back to unread-input-method-events to be handled again. | 1051 ;; are put back to unread-command-events to be handled again. If |
1001 ;; If CONTROL-FLAG is t, terminate the translation for the whole keys | 1052 ;; CONTROL-FLAG is t, terminate the translation for the whole keys in |
1002 ;; in quail-current-key. | 1053 ;; quail-current-key. If CONTROL-FLAG is nil, proceed the translation |
1003 ;; If CONTROL-FLAG is nil, proceed the translation with more keys. | 1054 ;; with more keys. |
1004 | 1055 |
1005 (defun quail-update-translation (control-flag) | 1056 (defun quail-update-translation (control-flag) |
1006 (quail-delete-region) | |
1007 (let ((func (quail-update-translation-function))) | 1057 (let ((func (quail-update-translation-function))) |
1008 (if func | 1058 (if func |
1009 (funcall func control-flag) | 1059 (setq control-flag (funcall func control-flag)) |
1010 (if (numberp control-flag) | 1060 (if (numberp control-flag) |
1011 (let ((len (length quail-current-key))) | 1061 (let ((len (length quail-current-key))) |
1012 (while (> len control-flag) | 1062 (if (= len 1) |
1013 (setq len (1- len)) | 1063 (setq control-flag t |
1014 (setq unread-input-method-events | 1064 quail-current-str quail-current-key) |
1015 (cons (aref quail-current-key len) | 1065 (while (> len control-flag) |
1016 unread-input-method-events))) | 1066 (setq len (1- len)) |
1017 ;; Insert the translated sequence. | 1067 (setq unread-command-events |
1018 ;; It is a string containing multibyte characters. | 1068 (cons (aref quail-current-key len) |
1019 ;; If enable-multibyte-characters, just insert it. | 1069 unread-command-events))) |
1020 (if enable-multibyte-characters | 1070 (if quail-current-str |
1021 (insert (or quail-current-str | 1071 (if input-method-exit-on-first-char |
1022 (substring quail-current-key 0 len))) | 1072 (setq control-flag t)) |
1023 ;; Otherwise, in case the user is using a single-byte | 1073 (setq quail-current-str |
1024 ;; extended-ASCII character set, | 1074 (substring quail-current-key 0 len))) |
1025 ;; try inserting the translated character. | 1075 (or enable-multibyte-characters |
1026 (let ((char (or quail-current-str | 1076 (progn |
1027 (substring quail-current-key 0 len)))) | 1077 (if (not (stringp quail-current-str)) |
1028 (if (stringp char) | 1078 (setq quail-current-str |
1029 (setq char (sref char 0))) | 1079 (char-to-string quail-current-str))) |
1030 (if (= (length (split-char char)) 2) | 1080 (setq quail-current-str |
1031 (insert-char (logand char 255) 1) | 1081 (string-as-unibyte quail-current-str)))))) |
1032 (quail-error "Three-byte characters require enabling multibyte characters"))))) | 1082 (if quail-current-str |
1033 (insert (or quail-current-str quail-current-key))))) | 1083 (if input-method-exit-on-first-char |
1084 (setq control-flag t)) | |
1085 (setq quail-current-str quail-current-key)))) | |
1086 (if (not input-method-use-echo-area) | |
1087 (progn | |
1088 (quail-delete-region) | |
1089 (insert quail-current-str)))) | |
1034 (quail-update-guidance) | 1090 (quail-update-guidance) |
1091 (or (stringp quail-current-str) | |
1092 (setq quail-current-str (char-to-string quail-current-str))) | |
1035 (if control-flag | 1093 (if control-flag |
1036 (quail-terminate-translation))) | 1094 (quail-terminate-translation))) |
1037 | 1095 |
1038 (defun quail-self-insert-command () | 1096 (defun quail-self-insert-command () |
1039 "Add the typed character to the key for translation." | 1097 "Add the typed character to the key for translation." |
1040 (interactive "*") | 1098 (interactive "*") |
1041 (setq quail-current-key | 1099 (setq quail-current-key |
1042 (concat quail-current-key (char-to-string last-command-event))) | 1100 (concat quail-current-key (char-to-string last-command-event))) |
1043 (unless (catch 'quail-tag | 1101 (or (catch 'quail-tag |
1044 (quail-update-translation (quail-translate-key)) | 1102 (quail-update-translation (quail-translate-key)) |
1045 t) | 1103 t) |
1046 ;; If someone throws for `quail-tag' by value nil, we exit from | 1104 ;; If someone throws for `quail-tag' by value nil, we exit from |
1047 ;; translation mode. | 1105 ;; translation mode. |
1048 (setq quail-translating nil))) | 1106 (setq quail-translating nil))) |
1049 | 1107 |
1050 ;; Return the actual definition part of Quail map MAP. | 1108 ;; Return the actual definition part of Quail map MAP. |
1051 (defun quail-map-definition (map) | 1109 (defun quail-map-definition (map) |
1052 (let ((def (car map))) | 1110 (let ((def (car map))) |
1053 (if (and (consp def) (not (vectorp (cdr def)))) | 1111 (if (and (consp def) (not (vectorp (cdr def)))) |
1122 (if relative-index | 1180 (if relative-index |
1123 (if (>= (+ start relative-index) end) | 1181 (if (>= (+ start relative-index) end) |
1124 (setcar indices end) | 1182 (setcar indices end) |
1125 (setcar indices (+ start relative-index)))) | 1183 (setcar indices (+ start relative-index)))) |
1126 (setq quail-current-str | 1184 (setq quail-current-str |
1127 (aref (cdr quail-current-translations) (car indices))))) | 1185 (aref (cdr quail-current-translations) (car indices))) |
1186 (or (stringp quail-current-str) | |
1187 (setq quail-current-str (char-to-string quail-current-str))))) | |
1128 | 1188 |
1129 (defun quail-translate-key () | 1189 (defun quail-translate-key () |
1130 "Translate the current key sequence according to the current Quail map. | 1190 "Translate the current key sequence according to the current Quail map. |
1131 Return t if we can terminate the translation. | 1191 Return t if we can terminate the translation. |
1132 Return nil if the current key sequence may be followed by more keys. | 1192 Return nil if the current key sequence may be followed by more keys. |
1226 (beep) | 1286 (beep) |
1227 (setcar indices (+ (nth 2 indices) offset)) | 1287 (setcar indices (+ (nth 2 indices) offset)) |
1228 (quail-update-current-translations) | 1288 (quail-update-current-translations) |
1229 (quail-update-translation nil))) | 1289 (quail-update-translation nil))) |
1230 (setq unread-command-events | 1290 (setq unread-command-events |
1231 (append (string-to-list unread-command-events))) | 1291 (cons last-command-event unread-command-events)) |
1232 (quail-terminate-translation))) | 1292 (quail-terminate-translation))) |
1233 | 1293 |
1234 (defun quail-prev-translation-block () | 1294 (defun quail-prev-translation-block () |
1235 "Select the previous batch of 10 translation candidates." | 1295 "Select the previous batch of 10 translation candidates." |
1236 (interactive) | 1296 (interactive) |
1253 | 1313 |
1254 (defun quail-abort-translation () | 1314 (defun quail-abort-translation () |
1255 "Abort translation and delete the current Quail key sequence." | 1315 "Abort translation and delete the current Quail key sequence." |
1256 (interactive) | 1316 (interactive) |
1257 (quail-delete-region) | 1317 (quail-delete-region) |
1318 (setq quail-current-str nil) | |
1258 (quail-terminate-translation)) | 1319 (quail-terminate-translation)) |
1259 | 1320 |
1260 (defun quail-delete-last-char () | 1321 (defun quail-delete-last-char () |
1261 "Delete the last input character from the current Quail key sequence." | 1322 "Delete the last input character from the current Quail key sequence." |
1262 (interactive) | 1323 (interactive) |
1295 (interactive) | 1356 (interactive) |
1296 (setq quail-translating nil) | 1357 (setq quail-translating nil) |
1297 (if (>= (point) (overlay-end quail-conv-overlay)) | 1358 (if (>= (point) (overlay-end quail-conv-overlay)) |
1298 (quail-error "End of conversion region")) | 1359 (quail-error "End of conversion region")) |
1299 (delete-char 1) | 1360 (delete-char 1) |
1300 (if (= (overlay-start quail-conv-overlay) | 1361 (let ((start (overlay-start quail-conv-overlay)) |
1301 (overlay-end quail-conv-overlay)) | 1362 (end (overlay-end quail-conv-overlay))) |
1302 (setq quail-converting nil))) | 1363 (setq quail-conversion-str (buffer-substring start end)) |
1364 (if (= start end) | |
1365 (setq quail-converting nil)))) | |
1303 | 1366 |
1304 (defun quail-conversion-delete-tail () | 1367 (defun quail-conversion-delete-tail () |
1305 (interactive) | 1368 (interactive) |
1306 (if (>= (point) (overlay-end quail-conv-overlay)) | 1369 (if (>= (point) (overlay-end quail-conv-overlay)) |
1307 (quail-error "End of conversion region")) | 1370 (quail-error "End of conversion region")) |
1308 (delete-region (point) (overlay-end quail-conv-overlay)) | 1371 (delete-region (point) (overlay-end quail-conv-overlay)) |
1309 (if (= (overlay-start quail-conv-overlay) | 1372 (let ((start (overlay-start quail-conv-overlay)) |
1310 (overlay-end quail-conv-overlay)) | 1373 (end (overlay-end quail-conv-overlay))) |
1311 (setq quail-converting nil))) | 1374 (setq quail-conversion-str (buffer-substring start end)) |
1375 (if (= start end) | |
1376 (setq quail-converting nil)))) | |
1312 | 1377 |
1313 (defun quail-conversion-backward-delete-char () | 1378 (defun quail-conversion-backward-delete-char () |
1314 (interactive) | 1379 (interactive) |
1315 (if (<= (point) (overlay-start quail-conv-overlay)) | 1380 (if (<= (point) (overlay-start quail-conv-overlay)) |
1316 (quail-error "Beginning of conversion region")) | 1381 (quail-error "Beginning of conversion region")) |
1317 (delete-char -1) | 1382 (delete-char -1) |
1318 (if (= (overlay-start quail-conv-overlay) | 1383 (let ((start (overlay-start quail-conv-overlay)) |
1319 (overlay-end quail-conv-overlay)) | 1384 (end (overlay-end quail-conv-overlay))) |
1320 (setq quail-converting nil))) | 1385 (setq quail-conversion-str (buffer-substring start end)) |
1386 (if (= start end) | |
1387 (setq quail-converting nil)))) | |
1321 | 1388 |
1322 (defun quail-do-conversion (func &rest args) | 1389 (defun quail-do-conversion (func &rest args) |
1323 "Call FUNC to convert text in the current conversion region of Quail. | 1390 "Call FUNC to convert text in the current conversion region of Quail. |
1324 Remaining args are for FUNC." | 1391 Remaining args are for FUNC." |
1325 (delete-overlay quail-overlay) | 1392 (delete-overlay quail-overlay) |
1396 (set-buffer-modified-p nil))) | 1463 (set-buffer-modified-p nil))) |
1397 (bury-buffer quail-guidance-buf) | 1464 (bury-buffer quail-guidance-buf) |
1398 | 1465 |
1399 ;; Then, display it in an appropriate window. | 1466 ;; Then, display it in an appropriate window. |
1400 (let ((win (minibuffer-window))) | 1467 (let ((win (minibuffer-window))) |
1401 (if (eq (selected-window) win) | 1468 (if (or (eq (selected-window) win) |
1469 input-method-use-echo-area) | |
1402 ;; Since we are in minibuffer, we can't use it for guidance. | 1470 ;; Since we are in minibuffer, we can't use it for guidance. |
1403 (if (eq win (frame-root-window)) | 1471 (if (eq win (frame-root-window)) |
1404 ;; Create a frame. It is sure that we are using some | 1472 ;; Create a frame. It is sure that we are using some |
1405 ;; window system. | 1473 ;; window system. |
1406 (quail-make-guidance-frame quail-guidance-buf) | 1474 (quail-make-guidance-frame quail-guidance-buf) |
1495 )))))) | 1563 )))))) |
1496 | 1564 |
1497 (defun quail-show-translations () | 1565 (defun quail-show-translations () |
1498 "Show the current possible translations." | 1566 "Show the current possible translations." |
1499 (let* ((key quail-current-key) | 1567 (let* ((key quail-current-key) |
1500 (map (quail-lookup-key quail-current-key))) | 1568 (map (quail-lookup-key quail-current-key)) |
1569 (current-translations quail-current-translations)) | |
1501 (if quail-current-translations | 1570 (if quail-current-translations |
1502 (quail-update-current-translations)) | 1571 (quail-update-current-translations)) |
1503 (save-excursion | 1572 (save-excursion |
1504 (set-buffer quail-guidance-buf) | 1573 (set-buffer quail-guidance-buf) |
1505 (erase-buffer) | 1574 (erase-buffer) |
1517 (insert (or prompt-key (aref key i))) | 1586 (insert (or prompt-key (aref key i))) |
1518 (setq i (1+ i)))) | 1587 (setq i (1+ i)))) |
1519 (insert key))) | 1588 (insert key))) |
1520 | 1589 |
1521 ;; Show followable keys. | 1590 ;; Show followable keys. |
1522 (if (cdr map) | 1591 (if (and (> (length key) 0) (cdr map)) |
1523 (let ((keys (mapcar (function (lambda (x) (car x))) | 1592 (let ((keys (mapcar (function (lambda (x) (car x))) |
1524 (cdr map)))) | 1593 (cdr map)))) |
1525 (setq keys (sort keys '<)) | 1594 (setq keys (sort keys '<)) |
1526 (insert "[") | 1595 (insert "[") |
1527 (while keys | 1596 (while keys |
1528 (insert (car keys)) | 1597 (insert (car keys)) |
1529 (setq keys (cdr keys))) | 1598 (setq keys (cdr keys))) |
1530 (insert "]"))) | 1599 (insert "]"))) |
1531 | 1600 |
1532 ;; Show list of translations. | 1601 ;; Show list of translations. |
1533 (if quail-current-translations | 1602 (if current-translations |
1534 (let* ((indices (car quail-current-translations)) | 1603 (let* ((indices (car current-translations)) |
1535 (cur (car indices)) | 1604 (cur (car indices)) |
1536 (start (nth 1 indices)) | 1605 (start (nth 1 indices)) |
1537 (end (nth 2 indices)) | 1606 (end (nth 2 indices)) |
1538 (idx start)) | 1607 (idx start)) |
1539 (indent-to (- quail-guidance-translations-starting-column 7)) | 1608 (indent-to (- quail-guidance-translations-starting-column 7)) |
1543 "??)")) | 1612 "??)")) |
1544 (while (< idx end) | 1613 (while (< idx end) |
1545 (insert (format " %d." (if (= (- idx start) 9) 0 | 1614 (insert (format " %d." (if (= (- idx start) 9) 0 |
1546 (1+ (- idx start))))) | 1615 (1+ (- idx start))))) |
1547 (let ((pos (point))) | 1616 (let ((pos (point))) |
1548 (insert (aref (cdr quail-current-translations) idx)) | 1617 (insert (aref (cdr current-translations) idx)) |
1549 (if (= idx cur) | 1618 (if (= idx cur) |
1550 (move-overlay quail-overlay pos (point)))) | 1619 (move-overlay quail-overlay pos (point)))) |
1551 (setq idx (1+ idx))))) | 1620 (setq idx (1+ idx))))) |
1552 ))) | 1621 ))) |
1553 | 1622 |
1812 (self-insert-command 1))))))) | 1881 (self-insert-command 1))))))) |
1813 (setq i (1+ i)))) | 1882 (setq i (1+ i)))) |
1814 (newline)) | 1883 (newline)) |
1815 | 1884 |
1816 (defun quail-translation-help () | 1885 (defun quail-translation-help () |
1817 "Show help message while translating in Quail mode." | 1886 "Show help message while translating in Quail input method." |
1818 (interactive) | 1887 (interactive) |
1819 (let ((package quail-current-package) | 1888 (if (not (eq this-command last-command)) |
1820 (current-key quail-current-key)) | 1889 (let (state-msg keymap) |
1821 (with-output-to-temp-buffer "*Quail-Help*" | 1890 (if (and quail-converting (= (length quail-current-key) 0)) |
1822 (save-excursion | 1891 (setq state-msg |
1823 (set-buffer standard-output) | 1892 (format "Converting string %S by input method %S.\n" |
1824 (let ((quail-current-package package)) | 1893 quail-conversion-str (quail-name)) |
1825 (princ "You are translating the key sequence ") | 1894 keymap (quail-conversion-keymap)) |
1826 (prin1 quail-current-key) | 1895 (setq state-msg |
1827 (princ" in Quail mode.\n") | 1896 (format "Translating key sequence %S by input method %S.\n" |
1828 (quail-help-insert-keymap-description | 1897 quail-current-key (quail-name)) |
1829 (quail-translation-keymap) | 1898 keymap (quail-translation-keymap))) |
1830 "----------------------- | 1899 (with-output-to-temp-buffer "*Quail-Help*" |
1900 (save-excursion | |
1901 (set-buffer standard-output) | |
1902 (insert state-msg) | |
1903 (quail-help-insert-keymap-description | |
1904 keymap | |
1905 "----------------------- | |
1831 key binding | 1906 key binding |
1832 --- -------\n")) | 1907 --- -------\n") |
1833 (help-mode))))) | 1908 (help-mode))))) |
1834 | 1909 (let (scroll-help) |
1835 (defun quail-conversion-help () | 1910 (save-selected-window |
1836 "Show help message while converting in Quail mode." | 1911 (select-window (get-buffer-window "*Quail-Help*")) |
1837 (interactive) | 1912 (if (eq this-command last-command) |
1838 (let ((package quail-current-package) | 1913 (if (< (window-end) (point-max)) |
1839 (str (buffer-substring (overlay-start quail-conv-overlay) | 1914 (scroll-up) |
1840 (overlay-end quail-conv-overlay)))) | 1915 (if (> (window-start) (point-min)) |
1841 (with-output-to-temp-buffer "*Quail-Help*" | 1916 (set-window-start (selected-window) (point-min))))) |
1842 (save-excursion | 1917 (setq scroll-help |
1843 (set-buffer standard-output) | 1918 (if (< (window-end (selected-window) 'up-to-date) (point-max)) |
1844 (let ((quail-current-package package)) | 1919 "Type \\[quail-translation-help] to scroll up the help" |
1845 (princ "You are converting the string ") | 1920 (if (> (window-start) (point-min)) |
1846 (prin1 str) | 1921 "Type \\[quail-translation-help] to see the head of help")))) |
1847 (princ " in Quail mode.\n") | 1922 (if scroll-help |
1848 (quail-help-insert-keymap-description | 1923 (progn |
1849 (quail-conversion-keymap) | 1924 (message "%s" (substitute-command-keys scroll-help)) |
1850 "----------------------- | 1925 (sit-for 1) |
1851 key binding | 1926 (message nil) |
1852 --- -------\n")) | 1927 (quail-update-guidance) |
1853 (help-mode))))) | 1928 )))) |
1854 | 1929 |
1855 | 1930 |
1856 (defvar quail-directory-name "quail" | 1931 (defvar quail-directory-name "quail" |
1857 "Name of Quail directory which cotains Quail packages. | 1932 "Name of Quail directory which cotains Quail packages. |
1858 This is a sub-directory of LEIM directory.") | 1933 This is a sub-directory of LEIM directory.") |