comparison lisp/international/quail.el @ 75560:607b2d435418

(quail-store-decode-map-key): Store a translated character too. (quail-char-equal-p): New function. (quail-find-key1): Check character equality by quail-char-equal-p. (quail-decode-map-generated): New variable. (quail-find-key): Check quail-decode-map-generated and re-generate a decode map if necessary.
author Kenichi Handa <handa@m17n.org>
date Wed, 31 Jan 2007 00:44:34 +0000
parents e3694f1cb928
children 2a562d836178
comparison
equal deleted inserted replaced
75559:305f8aa6d4fe 75560:607b2d435418
2632 (if (consp elt) 2632 (if (consp elt)
2633 (or (member key elt) 2633 (or (member key elt)
2634 (aset table char (cons key elt))) 2634 (aset table char (cons key elt)))
2635 (or (string= key elt) 2635 (or (string= key elt)
2636 (aset table char (list key elt)))) 2636 (aset table char (list key elt))))
2637 (aset table char key)))) 2637 (aset table char key))
2638 (if (and translation-table-for-input
2639 (setq char (aref translation-table-for-input char)))
2640 (let ((translation-table-for-input nil))
2641 (quail-store-decode-map-key table char key)))))
2638 2642
2639 ;; Helper function for quail-gen-decode-map. Store key strings to 2643 ;; Helper function for quail-gen-decode-map. Store key strings to
2640 ;; type each character under MAP in TABLE (char-table). MAP is an 2644 ;; type each character under MAP in TABLE (char-table). MAP is an
2641 ;; element of the current Quail map reached by typing keys in KEY 2645 ;; element of the current Quail map reached by typing keys in KEY
2642 ;; (string). 2646 ;; (string).
2676 (let ((table (make-char-table 'quail-decode-map nil))) 2680 (let ((table (make-char-table 'quail-decode-map nil)))
2677 (dolist (elt (cdr (quail-map))) 2681 (dolist (elt (cdr (quail-map)))
2678 (quail-gen-decode-map1 (cdr elt) (string (car elt)) table)) 2682 (quail-gen-decode-map1 (cdr elt) (string (car elt)) table))
2679 table)) 2683 table))
2680 2684
2685 ;; Check if CHAR equals to TARGET while also trying to translate CHAR
2686 ;; by translation-table-for-input.
2687
2688 (defsubst quail-char-equal-p (char target)
2689 (or (= char target)
2690 (and translation-table-for-input
2691 (setq char (aref translation-table-for-input char))
2692 (= char target))))
2693
2681 ;; Helper function for quail-find-key. Prepend key strings to type 2694 ;; Helper function for quail-find-key. Prepend key strings to type
2682 ;; for inputting CHAR by the current input method to KEY-LIST and 2695 ;; for inputting CHAR by the current input method to KEY-LIST and
2683 ;; return the result. MAP is an element of the current Quail map 2696 ;; return the result. MAP is an element of the current Quail map
2684 ;; reached by typing keys in KEY. 2697 ;; reached by typing keys in KEY.
2685 2698
2686 (defun quail-find-key1 (map key char key-list) 2699 (defun quail-find-key1 (map key char key-list)
2687 (let ((trans (car map)) 2700 (let ((trans (car map))
2688 (found-here nil)) 2701 (found-here nil))
2689 (cond ((stringp trans) 2702 (cond ((stringp trans)
2690 (setq found-here 2703 (setq found-here
2691 (and (= (length trans) 1) (= (aref trans 0) char)))) 2704 (and (= (length trans) 1)
2705 (quail-char-equal-p (aref trans 0) char))))
2692 ((or (vectorp trans) (consp trans)) 2706 ((or (vectorp trans) (consp trans))
2693 (if (consp trans) 2707 (if (consp trans)
2694 (setq trans (cdr trans))) 2708 (setq trans (cdr trans)))
2695 (setq found-here 2709 (setq found-here
2696 (catch 'tag 2710 (catch 'tag
2697 (dotimes (i (length trans)) 2711 (dotimes (i (length trans))
2698 (let ((target (aref trans i))) 2712 (let ((target (aref trans i)))
2699 (if (integerp target) 2713 (if (integerp target)
2700 (if (= target char) 2714 (if (quail-char-equal-p target char)
2701 (throw 'tag t)) 2715 (throw 'tag t))
2702 (if (and (= (length target) 1) 2716 (if (and (= (length target) 1)
2703 (= (aref target 0) char)) 2717 (quail-char-equal-p (aref target 0) char))
2704 (throw 'tag t)))))))) 2718 (throw 'tag t))))))))
2705 ((integerp trans) 2719 ((integerp trans)
2706 (if (= trans char) 2720 (setq found-here (quail-char-equal-p trans char))))
2707 (setq found-here t))))
2708 (if found-here 2721 (if found-here
2709 (setq key-list (cons key key-list))) 2722 (setq key-list (cons key key-list)))
2710 (if (> (length key) 1) 2723 (if (> (length key) 1)
2711 (dolist (elt (cdr map)) 2724 (dolist (elt (cdr map))
2712 (setq key-list 2725 (setq key-list
2713 (quail-find-key1 (cdr elt) (format "%s%c" key (car elt)) 2726 (quail-find-key1 (cdr elt) (format "%s%c" key (car elt))
2714 char key-list)))) 2727 char key-list))))
2715 key-list)) 2728 key-list))
2716 2729
2730 ;; If non-nil, the value has the form (QUAIL-MAP . CODING-SYSTEM)
2731 ;; where QUAIL-MAP is a quail-map of which decode map was generated
2732 ;; while buffer-file-coding-system was CODING-SYSTEM.
2733
2734 (defvar quail-decode-map-generated nil)
2735
2717 (defun quail-find-key (char) 2736 (defun quail-find-key (char)
2718 "Return a list of keys to type to input CHAR in the current input method. 2737 "Return a list of keys to type to input CHAR in the current input method.
2719 If CHAR is an ASCII character and can be input by typing itself, return t." 2738 If CHAR is an ASCII character and can be input by typing itself, return t."
2720 (let ((decode-map (or (quail-decode-map) 2739 (let ((decode-map (or (and (or (not quail-decode-map-generated)
2721 (setcar (nthcdr 10 quail-current-package) 2740 (and (eq (car quail-decode-map-generated) (quail-map))
2722 (quail-gen-decode-map)))) 2741 (eq (cdr quail-decode-map-generated)
2742 (or buffer-file-coding-system t))))
2743 (quail-decode-map))
2744 (let ((map (quail-gen-decode-map)))
2745 (setq quail-decode-map-generated
2746 (cons (quail-map) (or buffer-file-coding-system t)))
2747 (setcar (nthcdr 10 quail-current-package) map)
2748 map)))
2723 (key-list nil)) 2749 (key-list nil))
2724 (if (consp decode-map) 2750 (if (consp decode-map)
2725 (let ((str (string char))) 2751 (let ((str (string char)))
2726 (mapc #'(lambda (elt) 2752 (mapc #'(lambda (elt)
2727 (if (string= str (car elt)) 2753 (if (string= str (car elt))