aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenichi Handa1998-07-16 00:14:44 +0000
committerKenichi Handa1998-07-16 00:14:44 +0000
commitb58fc490b4085519055c3daae372bb43ec5889a9 (patch)
tree78eab7dc545f3c339caa90547194d34673575c48
parent9afa6c35753dd8af29d626f1a41d3739e98f2280 (diff)
downloademacs-b58fc490b4085519055c3daae372bb43ec5889a9.tar.gz
emacs-b58fc490b4085519055c3daae372bb43ec5889a9.zip
(quail-mode): This variable deleted.
(quail-current-key): Make it buffer local. (quail-current-str, quail-current-translations): Likewise. (quail-reset-conversion-region): This variable deleted. (quail-use-package): Call quail-activate at the tail. (quail-translation-keymap, quail-simple-translation-keymap): Key bindings for quail-execute-non-quail-command deleted. (quail-conversion-keymap): Likewise. Add key bindings for quail-self-insert-command. (quail-delete-overlays): Chekc overlay-start for overlays before deleting them. (quail-mode): This function deleted. (quail-inactivate, quail-activate): New functions. (quail-saved-current-map, quail-saved-current-buffer): These variables deleted. (quail-toggle-mode-temporarily, quail-execute-non-quail-command): These functions deleted. (quail-exit-conversion-mode, quail-prefix-arg): These variables deleted. (quail-error): New error condition. (quail-error): New function. (quail-translating, quail-converting): New variables. (quail-input-method, quail-overlay-region-events): New function. (quail-start-translation): Completely re-written. (quail-start-translation-in-conversion-mode): This function deleted. (quail-start-conversion): New function. (quail-terminate-translation): Just set quail-translating to nil. (quail-update-translation): Put some events back to unread-input-method-events instead of unread-command-events. Call quail-error instead of error. (quail-self-insert-command): Adjusted for the change of quail-start-translation. (quail-next-translation): Don't call quail-execute-non-quail-command, instead, put an event back of unread-command-events. (quail-prev-translation, quail-next-translation-block, quail-prev-translation-block): Likewize. (quail-conversion-backward-char): Call quail-error instead of error. Set quail-translating to nil. (quail-conversion-forward-char): Likewize. (quail-conversion-delete-char): Call quail-error instead of error. If conversion region gets vacant, set quail-converting to nil. (quail-conversion-backward-delete-char): Likewize. (quail-no-conversion): Just set quail-converting to nil. (quail-mouse-choose-completion): Call quai-error instead of error. (quail-choose-completion-string): Likewize. (quail-help): Don't handle quail-mode-map.
-rw-r--r--lisp/international/quail.el474
1 files changed, 180 insertions, 294 deletions
diff --git a/lisp/international/quail.el b/lisp/international/quail.el
index 995ce40fd84..cd830cca8bc 100644
--- a/lisp/international/quail.el
+++ b/lisp/international/quail.el
@@ -68,11 +68,6 @@ See the documentation of `quail-package-alist' for the format.")
68(defvar quail-guidance-win nil) 68(defvar quail-guidance-win nil)
69(make-variable-buffer-local 'quail-guidance-win) 69(make-variable-buffer-local 'quail-guidance-win)
70 70
71(defvar quail-mode nil
72 "Non-nil if in Quail minor mode.")
73(make-variable-buffer-local 'quail-mode)
74(put 'quail-mode 'permanent-local t)
75
76(defvar quail-overlay nil 71(defvar quail-overlay nil
77 "Overlay which covers the current translation region of Quail.") 72 "Overlay which covers the current translation region of Quail.")
78(make-variable-buffer-local 'quail-overlay) 73(make-variable-buffer-local 'quail-overlay)
@@ -83,9 +78,11 @@ See the documentation of `quail-package-alist' for the format.")
83 78
84(defvar quail-current-key nil 79(defvar quail-current-key nil
85 "Current key for translation in Quail mode.") 80 "Current key for translation in Quail mode.")
81(make-variable-buffer-local 'quail-current-key)
86 82
87(defvar quail-current-str nil 83(defvar quail-current-str nil
88 "Currently selected translation of the current key.") 84 "Currently selected translation of the current key.")
85(make-variable-buffer-local 'quail-current-str)
89 86
90(defvar quail-current-translations nil 87(defvar quail-current-translations nil
91 "Cons of indices and vector of possible translations of the current key. 88 "Cons of indices and vector of possible translations of the current key.
@@ -94,6 +91,7 @@ CURRENT is an index of the current translation,
94START and END are indices of the start and end of the current block, 91START and END are indices of the start and end of the current block,
95BLOCK is the current block index, 92BLOCK is the current block index,
96BLOCKS is a number of blocks of translation.") 93BLOCKS is a number of blocks of translation.")
94(make-variable-buffer-local 'quail-current-translations)
97 95
98(defvar quail-current-data nil 96(defvar quail-current-data nil
99 "Any Lisp object holding information of current translation status. 97 "Any Lisp object holding information of current translation status.
@@ -103,11 +101,6 @@ for translating the longer key sequence, this variable is set
103to that Lisp object.") 101to that Lisp object.")
104(make-variable-buffer-local 'quail-current-data) 102(make-variable-buffer-local 'quail-current-data)
105 103
106;; A flag to control conversion region. Normally nil, but if set to
107;; t, it means we must start the new conversion region if new key to
108;; be translated is input.
109(defvar quail-reset-conversion-region nil)
110
111;; Quail package handlers. 104;; Quail package handlers.
112 105
113(defvar quail-package-alist nil 106(defvar quail-package-alist nil
@@ -232,49 +225,11 @@ LEIM is available from the same ftp directory as Emacs."))
232 (setq libraries (cdr libraries)))))) 225 (setq libraries (cdr libraries))))))
233 (quail-select-package package-name) 226 (quail-select-package package-name)
234 (setq current-input-method-title (quail-title)) 227 (setq current-input-method-title (quail-title))
235 (quail-mode 1)) 228 (quail-activate))
236 229
237(defun quail-inactivate () 230(defconst quail-translation-keymap
238 "Turn off Quail input method."
239 (interactive)
240 (setq overriding-terminal-local-map nil)
241 (quail-mode -1))
242
243(or (assq 'quail-mode minor-mode-alist)
244 (setq minor-mode-alist
245 (cons '(quail-mode " Quail") minor-mode-alist)))
246
247(defvar quail-mode-map
248 (let ((map (make-keymap)) 231 (let ((map (make-keymap))
249 (i ? )) 232 (i ?\ ))
250 (while (< i 127)
251 (define-key map (char-to-string i) 'quail-start-translation)
252 (setq i (1+ i)))
253 (setq i 128)
254 (while (< i 256)
255 (define-key map (vector i) 'quail-start-translation)
256 (setq i (1+ i)))
257 map)
258 "Keymap for Quail mode.")
259
260(or (assq 'quail-mode minor-mode-map-alist)
261 (setq minor-mode-map-alist
262 (cons (cons 'quail-mode quail-mode-map) minor-mode-map-alist)))
263
264;; Since some Emacs Lisp programs (e.g. viper.el) make
265;; minor-mode-map-alist buffer-local, we must be sure to register
266;; quail-mode-map in default-value of minor-mode-map-alist.
267(if (local-variable-p 'minor-mode-map-alist)
268 (let ((map (default-value 'minor-mode-map-alist)))
269 (or (assq 'quail-mode map)
270 (set-default 'minor-mode-map-alist (cons 'quail-mode map)))))
271
272(defvar quail-translation-keymap
273 (let ((map (make-keymap))
274 (i 0))
275 (while (< i ?\ )
276 (define-key map (char-to-string i) 'quail-execute-non-quail-command)
277 (setq i (1+ i)))
278 (while (< i 127) 233 (while (< i 127)
279 (define-key map (char-to-string i) 'quail-self-insert-command) 234 (define-key map (char-to-string i) 'quail-self-insert-command)
280 (setq i (1+ i))) 235 (setq i (1+ i)))
@@ -300,8 +255,6 @@ LEIM is available from the same ftp directory as Emacs."))
300 (define-key map [mouse-2] 'quail-mouse-choose-completion) 255 (define-key map [mouse-2] 'quail-mouse-choose-completion)
301 (define-key map [down-mouse-2] nil) 256 (define-key map [down-mouse-2] nil)
302 (define-key map "\C-h" 'quail-translation-help) 257 (define-key map "\C-h" 'quail-translation-help)
303;;; This interferes with handling of escape sequences on non-X terminals.
304;;; (define-key map "\e" '(keymap (t . quail-execute-non-quail-command)))
305 (define-key map [?\C- ] 'quail-select-current) 258 (define-key map [?\C- ] 'quail-select-current)
306 (define-key map [tab] 'quail-completion) 259 (define-key map [tab] 'quail-completion)
307 (define-key map [delete] 'quail-delete-last-char) 260 (define-key map [delete] 'quail-delete-last-char)
@@ -309,56 +262,38 @@ LEIM is available from the same ftp directory as Emacs."))
309 (let ((meta-map (make-sparse-keymap))) 262 (let ((meta-map (make-sparse-keymap)))
310 (define-key map (char-to-string meta-prefix-char) meta-map) 263 (define-key map (char-to-string meta-prefix-char) meta-map)
311 (define-key map [escape] meta-map)) 264 (define-key map [escape] meta-map))
312 (define-key map (vector meta-prefix-char t)
313 'quail-execute-non-quail-command)
314 ;; At last, define default key binding.
315 (define-key map [t] 'quail-execute-non-quail-command)
316 map) 265 map)
317 "Keymap used processing translation in complex Quail modes. 266 "Keymap used processing translation in complex Quail modes.
318Only a few especially complex input methods use this map; 267Only a few especially complex input methods use this map;
319most use `quail-simple-translation-keymap' instead. 268most use `quail-simple-translation-keymap' instead.
320This map is activated while translation region is active.") 269This map is activated while translation region is active.")
321 270
322(defvar quail-simple-translation-keymap 271(defconst quail-simple-translation-keymap
323 (let ((map (make-keymap)) 272 (let ((map (make-keymap))
324 (i 0)) 273 (i ?\ ))
325 (while (< i ?\ )
326 (define-key map (char-to-string i) 'quail-execute-non-quail-command)
327 (setq i (1+ i)))
328 (while (< i 127) 274 (while (< i 127)
329 (define-key map (char-to-string i) 'quail-self-insert-command) 275 (define-key map (char-to-string i) 'quail-self-insert-command)
330 (setq i (1+ i))) 276 (setq i (1+ i)))
331 (define-key map "\177" 'quail-delete-last-char) 277 (define-key map "\177" 'quail-delete-last-char)
332 (define-key map [delete] 'quail-delete-last-char) 278 (define-key map [delete] 'quail-delete-last-char)
333 (define-key map [backspace] 'quail-delete-last-char) 279 (define-key map [backspace] 'quail-delete-last-char)
334;;; This interferes with handling of escape sequences on non-X terminals.
335;;; (define-key map "\e" '(keymap (t . quail-execute-non-quail-command)))
336 (let ((meta-map (make-sparse-keymap))) 280 (let ((meta-map (make-sparse-keymap)))
337 (define-key map (char-to-string meta-prefix-char) meta-map) 281 (define-key map (char-to-string meta-prefix-char) meta-map)
338 (define-key map [escape] meta-map)) 282 (define-key map [escape] meta-map))
339 (define-key map (vector meta-prefix-char t)
340 'quail-execute-non-quail-command)
341 ;; At last, define default key binding.
342 (define-key map [t]
343 'quail-execute-non-quail-command)
344 map) 283 map)
345 "Keymap used while processing translation in simple Quail modes. 284 "Keymap used while processing translation in simple Quail modes.
346A few especially complex input methods use `quail--translation-keymap' instead. 285A few especially complex input methods use `quail--translation-keymap' instead.
347This map is activated while translation region is active.") 286This map is activated while translation region is active.")
348 287
349(defvar quail-conversion-keymap 288(defconst quail-conversion-keymap
350 (let ((map (make-keymap)) 289 (let ((map (make-keymap))
351 (i 0)) 290 (i ?\ ))
352 (while (< i ?\ )
353 (define-key map (char-to-string i) 'quail-execute-non-quail-command)
354 (setq i (1+ i)))
355 (while (< i 127) 291 (while (< i 127)
356 (define-key map (char-to-string i) 292 (define-key map (char-to-string i) 'quail-self-insert-command)
357 'quail-start-translation-in-conversion-mode)
358 (setq i (1+ i))) 293 (setq i (1+ i)))
359 (setq i 128) 294 (setq i 128)
360 (while (< i 256) 295 (while (< i 256)
361 (define-key map (vector i) 'quail-start-translation-in-conversion-mode) 296 (define-key map (vector i) 'quail-self-insert-command)
362 (setq i (1+ i))) 297 (setq i (1+ i)))
363 (define-key map "\C-b" 'quail-conversion-backward-char) 298 (define-key map "\C-b" 'quail-conversion-backward-char)
364 (define-key map "\C-f" 'quail-conversion-forward-char) 299 (define-key map "\C-f" 'quail-conversion-forward-char)
@@ -366,18 +301,9 @@ This map is activated while translation region is active.")
366 (define-key map "\C-e" 'quail-conversion-end-of-region) 301 (define-key map "\C-e" 'quail-conversion-end-of-region)
367 (define-key map "\C-d" 'quail-conversion-delete-char) 302 (define-key map "\C-d" 'quail-conversion-delete-char)
368 (define-key map "\C-h" 'quail-conversion-help) 303 (define-key map "\C-h" 'quail-conversion-help)
369;;; This interferes with handling of escape sequences on non-X terminals.
370;;; (define-key map "\e" '(keymap (t . quail-execute-non-quail-command)))
371 (define-key map "\177" 'quail-conversion-backward-delete-char) 304 (define-key map "\177" 'quail-conversion-backward-delete-char)
372 (define-key map [delete] 'quail-conversion-backward-delete-char) 305 (define-key map [delete] 'quail-conversion-backward-delete-char)
373 (define-key map [backspace] 'quail-conversion-backward-delete-char) 306 (define-key map [backspace] 'quail-conversion-backward-delete-char)
374 (let ((meta-map (make-sparse-keymap)))
375 (define-key map (char-to-string meta-prefix-char) meta-map)
376 (define-key map [escape] meta-map))
377 (define-key map (vector meta-prefix-char t)
378 'quail-execute-non-quail-command)
379 ;; At last, define default key binding.
380 (define-key map [t] 'quail-execute-non-quail-command)
381 map) 307 map)
382 "Keymap used for processing conversion in Quail mode. 308 "Keymap used for processing conversion in Quail mode.
383This map is activated while convesion region is active but translation 309This map is activated while convesion region is active but translation
@@ -523,9 +449,9 @@ non-Quail commands."
523 449
524;; Delete overlays used in Quail mode. 450;; Delete overlays used in Quail mode.
525(defun quail-delete-overlays () 451(defun quail-delete-overlays ()
526 (if (overlayp quail-overlay) 452 (if (and (overlayp quail-overlay) (overlay-start quail-overlay))
527 (delete-overlay quail-overlay)) 453 (delete-overlay quail-overlay))
528 (if (overlayp quail-conv-overlay) 454 (if (and (overlayp quail-conv-overlay) (overlay-start quail-conv-overlay))
529 (delete-overlay quail-conv-overlay))) 455 (delete-overlay quail-conv-overlay)))
530 456
531;; Kill Quail guidance buffer. Set in kill-buffer-hook. 457;; Kill Quail guidance buffer. Set in kill-buffer-hook.
@@ -533,48 +459,33 @@ non-Quail commands."
533 (if (buffer-live-p quail-guidance-buf) 459 (if (buffer-live-p quail-guidance-buf)
534 (kill-buffer quail-guidance-buf))) 460 (kill-buffer quail-guidance-buf)))
535 461
536(defun quail-mode (&optional arg) 462(defun quail-inactivate ()
537 "Toggle Quail minor mode. 463 "Inactivate Quail input method."
538With arg, turn Quail mode on if and only if arg is positive. 464 (interactive)
539 465 (quail-activate -1))
540In Quail mode, all printable characters are bound to 466
541`quail-start-translation'. This function checks if the current input 467(defun quail-activate (&optional arg)
542method will translate the last input key. If not, the key is handled 468 "Activate Quail input method.
543out of Quail mode, i.e, in another activated minor mode or in the 469With arg, activate Quail input method if and only if arg is positive.
544current major mode. 470
545\\{quail-mode-map} 471While this input method is active, the variable
546Unlike the other minor modes, this is not an interactive function. 472`input-method-function' is bound to the function `quail-input-method'."
547Use the commands \\[toggle-input-method] (`toggle-input-method') or 473 (if (and arg
548\\[set-input-method] (`set-input-method') which automatically turn on 474 (< (prefix-numeric-value arg) 0))
549Quail mode with an appropriate Quail package, or turn it off." 475 ;; Let's inactivate Quail input method.
550 (setq quail-mode 476 (unwind-protect
551 (if (null arg) (null quail-mode) 477 (progn
552 (> (prefix-numeric-value arg) 0))) 478 (quail-hide-guidance-buf)
553 (if (null quail-mode) 479 (quail-delete-overlays)
554 ;; Let's turn off Quail mode. 480 (setq describe-current-input-method-function nil)
555 (progn 481 (run-hooks 'quail-inactivate-hook))
556 (quail-hide-guidance-buf) 482 (kill-local-variable 'input-method-function))
557 (quail-delete-overlays) 483 ;; Let's active Quail input method.
558 (setq describe-current-input-method-function nil)
559 (run-hooks 'quail-mode-exit-hook))
560 ;; Let's turn on Quail mode.
561 ;; At first, be sure that quail-mode is at the first element of
562 ;; minor-mode-map-alist.
563 (or (eq (car minor-mode-map-alist) 'quail-mode)
564 (let ((l minor-mode-map-alist))
565 (while (cdr l)
566 (if (eq (car (cdr l)) 'quail-mode)
567 (progn
568 (setcdr l (cdr (cdr l)))
569 (setq l nil))
570 (setq l (cdr l))))
571 (setq minor-mode-map-alist (cons 'quail-mode minor-mode-map-alist))))
572 (if (null quail-current-package) 484 (if (null quail-current-package)
573 ;; Quail package is not yet selected. Select one now. 485 ;; Quail package is not yet selected. Select one now.
574 (let (name) 486 (let (name)
575 (if quail-package-alist 487 (if quail-package-alist
576 (setq name (car (car quail-package-alist))) 488 (setq name (car (car quail-package-alist)))
577 (setq quail-mode nil)
578 (error "No Quail package loaded")) 489 (error "No Quail package loaded"))
579 (quail-select-package name))) 490 (quail-select-package name)))
580 (setq inactivate-current-input-method-function 'quail-inactivate) 491 (setq inactivate-current-input-method-function 'quail-inactivate)
@@ -585,66 +496,17 @@ Quail mode with an appropriate Quail package, or turn it off."
585 ;; before exiting. 496 ;; before exiting.
586 (if (eq (selected-window) (minibuffer-window)) 497 (if (eq (selected-window) (minibuffer-window))
587 (add-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer)) 498 (add-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer))
588 (make-local-hook 'post-command-hook)
589 (make-local-hook 'kill-buffer-hook) 499 (make-local-hook 'kill-buffer-hook)
590 (add-hook 'kill-buffer-hook 'quail-kill-guidance-buf nil t) 500 (add-hook 'kill-buffer-hook 'quail-kill-guidance-buf nil t)
591 (run-hooks 'quail-mode-hook)) 501 (run-hooks 'quail-activate-hook)
592 (force-mode-line-update)) 502 (make-local-variable 'input-method-function)
503 (setq input-method-function 'quail-input-method)))
593 504
594(defun quail-exit-from-minibuffer () 505(defun quail-exit-from-minibuffer ()
595 (inactivate-input-method) 506 (inactivate-input-method)
596 (if (<= (minibuffer-depth) 1) 507 (if (<= (minibuffer-depth) 1)
597 (remove-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer))) 508 (remove-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer)))
598 509
599(defvar quail-saved-current-map nil)
600(defvar quail-saved-current-buffer nil)
601
602;; Toggle Quail mode. This function is added to `post-command-hook'
603;; in Quail mode, to turn Quail mode temporarily off, or back on after
604;; one non-Quail command.
605(defun quail-toggle-mode-temporarily ()
606 (if quail-mode
607 ;; We are going to handle following events out of Quail mode.
608 (setq quail-saved-current-buffer (current-buffer)
609 quail-saved-current-map overriding-terminal-local-map
610 quail-mode nil
611 overriding-terminal-local-map nil)
612 ;; We have just executed one non-Quail command. We don't need
613 ;; this hook any more.
614 (remove-hook 'post-command-hook 'quail-toggle-mode-temporarily t)
615 (if (eq (current-buffer) quail-saved-current-buffer)
616 ;; We should go back to Quail mode only when the current input
617 ;; method was not turned off by the last command.
618 (when current-input-method
619 (setq quail-mode t
620 overriding-terminal-local-map quail-saved-current-map)
621 (if input-method-exit-on-invalid-key
622 (inactivate-input-method)))
623 ;; The last command changed the current buffer, we should not go
624 ;; back to Quail mode in this new buffer, but should turn on
625 ;; Quail mode in the original buffer.
626 (save-excursion
627 (set-buffer quail-saved-current-buffer)
628 (setq quail-mode t)
629 (quail-delete-overlays)))))
630
631(defun quail-execute-non-quail-command ()
632 "Execute one non-Quail command out of Quail mode.
633The current translation and conversion are terminated."
634 (interactive)
635 (let* ((key (this-command-keys))
636 (keylist (listify-key-sequence key)))
637 (setq unread-command-events (append keylist unread-command-events)))
638 (reset-this-command-lengths)
639 (quail-terminate-translation)
640 (quail-delete-overlays)
641 (setq overriding-terminal-local-map nil)
642 (if (buffer-live-p quail-guidance-buf)
643 (save-excursion
644 (set-buffer quail-guidance-buf)
645 (erase-buffer)))
646 (add-hook 'post-command-hook 'quail-toggle-mode-temporarily nil t))
647
648;; Keyboard layout translation handlers. 510;; Keyboard layout translation handlers.
649 511
650;; Some Quail packages provide localized keyboard simulation which 512;; Some Quail packages provide localized keyboard simulation which
@@ -984,67 +846,116 @@ The returned value is a Quail map specific to KEY."
984 )) 846 ))
985 map)) 847 map))
986 848
987;; If set to non-nil, exit conversion mode before starting new translation. 849(put 'quail-error 'error-conditions '(quail-error error))
988(defvar quail-exit-conversion-mode nil) 850(defun quail-error (&rest args)
989 851 (signal 'quail-error (apply 'format args)))
990(defvar quail-prefix-arg nil) 852
991 853(defvar quail-translating nil)
992(defun quail-start-translation (arg) 854(defvar quail-converting nil)
993 "Start translating the typed character in Quail mode." 855
994 (interactive "*p") 856(defun quail-input-method (key)
995 (setq prefix-arg current-prefix-arg) 857 (if (or buffer-read-only
996 (setq quail-prefix-arg arg) 858 (and (or overriding-terminal-local-map
997 (setq unread-command-events 859 overriding-local-map)
998 (cons last-command-event unread-command-events)) 860 (>= key ?0) (<= key ?9)))
999 ;; Check the possibility of translating the last key. 861 (list key)
1000 (if (and (integerp last-command-event) 862 (quail-setup-overlays (quail-conversion-keymap))
1001 (assq (if (quail-kbd-translate) 863 (let ((modified-p (buffer-modified-p)))
1002 (quail-keyboard-translate last-command-event) 864 (unwind-protect
1003 last-command-event) 865 (if (quail-conversion-keymap)
866 (quail-start-conversion key)
867 (quail-start-translation key))
868 (set-buffer-modified-p modified-p)
869 (quail-delete-overlays)))))
870
871(defun quail-overlay-region-events (overlay)
872 (let ((start (overlay-start overlay))
873 (end (overlay-end overlay)))
874 (if (< start end)
875 (prog1
876 (string-to-list (buffer-substring start end))
877 (delete-region start end)))))
878
879(defun quail-start-translation (key)
880 "Start translation of the typed character KEY by the current Quail package."
881 ;; Check the possibility of translating KEY.
882 (if (and (integerp key)
883 (assq (if (quail-kbd-translate) (quail-keyboard-translate key) key)
1004 (cdr (quail-map)))) 884 (cdr (quail-map))))
1005 ;; Ok, we can start translation. 885 ;; Ok, we can start translation.
1006 (if (quail-conversion-keymap) 886 (let* ((translation-keymap (quail-translation-keymap))
1007 ;; We must start translation in conversion mode. 887 (overriding-terminal-local-map translation-keymap)
1008 (setq quail-exit-conversion-mode nil 888 (generated-events nil)
1009 overriding-terminal-local-map (quail-conversion-keymap)) 889 (input-method-function nil))
1010 (quail-setup-overlays nil) 890 (setq quail-current-key ""
1011 (setq quail-current-key "") 891 quail-current-str nil
1012 (setq overriding-terminal-local-map (quail-translation-keymap))) 892 quail-translating t
1013 ;; Since the last event doesn't start any translation, handle it 893 unread-command-events (cons key unread-command-events))
1014 ;; out of Quail mode. We come back to Quail mode later by setting 894 (while quail-translating
1015 ;; function `quail-toggle-mode-temporarily' in 895 (let* ((echo-keystrokes 0)
1016 ;; `post-command-hook'. 896 (keyseq (read-key-sequence nil))
1017 (add-hook 'post-command-hook 'quail-toggle-mode-temporarily nil t))) 897 (cmd (lookup-key translation-keymap keyseq t)))
1018 898 (if (commandp cmd)
1019(defsubst quail-point-in-conversion-region () 899 (progn
1020 "Return non-nil value if the point is in conversion region of Quail mode." 900 (setq last-command-event (aref keyseq 0))
1021 (let (start pos) 901 (condition-case err
1022 (and (setq start (overlay-start quail-conv-overlay)) 902 (call-interactively cmd)
1023 (>= (setq pos (point)) start) 903 (quail-error (message "%s" (cdr err)) (beep))))
1024 (<= pos (overlay-end quail-conv-overlay))))) 904 ;; KEYSEQ is not defined in the translation keymap.
1025 905 ;; Let's return the event(s) to the caller.
1026(defun quail-start-translation-in-conversion-mode () 906 (setq generated-events (string-to-list keyseq)
1027 "Start translating the typed character in conversion mode of Quail mode." 907 quail-translating nil))))
1028 (interactive "*") 908 (setq generated-events
1029 (setq unread-command-events 909 (append (quail-overlay-region-events quail-overlay)
1030 (cons last-command-event unread-command-events)) 910 generated-events))
1031 ;; Check the possibility of translating the last key. 911 generated-events)
1032 (if (and (integerp last-command-event) 912
1033 (assq (if (quail-kbd-translate) 913 ;; Since KEY doesn't start any translation, just return it.
1034 (quail-keyboard-translate last-command-event) 914 (list key)))
1035 last-command-event) 915
916(defun quail-start-conversion (key)
917 "Start conversion of the typed character KEY by the current Quail package."
918 ;; Check the possibility of translating KEY.
919 (if (and (integerp key)
920 (assq (if (quail-kbd-translate) (quail-keyboard-translate key) key)
1036 (cdr (quail-map)))) 921 (cdr (quail-map))))
1037 ;; Ok, we can start translation. 922 ;; Ok, we can start translation and conversion.
1038 (progn 923 (let* ((conversion-keymap (quail-conversion-keymap))
1039 (quail-setup-overlays t) 924 (overriding-terminal-local-map conversion-keymap)
1040 (setq quail-current-key "") 925 (generated-events nil)
1041 (setq overriding-terminal-local-map (quail-translation-keymap)) 926 (input-method-function nil))
1042 (move-overlay quail-overlay (point) (point))) 927 (setq quail-current-key ""
1043 ;; Since the last event doesn't start any translation, handle it 928 quail-current-str nil
1044 ;; out of Quail mode. We come back to Quail mode later by setting 929 quail-converting t
1045 ;; function `quail-toggle-mode-temporarily' in 930 quail-translating t
1046 ;; `post-command-hook'. 931 unread-command-events (cons key unread-command-events))
1047 (add-hook 'post-command-hook 'quail-toggle-mode-temporarily nil t))) 932 (while quail-converting
933 (or quail-translating
934 (progn
935 (setq quail-current-key ""
936 quail-current-str nil
937 quail-translating t)
938 (quail-setup-overlays nil)))
939 (let* ((echo-keystrokes 0)
940 (keyseq (read-key-sequence nil))
941 (cmd (lookup-key conversion-keymap keyseq t)))
942 (if (commandp cmd)
943 (progn
944 (setq last-command-event (aref keyseq 0))
945 (condition-case err
946 (call-interactively cmd)
947 (quail-error (message "%s" (cdr err)) (beep))))
948 ;; KEYSEQ is not defined in the conversion keymap.
949 ;; Let's return the event(s) to the caller.
950 (setq generated-events (string-to-list keyseq)
951 quail-converting nil))))
952 (setq generated-events
953 (append (quail-overlay-region-events quail-conv-overlay)
954 generated-events))
955 generated-events)
956
957 ;; Since KEY doesn't start any translation, just return it.
958 (list key)))
1048 959
1049(defsubst quail-delete-region () 960(defsubst quail-delete-region ()
1050 "Delete the text in the current translation region of Quail." 961 "Delete the text in the current translation region of Quail."
@@ -1054,38 +965,11 @@ The returned value is a Quail map specific to KEY."
1054 965
1055(defun quail-terminate-translation () 966(defun quail-terminate-translation ()
1056 "Terminate the translation of the current key." 967 "Terminate the translation of the current key."
1057 (when (overlayp quail-overlay) 968 (setq quail-translating nil)
1058 (let ((start (overlay-start quail-overlay)))
1059 (if (and start
1060 (< start (overlay-end quail-overlay)))
1061 ;; Here we simulate self-insert-command.
1062 (let ((seq (string-to-sequence
1063 (buffer-substring (overlay-start quail-overlay)
1064 (overlay-end quail-overlay))
1065 'list))
1066 last-command-char)
1067 (goto-char start)
1068 (quail-delete-region)
1069 (setq last-command-char (car seq))
1070 (self-insert-command (or quail-prefix-arg 1))
1071 (setq quail-prefix-arg nil)
1072 (setq seq (cdr seq))
1073 (while seq
1074 (setq last-command-char (car seq))
1075 (self-insert-command 1)
1076 (setq seq (cdr seq))))))
1077 (delete-overlay quail-overlay))
1078 (if (buffer-live-p quail-guidance-buf) 969 (if (buffer-live-p quail-guidance-buf)
1079 (save-excursion 970 (save-excursion
1080 (set-buffer quail-guidance-buf) 971 (set-buffer quail-guidance-buf)
1081 (erase-buffer))) 972 (erase-buffer))))
1082 (setq overriding-terminal-local-map
1083 (quail-conversion-keymap))
1084 ;; Run this hook only when the current input method doesn't require
1085 ;; conversion. When conversion is required, the conversion function
1086 ;; should run this hook at a proper timing.
1087 (unless (quail-conversion-keymap)
1088 (run-hooks 'input-method-after-insert-chunk-hook)))
1089 973
1090(defun quail-select-current () 974(defun quail-select-current ()
1091 "Select the current text shown in Quail translation region." 975 "Select the current text shown in Quail translation region."
@@ -1095,7 +979,7 @@ The returned value is a Quail map specific to KEY."
1095;; Update the current translation status according to CONTROL-FLAG. 979;; Update the current translation status according to CONTROL-FLAG.
1096;; If CONTROL-FLAG is integer value, it is the number of keys in the 980;; If CONTROL-FLAG is integer value, it is the number of keys in the
1097;; head quail-current-key which can be translated. The remaining keys 981;; head quail-current-key which can be translated. The remaining keys
1098;; are put back to unread-command-events to be handled again. 982;; are put back to unread-input-method-events to be handled again.
1099;; If CONTROL-FLAG is t, terminate the translation for the whole keys 983;; If CONTROL-FLAG is t, terminate the translation for the whole keys
1100;; in quail-current-key. 984;; in quail-current-key.
1101;; If CONTROL-FLAG is nil, proceed the translation with more keys. 985;; If CONTROL-FLAG is nil, proceed the translation with more keys.
@@ -1109,9 +993,9 @@ The returned value is a Quail map specific to KEY."
1109 (let ((len (length quail-current-key))) 993 (let ((len (length quail-current-key)))
1110 (while (> len control-flag) 994 (while (> len control-flag)
1111 (setq len (1- len)) 995 (setq len (1- len))
1112 (setq unread-command-events 996 (setq unread-input-method-events
1113 (cons (aref quail-current-key len) 997 (cons (aref quail-current-key len)
1114 unread-command-events))) 998 unread-input-method-events)))
1115 ;; Insert the translated sequence. 999 ;; Insert the translated sequence.
1116 ;; It is a string containing multibyte characters. 1000 ;; It is a string containing multibyte characters.
1117 ;; If enable-multibyte-characters, just insert it. 1001 ;; If enable-multibyte-characters, just insert it.
@@ -1127,7 +1011,7 @@ The returned value is a Quail map specific to KEY."
1127 (setq char (sref char 0))) 1011 (setq char (sref char 0)))
1128 (if (= (length (split-char char)) 2) 1012 (if (= (length (split-char char)) 2)
1129 (insert-char (logand char 255) 1) 1013 (insert-char (logand char 255) 1)
1130 (error "Three-byte characters require enabling multibyte characters"))))) 1014 (quail-error "Three-byte characters require enabling multibyte characters")))))
1131 (insert (or quail-current-str quail-current-key))))) 1015 (insert (or quail-current-str quail-current-key)))))
1132 (quail-update-guidance) 1016 (quail-update-guidance)
1133 (if control-flag 1017 (if control-flag
@@ -1143,7 +1027,7 @@ The returned value is a Quail map specific to KEY."
1143 t) 1027 t)
1144 ;; If someone throws for `quail-tag' by value nil, we exit from 1028 ;; If someone throws for `quail-tag' by value nil, we exit from
1145 ;; translation mode. 1029 ;; translation mode.
1146 (setq overriding-terminal-local-map nil))) 1030 (setq quail-translating nil)))
1147 1031
1148;; Return the actual definition part of Quail map MAP. 1032;; Return the actual definition part of Quail map MAP.
1149(defun quail-map-definition (map) 1033(defun quail-map-definition (map)
@@ -1294,7 +1178,9 @@ sequence counting from the head."
1294 (setcar indices (1+ (car indices))) 1178 (setcar indices (1+ (car indices)))
1295 (quail-update-current-translations) 1179 (quail-update-current-translations)
1296 (quail-update-translation nil))) 1180 (quail-update-translation nil)))
1297 (quail-execute-non-quail-command))) 1181 (setq unread-command-events
1182 (cons last-command-event unread-command-events))
1183 (quail-terminate-translation)))
1298 1184
1299(defun quail-prev-translation () 1185(defun quail-prev-translation ()
1300 "Select previous translation in the current batch of candidates." 1186 "Select previous translation in the current batch of candidates."
@@ -1307,7 +1193,9 @@ sequence counting from the head."
1307 (setcar indices (1- (car indices))) 1193 (setcar indices (1- (car indices)))
1308 (quail-update-current-translations) 1194 (quail-update-current-translations)
1309 (quail-update-translation nil))) 1195 (quail-update-translation nil)))
1310 (quail-execute-non-quail-command))) 1196 (setq unread-command-events
1197 (cons last-command-event unread-command-events))
1198 (quail-terminate-translation)))
1311 1199
1312(defun quail-next-translation-block () 1200(defun quail-next-translation-block ()
1313 "Select from the next block of translations." 1201 "Select from the next block of translations."
@@ -1321,7 +1209,9 @@ sequence counting from the head."
1321 (setcar indices (+ (nth 2 indices) offset)) 1209 (setcar indices (+ (nth 2 indices) offset))
1322 (quail-update-current-translations) 1210 (quail-update-current-translations)
1323 (quail-update-translation nil))) 1211 (quail-update-translation nil)))
1324 (quail-execute-non-quail-command))) 1212 (setq unread-command-events
1213 (append (string-to-list unread-command-events)))
1214 (quail-terminate-translation)))
1325 1215
1326(defun quail-prev-translation-block () 1216(defun quail-prev-translation-block ()
1327 "Select the previous batch of 10 translation candidates." 1217 "Select the previous batch of 10 translation candidates."
@@ -1339,7 +1229,9 @@ sequence counting from the head."
1339 (setcar indices (+ (nth 1 indices) offset)) 1229 (setcar indices (+ (nth 1 indices) offset))
1340 (quail-update-current-translations))) 1230 (quail-update-current-translations)))
1341 (quail-update-translation nil))) 1231 (quail-update-translation nil)))
1342 (quail-execute-non-quail-command))) 1232 (setq unread-command-events
1233 (cons last-command-event unread-command-events))
1234 (quail-terminate-translation)))
1343 1235
1344(defun quail-abort-translation () 1236(defun quail-abort-translation ()
1345 "Abort translation and delete the current Quail key sequence." 1237 "Abort translation and delete the current Quail key sequence."
@@ -1360,13 +1252,15 @@ sequence counting from the head."
1360(defun quail-conversion-backward-char () 1252(defun quail-conversion-backward-char ()
1361 (interactive) 1253 (interactive)
1362 (if (<= (point) (overlay-start quail-conv-overlay)) 1254 (if (<= (point) (overlay-start quail-conv-overlay))
1363 (error "Beginning of conversion region")) 1255 (quail-error "Beginning of conversion region"))
1256 (setq quail-translating nil)
1364 (forward-char -1)) 1257 (forward-char -1))
1365 1258
1366(defun quail-conversion-forward-char () 1259(defun quail-conversion-forward-char ()
1367 (interactive) 1260 (interactive)
1368 (if (>= (point) (overlay-end quail-conv-overlay)) 1261 (if (>= (point) (overlay-end quail-conv-overlay))
1369 (error "End of conversion region")) 1262 (quail-error "End of conversion region"))
1263 (setq quail-translating nil)
1370 (forward-char 1)) 1264 (forward-char 1))
1371 1265
1372(defun quail-conversion-beginning-of-region () 1266(defun quail-conversion-beginning-of-region ()
@@ -1380,22 +1274,20 @@ sequence counting from the head."
1380(defun quail-conversion-delete-char () 1274(defun quail-conversion-delete-char ()
1381 (interactive) 1275 (interactive)
1382 (if (>= (point) (overlay-end quail-conv-overlay)) 1276 (if (>= (point) (overlay-end quail-conv-overlay))
1383 (error "End of conversion region")) 1277 (quail-error "End of conversion region"))
1384 (delete-char 1) 1278 (delete-char 1)
1385 (when (= (overlay-start quail-conv-overlay) 1279 (if (= (overlay-start quail-conv-overlay)
1386 (overlay-end quail-conv-overlay)) 1280 (overlay-end quail-conv-overlay))
1387 (quail-delete-overlays) 1281 (setq quail-converting nil)))
1388 (setq overriding-terminal-local-map nil)))
1389 1282
1390(defun quail-conversion-backward-delete-char () 1283(defun quail-conversion-backward-delete-char ()
1391 (interactive) 1284 (interactive)
1392 (if (<= (point) (overlay-start quail-conv-overlay)) 1285 (if (<= (point) (overlay-start quail-conv-overlay))
1393 (error "Beginning of conversion region")) 1286 (quail-error "Beginning of conversion region"))
1394 (delete-char -1) 1287 (delete-char -1)
1395 (when (= (overlay-start quail-conv-overlay) 1288 (if (= (overlay-start quail-conv-overlay)
1396 (overlay-end quail-conv-overlay)) 1289 (overlay-end quail-conv-overlay))
1397 (quail-delete-overlays) 1290 (setq quail-converting nil)))
1398 (setq overriding-terminal-local-map nil)))
1399 1291
1400(defun quail-do-conversion (func &rest args) 1292(defun quail-do-conversion (func &rest args)
1401 "Call FUNC to convert text in the current conversion region of Quail. 1293 "Call FUNC to convert text in the current conversion region of Quail.
@@ -1406,8 +1298,7 @@ Remaining args are for FUNC."
1406(defun quail-no-conversion () 1298(defun quail-no-conversion ()
1407 "Do no conversion of the current conversion region of Quail." 1299 "Do no conversion of the current conversion region of Quail."
1408 (interactive) 1300 (interactive)
1409 (quail-delete-overlays) 1301 (setq quail-converting nil)
1410 (setq overriding-terminal-local-map nil)
1411 (run-hooks 'input-method-after-insert-chunk-hook)) 1302 (run-hooks 'input-method-after-insert-chunk-hook))
1412 1303
1413;; Guidance, Completion, and Help buffer handlers. 1304;; Guidance, Completion, and Help buffer handlers.
@@ -1752,7 +1643,7 @@ All possible translations of the current key and whole possible longer keys
1752 (if (and (not (bobp)) (get-text-property (1- (point)) 'mouse-face)) 1643 (if (and (not (bobp)) (get-text-property (1- (point)) 'mouse-face))
1753 (setq end (1- (point)) beg (point))) 1644 (setq end (1- (point)) beg (point)))
1754 (if (null beg) 1645 (if (null beg)
1755 (error "No completion here")) 1646 (quail-error "No completion here"))
1756 (setq beg (previous-single-property-change beg 'mouse-face)) 1647 (setq beg (previous-single-property-change beg 'mouse-face))
1757 (setq end (or (next-single-property-change end 'mouse-face) 1648 (setq end (or (next-single-property-change end 'mouse-face)
1758 (point-max))) 1649 (point-max)))
@@ -1782,7 +1673,7 @@ All possible translations of the current key and whole possible longer keys
1782 (or (not (active-minibuffer-window)) 1673 (or (not (active-minibuffer-window))
1783 (not (equal buffer 1674 (not (equal buffer
1784 (window-buffer (active-minibuffer-window)))))) 1675 (window-buffer (active-minibuffer-window))))))
1785 (error "Minibuffer is not active for completion") 1676 (quail-error "Minibuffer is not active for completion")
1786 ;; Insert the completion into the buffer where completion was requested. 1677 ;; Insert the completion into the buffer where completion was requested.
1787 (set-buffer buffer) 1678 (set-buffer buffer)
1788; (if base-size 1679; (if base-size
@@ -1822,11 +1713,6 @@ All possible translations of the current key and whole possible longer keys
1822 (newline) 1713 (newline)
1823 (if (quail-show-layout) (quail-show-kbd-layout)) 1714 (if (quail-show-layout) (quail-show-kbd-layout))
1824 (quail-help-insert-keymap-description 1715 (quail-help-insert-keymap-description
1825 quail-mode-map
1826 "---- Key bindings (before starting translation) ----
1827key binding
1828--- -------\n")
1829 (quail-help-insert-keymap-description
1830 (quail-translation-keymap) 1716 (quail-translation-keymap)
1831 "--- Key bindings (while translating) --- 1717 "--- Key bindings (while translating) ---
1832key binding 1718key binding