/[emacs]/emacs/lisp/international/quail.el
ViewVC logotype

Diff of /emacs/lisp/international/quail.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.130.2.2 by handa, Fri Apr 16 12:50:30 2004 UTC revision 1.130.2.3 by miles, Mon Jun 28 07:29:47 2004 UTC
# Line 1043  which to install MAP. Line 1043  which to install MAP.
1043  The installed decode map can be referred by the function `quail-decode-map'."  The installed decode map can be referred by the function `quail-decode-map'."
1044    (if (null quail-current-package)    (if (null quail-current-package)
1045        (error "No current Quail package"))        (error "No current Quail package"))
1046    (if (not (and (consp decode-map) (eq (car decode-map) 'decode-map)))    (if (if (consp decode-map)
1047        (error "Invalid Quail decode map `%s'" decode-map))            (eq (car decode-map) 'decode-map)
1048    (setcar (nthcdr 10 quail-current-package) decode-map))          (if (char-table-p decode-map)
1049                (eq (char-table-subtype decode-map) 'quail-decode-map)))
1050          (setcar (nthcdr 10 quail-current-package) decode-map)
1051        (error "Invalid Quail decode map `%s'" decode-map)))
1052    
1053    
1054  ;;;###autoload  ;;;###autoload
1055  (defun quail-defrule (key translation &optional name append)  (defun quail-defrule (key translation &optional name append)
# Line 1218  selected translation." Line 1222  selected translation."
1222     (t     (t
1223      (error "Invalid object in Quail map: %s" def))))      (error "Invalid object in Quail map: %s" def))))
1224    
1225  (defun quail-lookup-key (key &optional len)  (defun quail-lookup-key (key &optional len not-reset-indices)
1226    "Lookup KEY of length LEN in the current Quail map and return the definition.    "Lookup KEY of length LEN in the current Quail map and return the definition.
1227  The returned value is a Quail map specific to KEY."  The returned value is a Quail map specific to KEY."
1228    (or len    (or len
# Line 1256  The returned value is a Quail map specif Line 1260  The returned value is a Quail map specif
1260            (if (and (consp translation) (vectorp (cdr translation)))            (if (and (consp translation) (vectorp (cdr translation)))
1261                (progn                (progn
1262                  (setq quail-current-translations translation)                  (setq quail-current-translations translation)
1263                  (if (quail-forget-last-selection)                  (if (and (not not-reset-indices) (quail-forget-last-selection))
1264                      (setcar (car quail-current-translations) 0))))))                      (setcar (car quail-current-translations) 0))))))
1265      ;; We may have to reform cdr part of MAP.      ;; We may have to reform cdr part of MAP.
1266      (if (and (cdr map) (functionp (cdr map)))      (if (and (cdr map) (functionp (cdr map)))
# Line 1512  with more keys." Line 1516  with more keys."
1516        (let (pos)        (let (pos)
1517          (quail-delete-region)          (quail-delete-region)
1518          (setq pos (point))          (setq pos (point))
1519            (or enable-multibyte-characters
1520                (let (char)
1521                  (if (stringp quail-current-str)
1522                      (catch 'tag
1523                        (mapc #'(lambda (ch)
1524                                  (when (/= (unibyte-char-to-multibyte
1525                                             (multibyte-char-to-unibyte ch))
1526                                            ch)
1527                                      (setq char ch)
1528                                      (throw 'tag nil)))
1529                              quail-current-str))
1530                    (if (/= (unibyte-char-to-multibyte
1531                             (multibyte-char-to-unibyte quail-current-str))
1532                            quail-current-str)
1533                        (setq char quail-current-str)))
1534                  (when char
1535                    (message "Can't input %c in the current unibyte buffer" char)
1536                    (ding)
1537                    (sit-for 2)
1538                    (message nil)
1539                    (setq quail-current-str nil)
1540                    (throw 'quail-tag nil))))
1541          (insert quail-current-str)          (insert quail-current-str)
1542          (move-overlay quail-overlay pos (point))          (move-overlay quail-overlay pos (point))
1543          (if (overlayp quail-conv-overlay)          (if (overlayp quail-conv-overlay)
# Line 2009  minibuffer and the selected frame has no Line 2035  minibuffer and the selected frame has no
2035    
2036  (defun quail-get-translations ()  (defun quail-get-translations ()
2037    "Return a string containing the current possible translations."    "Return a string containing the current possible translations."
2038    (let ((map (quail-lookup-key quail-current-key))    (let ((map (quail-lookup-key quail-current-key nil t))
2039          (str (copy-sequence quail-current-key)))          (str (copy-sequence quail-current-key)))
2040      (if quail-current-translations      (if quail-current-translations
2041          (quail-update-current-translations))          (quail-update-current-translations))
# Line 2080  are shown (at most to the depth specifie Line 2106  are shown (at most to the depth specifie
2106    (quail-setup-completion-buf)    (quail-setup-completion-buf)
2107    (let ((win (get-buffer-window quail-completion-buf 'visible))    (let ((win (get-buffer-window quail-completion-buf 'visible))
2108          (key quail-current-key)          (key quail-current-key)
2109          (map (quail-lookup-key quail-current-key))          (map (quail-lookup-key quail-current-key nil t))
2110          (require-update nil))          (require-update nil))
2111      (with-current-buffer quail-completion-buf      (with-current-buffer quail-completion-buf
2112        (if (and win        (if (and win
# Line 2556  KEY BINDINGS FOR CONVERSION Line 2582  KEY BINDINGS FOR CONVERSION
2582            (quail-update-guidance)            (quail-update-guidance)
2583            ))))            ))))
2584    
2585    ;; Add KEY (string) to the element of TABLE (char-table) for CHAR if
2586    ;; it is not yet stored.  As a result, the element is a string or a
2587    ;; list of strings.
2588    
2589    (defsubst quail-store-decode-map-key (table char key)
2590      (let ((elt (aref table char)))
2591        (if elt
2592            (if (consp elt)
2593                (or (member key elt)
2594                    (aset table char (cons key elt)))
2595              (or (string= key elt)
2596                  (aset table char (list key elt))))
2597          (aset table char key))))
2598    
2599    ;; Helper function for quail-gen-decode-map.  Store key strings to
2600    ;; type each character under MAP in TABLE (char-table).  MAP is an
2601    ;; element of the current Quail map reached by typing keys in KEY
2602    ;; (string).
2603    
2604    (defun quail-gen-decode-map1 (map key table)
2605      (when (and (consp map) (listp (cdr map)))
2606        (let ((trans (car map)))
2607          (cond ((integerp trans)
2608                 (quail-store-decode-map-key table trans key))
2609                ((stringp trans)
2610                 (dotimes (i (length trans))
2611                   (quail-store-decode-map-key table (aref trans i) key)))
2612                ((or (vectorp trans)
2613                     (and (consp trans)
2614                          (setq trans (cdr trans))))
2615                 (dotimes (i (length trans))
2616                   (let ((elt (aref trans i)))
2617                     (if (stringp elt)
2618                         (if (= (length elt) 1)
2619                             (quail-store-decode-map-key table (aref elt 0) key))
2620                       (quail-store-decode-map-key table elt key)))))))
2621        (if (> (length key) 1)
2622            (dolist (elt (cdr map))
2623              (quail-gen-decode-map1 (cdr elt) key table))
2624          (dolist (elt (cdr map))
2625            (quail-gen-decode-map1 (cdr elt) (format "%s%c" key (car elt))
2626                                     table)))))
2627    
2628    (put 'quail-decode-map 'char-table-extra-slots 0)
2629    
2630    ;; Generate a halfly-cooked decode map (char-table) for the current
2631    ;; Quail map.  An element for a character C is a key string or a list
2632    ;; of a key strings to type to input C.  The lenth of key string is at
2633    ;; most 2.  If it is 2, more keys may be required to input C.
2634    
2635    (defun quail-gen-decode-map ()
2636      (let ((table (make-char-table 'quail-decode-map nil)))
2637        (dolist (elt (cdr (quail-map)))
2638          (quail-gen-decode-map1 (cdr elt) (string (car elt)) table))
2639        table))
2640    
2641    ;; Helper function for quail-find-key.  Prepend key strings to type
2642    ;; for inputting CHAR by the current input method to KEY-LIST and
2643    ;; return the result.  MAP is an element of the current Quail map
2644    ;; reached by typing keys in KEY.
2645    
2646    (defun quail-find-key1 (map key char key-list)
2647      (let ((trans (car map))
2648            (found-here nil))
2649        (cond ((stringp trans)
2650               (setq found-here
2651                     (and (= (length trans) 1) (= (aref trans 0) char))))
2652              ((or (vectorp trans) (consp trans))
2653               (if (consp trans)
2654                   (setq trans (cdr trans)))
2655               (setq found-here
2656                     (catch 'tag
2657                       (dotimes (i (length trans))
2658                         (let ((target (aref trans i)))
2659                           (if (integerp target)
2660                               (if (= target char)
2661                                   (throw 'tag t))
2662                             (if (and (= (length target) 1)
2663                                      (= (aref target 0) char))
2664                                 (throw 'tag t))))))))
2665                ((integerp trans)
2666                 (if (= trans char)
2667                     (setq found-here t))))
2668        (if found-here
2669            (setq key-list (cons key key-list)))
2670        (if (> (length key) 1)
2671            (dolist (elt (cdr map))
2672              (setq key-list
2673                    (quail-find-key1 (cdr elt) (format "%s%c" key (car elt))
2674                                         char key-list))))
2675        key-list))
2676    
2677    (defun quail-find-key (char)
2678      "Return a list of keys to type to input CHAR in the current input method.
2679    If CHAR is an ASCII character and can be input by typing itself, return t."
2680      (let ((decode-map (or (quail-decode-map)
2681                            (setcar (nthcdr 10 quail-current-package)
2682                                    (quail-gen-decode-map))))
2683            (key-list nil))
2684        (if (consp decode-map)
2685            (let ((str (string char)))
2686              (mapc #'(lambda (elt)
2687                        (if (string= str (car elt))
2688                            (setq key-list (cons (cdr elt) key-list))))
2689                    (cdr decode-map)))
2690          (let ((key-head (aref decode-map char)))
2691            (if (stringp key-head)
2692                (setq key-list (quail-find-key1
2693                                (quail-lookup-key key-head nil t)
2694                                key-head char nil))
2695              (mapc #'(lambda (elt)
2696                        (setq key-list
2697                              (quail-find-key1
2698                               (quail-lookup-key elt nil t) elt char key-list)))
2699                    key-head))))
2700        (or key-list
2701            (and (< char 128)
2702                 (not (quail-lookup-key (string char) 1))))))
2703    
2704    (defun quail-show-key ()
2705      "Show a list of key strings to type for inputting a character at point."
2706      (interactive)
2707      (or current-input-method
2708          (error "No input method is activated"))
2709      (let* ((char (following-char))
2710             (key-list (quail-find-key char)))
2711        (cond ((consp key-list)
2712               (message "To input `%c', type \"%s\""
2713                        char
2714                        (mapconcat 'identity key-list "\", \"")))
2715              ((eq key-list t)
2716               (message "To input `%s', just type it"
2717                        (single-key-description char)))
2718              (t
2719               (message "%c can't be input by the current input method" char)))))
2720    
2721    
2722  ;; Quail map generator from state transition table.  ;; Quail map generator from state transition table.
2723    
2724  (defun quail-map-from-table (table)  (defun quail-map-from-table (table)
# Line 2661  function `quail-install-map' (which see) Line 2824  function `quail-install-map' (which see)
2824           (translation-list nil)           (translation-list nil)
2825           map)           map)
2826      (while (> len 0)      (while (> len 0)
2827        (setq map (quail-lookup-key key len)        (setq map (quail-lookup-key key len t)
2828              len (1- len))              len (1- len))
2829        (if map        (if map
2830            (let* ((def (quail-map-definition map))            (let* ((def (quail-map-definition map))

Legend:
Removed from v.1.130.2.2  
changed lines
  Added in v.1.130.2.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26