diff options
| author | Kenichi Handa | 1998-08-06 05:38:11 +0000 |
|---|---|---|
| committer | Kenichi Handa | 1998-08-06 05:38:11 +0000 |
| commit | d91eafdf6bc02c154a239b5929bf788e74f8d199 (patch) | |
| tree | 7757d9b04d5930b5f4a7cc77cd98785b5be24b4c | |
| parent | e23f810c3eae579db8b75d33dcffc75be54d1fc7 (diff) | |
| download | emacs-d91eafdf6bc02c154a239b5929bf788e74f8d199.tar.gz emacs-d91eafdf6bc02c154a239b5929bf788e74f8d199.zip | |
(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.
| -rw-r--r-- | lisp/international/quail.el | 371 |
1 files changed, 223 insertions, 148 deletions
diff --git a/lisp/international/quail.el b/lisp/international/quail.el index 911ba025b9a..98176f3d84b 100644 --- a/lisp/international/quail.el +++ b/lisp/international/quail.el | |||
| @@ -227,9 +227,12 @@ LEIM is available from the same ftp directory as Emacs.")) | |||
| 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))) |
| @@ -259,33 +262,33 @@ LEIM is available from the same ftp directory as Emacs.")) | |||
| 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) |
| @@ -301,7 +304,7 @@ This map is activated while translation region is active.") | |||
| 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) |
| @@ -320,7 +323,7 @@ region is not active.") | |||
| 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. |
| @@ -380,7 +383,7 @@ 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 |
| @@ -853,6 +856,7 @@ The returned value is a Quail map specific to KEY." | |||
| 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 |
| @@ -860,7 +864,13 @@ The returned value is a Quail map specific to KEY." | |||
| 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) |
| @@ -870,6 +880,8 @@ The returned value is a Quail map specific to KEY." | |||
| 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 |
| @@ -885,30 +897,44 @@ The returned value is a Quail map specific to KEY." | |||
| 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 |
| @@ -916,13 +942,19 @@ The returned value is a Quail map specific to KEY." | |||
| 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))) |
| @@ -930,57 +962,76 @@ The returned value is a Quail map specific to KEY." | |||
| 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 "" |
| 943 | quail-converting t | ||
| 944 | quail-translating t | 979 | quail-translating t |
| 945 | unread-command-events (cons key unread-command-events)) | 980 | quail-converting t |
| 981 | quail-conversion-str "") | ||
| 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 | 1034 | ||
| 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 | |||
| 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) |
| @@ -997,41 +1048,48 @@ The returned value is a Quail map specific to KEY." | |||
| 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 | ||
| @@ -1040,12 +1098,12 @@ The returned value is a Quail map specific to KEY." | |||
| 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) |
| @@ -1124,7 +1182,9 @@ The returned value is a Quail map specific to KEY." | |||
| 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. |
| @@ -1228,7 +1288,7 @@ sequence counting from the head." | |||
| 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 () |
| @@ -1255,6 +1315,7 @@ sequence counting from the head." | |||
| 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 () |
| @@ -1297,27 +1358,33 @@ sequence counting from the head." | |||
| 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. |
| @@ -1398,7 +1465,8 @@ or in a newly created frame (if the selected frame has no other windows)." | |||
| 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 |
| @@ -1497,7 +1565,8 @@ or in a newly created frame (if the selected frame has no other windows)." | |||
| 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 |
| @@ -1519,7 +1588,7 @@ or in a newly created frame (if the selected frame has no other windows)." | |||
| 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 '<)) |
| @@ -1530,8 +1599,8 @@ or in a newly created frame (if the selected frame has no other windows)." | |||
| 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)) |
| @@ -1545,7 +1614,7 @@ or in a newly created frame (if the selected frame has no other windows)." | |||
| 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))))) |
| @@ -1814,43 +1883,49 @@ key binding | |||
| 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" |