comparison lisp/international/quail.el @ 50541:ad343b711d5e

* international/quail.el (quail-guidance-str) (quail-guidance-frame): New variables. (quail-guidance-win): Delete this variable. (quail-setup-overlays): Make overlay not rear-advancing. (quail-kill-guidance-buf): Delete this function. (quail-activate): Add/remove quail-show-guidance to/from post-command-hook. (quail-input-method): Don't setup quail-guidance-buf. Initialize quail-guidance-str to "". (quail-start-translation): Call quail-show-guidance at first. (quail-start-conversion): Likewise. (quail-terminate-translation): Don't erase quail-guidance-buf. (quail-update-translation): Stretch overlays if their starting and ending positions are same. (quail-update-current-translations): Check the width of the current window, not the width of quail-guidance-win. (quail-make-guidance-frame): Delete the arg BUF. Fix position calculation. Don't set the window buffer, just return the new frame. (quail-minibuffer-message): New function. (quail-show-guidance): Renamed from quail-show-guidance-buf. Use message and quail-minibuffer-message to display the guidance. (quail-hide-guidance): Renamed from quail-hide-guidance-buf. Only delete quail-guidance-frame. (quail-update-guidance): Just update quail-guidance-str, not display it. (quail-get-translations): Renamed from quail-show-translations. Return a string instead of inserting it in quail-guaidance-buf.
author Kenichi Handa <handa@m17n.org>
date Fri, 11 Apr 2003 03:58:00 +0000
parents 2fdc3bbb00ae
children 86e781de42e7
comparison
equal deleted inserted replaced
50540:0f0bc7773998 50541:ad343b711d5e
64 "The current Quail package, which depends on the current input method. 64 "The current Quail package, which depends on the current input method.
65 See the documentation of `quail-package-alist' for the format.") 65 See the documentation of `quail-package-alist' for the format.")
66 (make-variable-buffer-local 'quail-current-package) 66 (make-variable-buffer-local 'quail-current-package)
67 (put 'quail-current-package 'permanent-local t) 67 (put 'quail-current-package 'permanent-local t)
68 68
69 ;; Quail uses the following two buffers to assist users. 69 ;; Quail uses the following variables to assist users.
70 ;; A buffer to show available key sequence or translation list. 70 ;; A string containing available key sequences or translation list.
71 (defvar quail-guidance-buf nil) 71 (defvar quail-guidance-str nil)
72 ;; A buffer to show completion list of the current key sequence. 72 ;; A buffer to show completion list of the current key sequence.
73 (defvar quail-completion-buf nil) 73 (defvar quail-completion-buf nil)
74 ;; We may display the guidance string in a buffer on a one-line frame.
75 (defvar quail-guidance-buf nil)
76 (defvar quail-guidance-frame nil)
74 77
75 ;; Each buffer in which Quail is activated should use different 78 ;; Each buffer in which Quail is activated should use different
76 ;; guidance buffers. 79 ;; guidance string.
77 (make-variable-buffer-local 'quail-guidance-buf) 80 (make-variable-buffer-local 'quail-guidance-str)
78 (put 'quail-guidance-buf 'permanent-local t) 81 (put 'quail-guidance-str 'permanent-local t)
79
80 ;; A main window showing Quail guidance buffer.
81 (defvar quail-guidance-win nil)
82 (make-variable-buffer-local 'quail-guidance-win)
83 82
84 (defvar quail-overlay nil 83 (defvar quail-overlay nil
85 "Overlay which covers the current translation region of Quail.") 84 "Overlay which covers the current translation region of Quail.")
86 (make-variable-buffer-local 'quail-overlay) 85 (make-variable-buffer-local 'quail-overlay)
87 86
512 ;; Setup overlays used in Quail mode. 511 ;; Setup overlays used in Quail mode.
513 (defun quail-setup-overlays (conversion-mode) 512 (defun quail-setup-overlays (conversion-mode)
514 (let ((pos (point))) 513 (let ((pos (point)))
515 (if (overlayp quail-overlay) 514 (if (overlayp quail-overlay)
516 (move-overlay quail-overlay pos pos) 515 (move-overlay quail-overlay pos pos)
517 (setq quail-overlay (make-overlay pos pos nil nil t)) 516 (setq quail-overlay (make-overlay pos pos))
518 (if input-method-highlight-flag 517 (if input-method-highlight-flag
519 (overlay-put quail-overlay 'face 'underline)) 518 (overlay-put quail-overlay 'face 'underline))
520 (let ((l (quail-overlay-plist))) 519 (let ((l (quail-overlay-plist)))
521 (while l 520 (while l
522 (overlay-put quail-overlay (car l) (car (cdr l))) 521 (overlay-put quail-overlay (car l) (car (cdr l)))
523 (setq l (cdr (cdr l)))))) 522 (setq l (cdr (cdr l))))))
524 (if conversion-mode 523 (if conversion-mode
525 (if (overlayp quail-conv-overlay) 524 (if (overlayp quail-conv-overlay)
526 (if (not (overlay-start quail-conv-overlay)) 525 (if (not (overlay-start quail-conv-overlay))
527 (move-overlay quail-conv-overlay pos pos)) 526 (move-overlay quail-conv-overlay pos pos))
528 (setq quail-conv-overlay (make-overlay pos pos nil nil t)) 527 (setq quail-conv-overlay (make-overlay pos pos))
529 (if input-method-highlight-flag 528 (if input-method-highlight-flag
530 (overlay-put quail-conv-overlay 'face 'underline)))))) 529 (overlay-put quail-conv-overlay 'face 'underline))))))
531 530
532 ;; Delete overlays used in Quail mode. 531 ;; Delete overlays used in Quail mode.
533 (defun quail-delete-overlays () 532 (defun quail-delete-overlays ()
534 (if (and (overlayp quail-overlay) (overlay-start quail-overlay)) 533 (if (and (overlayp quail-overlay) (overlay-start quail-overlay))
535 (delete-overlay quail-overlay)) 534 (delete-overlay quail-overlay))
536 (if (and (overlayp quail-conv-overlay) (overlay-start quail-conv-overlay)) 535 (if (and (overlayp quail-conv-overlay) (overlay-start quail-conv-overlay))
537 (delete-overlay quail-conv-overlay))) 536 (delete-overlay quail-conv-overlay)))
538
539 ;; Kill Quail guidance buffer. Set in kill-buffer-hook.
540 (defun quail-kill-guidance-buf ()
541 (if (buffer-live-p quail-guidance-buf)
542 (kill-buffer quail-guidance-buf)))
543 537
544 (defun quail-inactivate () 538 (defun quail-inactivate ()
545 "Inactivate Quail input method. 539 "Inactivate Quail input method.
546 540
547 This function runs the normal hook `quail-inactivate-hook'." 541 This function runs the normal hook `quail-inactivate-hook'."
560 (if (and arg 554 (if (and arg
561 (< (prefix-numeric-value arg) 0)) 555 (< (prefix-numeric-value arg) 0))
562 ;; Let's inactivate Quail input method. 556 ;; Let's inactivate Quail input method.
563 (unwind-protect 557 (unwind-protect
564 (progn 558 (progn
565 (quail-hide-guidance-buf)
566 (quail-delete-overlays) 559 (quail-delete-overlays)
567 (setq describe-current-input-method-function nil) 560 (setq describe-current-input-method-function nil)
561 (quail-hide-guidance)
562 (remove-hook 'post-command-hook 'quail-show-guidance t)
568 (run-hooks 'quail-inactivate-hook)) 563 (run-hooks 'quail-inactivate-hook))
569 (kill-local-variable 'input-method-function)) 564 (kill-local-variable 'input-method-function))
570 ;; Let's activate Quail input method. 565 ;; Let's activate Quail input method.
571 (if (null quail-current-package) 566 (if (null quail-current-package)
572 ;; Quail package is not yet selected. Select one now. 567 ;; Quail package is not yet selected. Select one now.
576 (error "No Quail package loaded")) 571 (error "No Quail package loaded"))
577 (quail-select-package name))) 572 (quail-select-package name)))
578 (setq inactivate-current-input-method-function 'quail-inactivate) 573 (setq inactivate-current-input-method-function 'quail-inactivate)
579 (setq describe-current-input-method-function 'quail-help) 574 (setq describe-current-input-method-function 'quail-help)
580 (quail-delete-overlays) 575 (quail-delete-overlays)
581 (quail-show-guidance-buf) 576 (setq quail-guidance-str "")
577 (quail-show-guidance)
582 ;; If we are in minibuffer, turn off the current input method 578 ;; If we are in minibuffer, turn off the current input method
583 ;; before exiting. 579 ;; before exiting.
584 (if (eq (selected-window) (minibuffer-window)) 580 (when (eq (selected-window) (minibuffer-window))
585 (add-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer)) 581 (add-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer)
586 (add-hook 'kill-buffer-hook 'quail-kill-guidance-buf nil t) 582 (add-hook 'post-command-hook 'quail-show-guidance nil t))
587 (run-hooks 'quail-activate-hook) 583 (run-hooks 'quail-activate-hook)
588 (make-local-variable 'input-method-function) 584 (make-local-variable 'input-method-function)
589 (setq input-method-function 'quail-input-method))) 585 (setq input-method-function 'quail-input-method)))
590 586
591 (defun quail-exit-from-minibuffer () 587 (defun quail-exit-from-minibuffer ()
1311 overriding-local-map) 1307 overriding-local-map)
1312 (list key) 1308 (list key)
1313 (quail-setup-overlays (quail-conversion-keymap)) 1309 (quail-setup-overlays (quail-conversion-keymap))
1314 (let ((modified-p (buffer-modified-p)) 1310 (let ((modified-p (buffer-modified-p))
1315 (buffer-undo-list t)) 1311 (buffer-undo-list t))
1316 (or (and quail-guidance-win
1317 (window-live-p quail-guidance-win)
1318 (eq (window-buffer quail-guidance-win) quail-guidance-buf)
1319 (not input-method-use-echo-area))
1320 (quail-show-guidance-buf))
1321 (unwind-protect 1312 (unwind-protect
1322 (let ((input-string (if (quail-conversion-keymap) 1313 (let ((input-string (if (quail-conversion-keymap)
1323 (quail-start-conversion key) 1314 (quail-start-conversion key)
1324 (quail-start-translation key)))) 1315 (quail-start-translation key))))
1316 (setq quail-guidance-str "")
1325 (when (and (stringp input-string) 1317 (when (and (stringp input-string)
1326 (> (length input-string) 0)) 1318 (> (length input-string) 0))
1327 (if input-method-exit-on-first-char 1319 (if input-method-exit-on-first-char
1328 (list (aref input-string 0)) 1320 (list (aref input-string 0))
1329 (quail-input-string-to-events input-string)))) 1321 (quail-input-string-to-events input-string))))
1330 (quail-delete-overlays) 1322 (quail-delete-overlays)
1331 (if (buffer-live-p quail-guidance-buf)
1332 (with-current-buffer quail-guidance-buf
1333 (erase-buffer)))
1334 (quail-hide-guidance-buf)
1335 (set-buffer-modified-p modified-p) 1323 (set-buffer-modified-p modified-p)
1336 ;; Run this hook only when the current input method doesn't require 1324 ;; Run this hook only when the current input method doesn't require
1337 ;; conversion. When conversion is required, the conversion function 1325 ;; conversion. When conversion is required, the conversion function
1338 ;; should run this hook at a proper timing. 1326 ;; should run this hook at a proper timing.
1339 (unless (quail-conversion-keymap) 1327 (unless (quail-conversion-keymap)
1376 quail-translating t) 1364 quail-translating t)
1377 (if key 1365 (if key
1378 (setq unread-command-events (cons key unread-command-events))) 1366 (setq unread-command-events (cons key unread-command-events)))
1379 (while quail-translating 1367 (while quail-translating
1380 (set-buffer-modified-p modified-p) 1368 (set-buffer-modified-p modified-p)
1369 (quail-show-guidance)
1381 (let* ((keyseq (read-key-sequence 1370 (let* ((keyseq (read-key-sequence
1382 (and input-method-use-echo-area 1371 (and input-method-use-echo-area
1383 (concat input-method-previous-message 1372 (concat input-method-previous-message
1384 quail-current-str)) 1373 quail-current-str))
1385 nil nil t)) 1374 nil nil t))
1440 (progn 1429 (progn
1441 (setq quail-current-key "" 1430 (setq quail-current-key ""
1442 quail-current-str "" 1431 quail-current-str ""
1443 quail-translating t) 1432 quail-translating t)
1444 (quail-setup-overlays nil))) 1433 (quail-setup-overlays nil)))
1445 ;; Hide '... loaded' message. 1434 (quail-show-guidance)
1446 (message nil)
1447 (let* ((keyseq (read-key-sequence 1435 (let* ((keyseq (read-key-sequence
1448 (and input-method-use-echo-area 1436 (and input-method-use-echo-area
1449 (concat input-method-previous-message 1437 (concat input-method-previous-message
1450 quail-conversion-str 1438 quail-conversion-str
1451 quail-current-str)) 1439 quail-current-str))
1490 (char-to-string key))) 1478 (char-to-string key)))
1491 1479
1492 (defun quail-terminate-translation () 1480 (defun quail-terminate-translation ()
1493 "Terminate the translation of the current key." 1481 "Terminate the translation of the current key."
1494 (setq quail-translating nil) 1482 (setq quail-translating nil)
1495 (if (buffer-live-p quail-guidance-buf) 1483 (setq quail-guidance-str " "))
1496 (with-current-buffer quail-guidance-buf
1497 (erase-buffer))))
1498 1484
1499 (defun quail-select-current () 1485 (defun quail-select-current ()
1500 "Accept the currently selected translation." 1486 "Accept the currently selected translation."
1501 (interactive) 1487 (interactive)
1502 (quail-terminate-translation)) 1488 (quail-terminate-translation))
1533 quail-current-key)) 1519 quail-current-key))
1534 (if (and input-method-exit-on-first-char 1520 (if (and input-method-exit-on-first-char
1535 (quail-simple)) 1521 (quail-simple))
1536 (setq control-flag t))))))) 1522 (setq control-flag t)))))))
1537 (or input-method-use-echo-area 1523 (or input-method-use-echo-area
1538 (progn 1524 (let (pos)
1539 (quail-delete-region) 1525 (quail-delete-region)
1540 (insert quail-current-str))) 1526 (setq pos (point))
1527 (insert quail-current-str)
1528 (move-overlay quail-overlay pos (point))
1529 (if (overlayp quail-conv-overlay)
1530 (if (not (overlay-start quail-conv-overlay))
1531 (move-overlay quail-conv-overlay pos (point))
1532 (if (< (overlay-end quail-conv-overlay) (point))
1533 (move-overlay quail-conv-overlay
1534 (overlay-start quail-conv-overlay)
1535 (point)))))))
1541 (let (quail-current-str) 1536 (let (quail-current-str)
1542 (quail-update-guidance)) 1537 (quail-update-guidance))
1543 (or (stringp quail-current-str) 1538 (or (stringp quail-current-str)
1544 (setq quail-current-str (char-to-string quail-current-str))) 1539 (setq quail-current-str (char-to-string quail-current-str)))
1545 (if control-flag 1540 (if control-flag
1599 1594
1600 (if (or (null end) ; We have not yet calculated END. 1595 (if (or (null end) ; We have not yet calculated END.
1601 (< cur start) ; We moved to the previous block. 1596 (< cur start) ; We moved to the previous block.
1602 (>= cur end)) ; We moved to the next block. 1597 (>= cur end)) ; We moved to the next block.
1603 (let ((len (length (cdr quail-current-translations))) 1598 (let ((len (length (cdr quail-current-translations)))
1604 (maxcol (- (window-width quail-guidance-win) 1599 (maxcol (- (window-width)
1605 quail-guidance-translations-starting-column)) 1600 quail-guidance-translations-starting-column))
1606 (block (nth 3 indices)) 1601 (block (nth 3 indices))
1607 col idx width trans num-items blocks) 1602 col idx width trans num-items blocks)
1608 (if (< cur start) 1603 (if (< cur start)
1609 ;; We must calculate from the head. 1604 ;; We must calculate from the head.
1861 (interactive) 1856 (interactive)
1862 (setq quail-converting nil)) 1857 (setq quail-converting nil))
1863 1858
1864 ;; Guidance, Completion, and Help buffer handlers. 1859 ;; Guidance, Completion, and Help buffer handlers.
1865 1860
1866 (defun quail-make-guidance-frame (buf) 1861 (defun quail-make-guidance-frame ()
1867 "Make a new one-line frame for Quail guidance buffer." 1862 "Make a new one-line frame for Quail guidance."
1868 (let* ((fparam (frame-parameters)) 1863 (let* ((fparam (frame-parameters))
1869 (top (cdr (assq 'top fparam))) 1864 (top (cdr (assq 'top fparam)))
1870 (border (cdr (assq 'border-width fparam))) 1865 (border (cdr (assq 'border-width fparam)))
1871 (internal-border (cdr (assq 'internal-border-width fparam))) 1866 (internal-border (cdr (assq 'internal-border-width fparam)))
1872 (newtop (- top 1867 (newtop (- top
1873 (frame-char-height) (* internal-border 2) (* border 2)))) 1868 (frame-char-height) (* internal-border 2) (* border 2))))
1874 (if (< newtop 0) 1869 (if (< newtop 0)
1875 (setq newtop (+ top (frame-pixel-height)))) 1870 (setq newtop (+ top (frame-pixel-height) internal-border border)))
1876 (let* ((frame (make-frame (append '((user-position . t) (height . 1) 1871 (make-frame (append '((user-position . t) (height . 1)
1877 (minibuffer) (menu-bar-lines . 0)) 1872 (minibuffer)
1878 (cons (cons 'top newtop) fparam)))) 1873 (menu-bar-lines . 0) (tool-bar-lines . 0))
1879 (win (frame-first-window frame))) 1874 (cons (cons 'top newtop) fparam)))))
1880 (set-window-buffer win buf)
1881 ;;(set-window-dedicated-p win t)
1882 )))
1883 1875
1884 (defun quail-setup-completion-buf () 1876 (defun quail-setup-completion-buf ()
1885 "Setup Quail completion buffer." 1877 "Setup Quail completion buffer."
1886 (unless (buffer-live-p quail-completion-buf) 1878 (unless (buffer-live-p quail-completion-buf)
1887 (let ((default-enable-multibyte-characters enable-multibyte-characters)) 1879 (let ((default-enable-multibyte-characters enable-multibyte-characters))
1898 (quail-simple))) 1890 (quail-simple)))
1899 (if (eq input-method-verbose-flag 'complex-only) 1891 (if (eq input-method-verbose-flag 'complex-only)
1900 (not (quail-simple)) 1892 (not (quail-simple))
1901 t)))) 1893 t))))
1902 1894
1903 (defun quail-show-guidance-buf () 1895
1904 "Display a guidance buffer for Quail input method in some window. 1896 ;; Quail specific version of minibuffer-message. It displays STRING
1905 Create the buffer if it does not exist yet. 1897 ;; with timeout 1000000 seconds instead of two seconds.
1906 The buffer is normally displayed at the echo area, 1898
1907 but if the current buffer is a minibuffer, it is shown in 1899 (defun quail-minibuffer-message (string)
1908 the bottom-most ordinary window of the same frame, 1900 (message nil)
1909 or in a newly created frame (if the selected frame has no other windows)." 1901 (let ((point-max (point-max))
1910 (when (quail-require-guidance-buf) 1902 (inhibit-quit t))
1911 ;; At first, setup a guidance buffer. 1903 (save-excursion
1912 (let ((default-enable-multibyte-characters enable-multibyte-characters)) 1904 (goto-char point-max)
1913 (or (buffer-live-p quail-guidance-buf) 1905 (insert string))
1914 (setq quail-guidance-buf (generate-new-buffer " *Quail-guidance*")))) 1906 (sit-for 1000000)
1915 (let ((package quail-current-package)) 1907 (delete-region point-max (point-max))
1916 (with-current-buffer quail-guidance-buf 1908 (when quit-flag
1917 ;; To show the title of Quail package. 1909 (setq quit-flag nil
1918 (setq quail-current-package package 1910 unread-command-events '(7)))))
1919 current-input-method (quail-name) 1911
1920 current-input-method-title (quail-title)) 1912 (defun quail-show-guidance ()
1921 (erase-buffer) 1913 "Display a guidance for Quail input method in some window.
1922 (or (overlayp quail-overlay) 1914 The guidance is normally displayed at the echo area,
1923 (progn 1915 or in a newly created frame (if the current buffer is a
1924 (setq quail-overlay (make-overlay 1 1)) 1916 minibuffer and the selected frame has no other windows)."
1925 (overlay-put quail-overlay 'face 'highlight))) 1917 ;; At first, setup a buffer for completion.
1926 (delete-overlay quail-overlay)
1927 (set-buffer-modified-p nil)))
1928 (bury-buffer quail-guidance-buf)
1929
1930 ;; Assign the buffer " *Minibuf-N*" to all windows which are now
1931 ;; displaying quail-guidance-buf.
1932 (let ((win-list (get-buffer-window-list quail-guidance-buf t t)))
1933 (while win-list
1934 (set-window-buffer (car win-list)
1935 (format " *Minibuf-%d*" (minibuffer-depth)))
1936 (setq win-list (cdr win-list))))
1937
1938 ;; Then, display it in an appropriate window.
1939 (let ((win (minibuffer-window)))
1940 (if (or (eq (selected-window) win)
1941 input-method-use-echo-area)
1942 ;; Since we are in minibuffer, we can't use it for guidance.
1943 (if (eq win (frame-root-window))
1944 ;; Create a frame. It is sure that we are using some
1945 ;; window system.
1946 (quail-make-guidance-frame quail-guidance-buf)
1947 ;; Find the bottom window and split it if necessary.
1948 (setq win (window-at
1949 0 (1- (- (frame-height) (window-height win)))))
1950 (let ((height (window-height win))
1951 (window-min-height 2))
1952 ;; If WIN is tall enough, split it vertically and use
1953 ;; the lower one.
1954 (when (>= height 4)
1955 ;; Here, `split-window' returns a lower window
1956 ;; which is what we wanted.
1957 (setq win (split-window win (- height 2))))
1958 (set-window-buffer win quail-guidance-buf)
1959 (with-current-buffer quail-guidance-buf
1960 (fit-window-to-buffer win nil (window-height win)))))
1961 (set-window-buffer win quail-guidance-buf)
1962 (set-minibuffer-window win))
1963 (setq quail-guidance-win win)))
1964
1965 ;; And, create a buffer for completion.
1966 (quail-setup-completion-buf) 1918 (quail-setup-completion-buf)
1967 (bury-buffer quail-completion-buf)) 1919 (bury-buffer quail-completion-buf)
1968 1920
1969 (defun quail-hide-guidance-buf () 1921 ;; Then, show the guidance.
1970 "Hide the Quail guidance buffer." 1922 (when (and (quail-require-guidance-buf)
1971 (if (buffer-live-p quail-guidance-buf) 1923 (null unread-command-events)
1972 (let ((win-list (get-buffer-window-list quail-guidance-buf t t)) 1924 (null unread-post-input-method-events))
1973 win) 1925 (if (or (eq (selected-window) (minibuffer-window))
1974 (while win-list 1926 input-method-use-echo-area)
1975 (setq win (car win-list) win-list (cdr win-list)) 1927 (if (eq (minibuffer-window) (frame-root-window))
1976 (if (window-minibuffer-p win) 1928 ;; Use another frame. It is sure that we are using some
1977 ;; We are using echo area for the guidance buffer. 1929 ;; window system.
1978 ;; Vacate it to the deepest minibuffer. 1930 (let ((guidance quail-guidance-str))
1979 (set-window-buffer win 1931 (or (frame-live-p quail-guidance-frame)
1980 (format " *Minibuf-%d*" (minibuffer-depth))) 1932 (setq quail-guidance-frame
1981 (if (eq win (frame-root-window (window-frame win))) 1933 (quail-make-guidance-frame)))
1982 (progn 1934 (or (buffer-live-p quail-guidance-buf)
1983 ;; We are using a separate frame for guidance buffer. 1935 (setq quail-guidance-buf
1984 ;;(set-window-dedicated-p win nil) 1936 (get-buffer-create " *Quail-guidance*")))
1985 (delete-frame (window-frame win))) 1937 (save-excursion
1986 ;;(set-window-dedicated-p win nil) 1938 (set-buffer quail-guidance-buf)
1987 (delete-window win)))) 1939 (erase-buffer)
1988 (setq quail-guidance-win nil)))) 1940 (setq cursor-type nil)
1941 (insert guidance))
1942 (set-window-buffer (frame-root-window quail-guidance-frame)
1943 quail-guidance-buf)
1944 (quail-minibuffer-message
1945 (format " [%s]" current-input-method-title)))
1946 ;; Show the guidance in the next line of the currrent
1947 ;; minibuffer.
1948 (quail-minibuffer-message
1949 (format " [%s]\n%s"
1950 current-input-method-title quail-guidance-str)))
1951 ;; Show the guidance in echo area without logging.
1952 (let ((message-log-max nil))
1953 (message "%s" quail-guidance-str)))))
1954
1955 (defun quail-hide-guidance ()
1956 "Hide the Quail guidance."
1957 (when (and (quail-require-guidance-buf)
1958 (or (eq (selected-window) (minibuffer-window))
1959 input-method-use-echo-area)
1960 (eq (minibuffer-window) (frame-root-window)))
1961 ;; We are using another frame for the guidance.
1962 (if (frame-live-p quail-guidance-frame)
1963 (delete-frame quail-guidance-frame))
1964 (if (buffer-live-p quail-guidance-buf)
1965 (kill-buffer quail-guidance-buf))))
1989 1966
1990 (defun quail-update-guidance () 1967 (defun quail-update-guidance ()
1991 "Update the Quail guidance buffer and completion buffer (if displayed now)." 1968 "Update the Quail guidance buffer and completion buffer (if displayed now)."
1992 ;; Update guidance buffer. 1969 ;; Update the guidance string.
1993 (if (quail-require-guidance-buf) 1970 (when (quail-require-guidance-buf)
1994 (let ((guidance (quail-guidance))) 1971 (let ((guidance (quail-guidance)))
1995 (unless (and (eq (selected-frame) (window-frame (minibuffer-window))) 1972 (cond ((or (eq guidance t)
1996 (eq (selected-frame) (window-frame quail-guidance-win))) 1973 (consp guidance))
1997 ;; The guidance window is not shown in this frame, show it. 1974 ;; Show the current possible translations.
1998 (quail-show-guidance-buf)) 1975 (setq quail-guidance-str
1999 (cond ((or (eq guidance t) 1976 (quail-get-translations)))
2000 (consp guidance)) 1977 ((null guidance)
2001 ;; Show the current possible translations. 1978 ;; Show the current input keys.
2002 (quail-show-translations)) 1979 (let ((key quail-current-key))
2003 ((null guidance) 1980 (if (quail-kbd-translate)
2004 ;; Show the current input keys. 1981 (setq key (quail-keyseq-translate key)))
2005 (let ((key quail-current-key)) 1982 (setq quail-guidance-str (if (stringp key) key (string key)))))
2006 (if (quail-kbd-translate) 1983 (t
2007 (setq key (quail-keyseq-translate key))) 1984 (setq quail-guidance-str " ")))))
2008 (with-current-buffer quail-guidance-buf
2009 (erase-buffer)
2010 (insert key)))))
2011 ;; Make sure the height of the guidance window is OK --
2012 ;; sometimes, if the minibuffer window expands due to user
2013 ;; input (for instance if the newly inserted character is in a
2014 ;; different font), it will cause the guidance window to be
2015 ;; only partially visible. We force a redisplay first because
2016 ;; this automatic expansion doesn't happen until then, and we
2017 ;; want to see the window sizes after the expansion.
2018 (sit-for 0)
2019 (fit-window-to-buffer quail-guidance-win nil
2020 (window-height quail-guidance-win))))
2021 1985
2022 ;; Update completion buffer if displayed now. We highlight the 1986 ;; Update completion buffer if displayed now. We highlight the
2023 ;; selected candidate string in *Completion* buffer if any. 1987 ;; selected candidate string in *Completion* buffer if any.
2024 (let ((win (get-buffer-window quail-completion-buf)) 1988 (let ((win (get-buffer-window quail-completion-buf))
2025 key str pos) 1989 key str pos)
2034 (goto-char (point-min)) 1998 (goto-char (point-min))
2035 (if (null (search-forward (concat " " key ":") nil t)) 1999 (if (null (search-forward (concat " " key ":") nil t))
2036 (delete-overlay quail-overlay) 2000 (delete-overlay quail-overlay)
2037 (setq pos (point)) 2001 (setq pos (point))
2038 (if (and str (search-forward (concat "." str) nil t)) 2002 (if (and str (search-forward (concat "." str) nil t))
2039 (move-overlay quail-overlay (1+ (match-beginning 0)) (point)) 2003 (move-overlay quail-overlay (1+ (match-beginning 0)) (point))
2040 (move-overlay quail-overlay (match-beginning 0) (point))) 2004 (move-overlay quail-overlay (match-beginning 0) (point)))
2041 ;; Now POS points end of KEY and (point) points end of STR. 2005 ;; Now POS points end of KEY and (point) points end of STR.
2042 (if (pos-visible-in-window-p (point) win) 2006 (if (pos-visible-in-window-p (point) win)
2043 ;; STR is already visible. 2007 ;; STR is already visible.
2044 nil 2008 nil
2045 ;; We want to make both KEY and STR visible, but if the 2009 ;; We want to make both KEY and STR visible, but if the
2049 (set-window-start win (point)) 2013 (set-window-start win (point))
2050 (if (not (pos-visible-in-window-p pos win)) 2014 (if (not (pos-visible-in-window-p pos win))
2051 (set-window-start win pos)) 2015 (set-window-start win pos))
2052 )))))) 2016 ))))))
2053 2017
2054 (defun quail-show-translations () 2018 (defun quail-get-translations ()
2055 "Show the current possible translations." 2019 "Return a string containing the current possible translations."
2056 (let* ((key quail-current-key) 2020 (let ((map (quail-lookup-key quail-current-key))
2057 (map (quail-lookup-key quail-current-key)) 2021 (str (copy-sequence quail-current-key)))
2058 (current-translations quail-current-translations))
2059 (if quail-current-translations 2022 (if quail-current-translations
2060 (quail-update-current-translations)) 2023 (quail-update-current-translations))
2061 (with-current-buffer quail-guidance-buf 2024
2062 (erase-buffer) 2025 ;; Show the current key.
2063 2026 (let ((guidance (quail-guidance)))
2064 ;; Show the current key. 2027 (if (listp guidance)
2065 (let ((guidance (quail-guidance))) 2028 ;; We must replace thetyped key with the specified PROMPTKEY.
2066 (if (listp guidance) 2029 (dotimes (i (length str))
2067 ;; We must show the specified PROMPTKEY instead of the 2030 (let ((prompt-key (cdr (assoc (aref str i) guidance))))
2068 ;; actual typed keys. 2031 (if prompt-key
2069 (let ((i 0) 2032 (aset str i (aref prompt-key 0)))))))
2070 (len (length key))
2071 prompt-key)
2072 (while (< i len)
2073 (setq prompt-key (cdr (assoc (aref key i) guidance)))
2074 (insert (or prompt-key (aref key i)))
2075 (setq i (1+ i))))
2076 (insert key)))
2077 2033
2078 ;; Show followable keys. 2034 ;; Show followable keys.
2079 (if (and (> (length key) 0) (cdr map)) 2035 (if (and (> (length quail-current-key) 0) (cdr map))
2080 (let ((keys (mapcar (function (lambda (x) (car x))) 2036 (setq str
2081 (cdr map)))) 2037 (format "%s[%s]"
2082 (setq keys (sort keys '<)) 2038 str
2083 (insert "[") 2039 (concat (sort (mapcar (function (lambda (x) (car x)))
2084 (while keys 2040 (cdr map))
2085 (insert (car keys)) 2041 '<)))))
2086 (setq keys (cdr keys)))
2087 (insert "]")))
2088
2089 ;; Show list of translations. 2042 ;; Show list of translations.
2090 (if (and current-translations 2043 (if (and quail-current-translations
2091 (not (quail-deterministic))) 2044 (not (quail-deterministic)))
2092 (let* ((indices (car current-translations)) 2045 (let* ((indices (car quail-current-translations))
2093 (cur (car indices)) 2046 (cur (car indices))
2094 (start (nth 1 indices)) 2047 (start (nth 1 indices))
2095 (end (nth 2 indices)) 2048 (end (nth 2 indices))
2096 (idx start)) 2049 (idx start))
2097 (indent-to (- quail-guidance-translations-starting-column 7)) 2050 (if (< (string-width str)
2098 (insert (format "(%02d/"(nth 3 indices)) 2051 (- quail-guidance-translations-starting-column 7))
2099 (if (nth 4 indices) 2052 (setq str
2100 (format "%02d)" (nth 4 indices)) 2053 (concat str
2101 "??)")) 2054 (make-string
2055 (- quail-guidance-translations-starting-column
2056 7 (string-width str))
2057 32))))
2058 (setq str (format "%s(%02d/%s)"
2059 str (nth 3 indices)
2060 (if (nth 4 indices)
2061 (format "%02d" (nth 4 indices))
2062 "??")))
2102 (while (< idx end) 2063 (while (< idx end)
2103 (insert (format " %d." (if (= (- idx start) 9) 0 2064 (let ((len (length str))
2104 (1+ (- idx start))))) 2065 (trans (aref (cdr quail-current-translations) idx)))
2105 (let ((pos (point))) 2066 (or (stringp trans)
2106 (insert (aref (cdr current-translations) idx)) 2067 (setq trans (string trans)))
2068 (setq str (format "%s %d.%s"
2069 str
2070 (if (= (- idx start) 9) 0
2071 (1+ (- idx start)))
2072 trans))
2107 (if (= idx cur) 2073 (if (= idx cur)
2108 (move-overlay quail-overlay pos (point)))) 2074 (put-text-property (+ len 3) (length str)
2109 (setq idx (1+ idx))))) 2075 'face 'highlight str))
2110 ))) 2076 (setq idx (1+ idx))))))
2077
2078 str))
2111 2079
2112 (defvar quail-completion-max-depth 5 2080 (defvar quail-completion-max-depth 5
2113 "The maximum depth of Quail completion list.") 2081 "The maximum depth of Quail completion list.")
2114 2082
2115 (defun quail-completion () 2083 (defun quail-completion ()