[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] Changes to emacs/lisp/international/quail.el [emacs-unicod
From: |
Miles Bader |
Subject: |
[Emacs-diffs] Changes to emacs/lisp/international/quail.el [emacs-unicode-2] |
Date: |
Mon, 28 Jun 2004 04:41:07 -0400 |
Index: emacs/lisp/international/quail.el
diff -c emacs/lisp/international/quail.el:1.130.2.2
emacs/lisp/international/quail.el:1.130.2.3
*** emacs/lisp/international/quail.el:1.130.2.2 Fri Apr 16 12:50:30 2004
--- emacs/lisp/international/quail.el Mon Jun 28 07:29:47 2004
***************
*** 1043,1051 ****
The installed decode map can be referred by the function `quail-decode-map'."
(if (null quail-current-package)
(error "No current Quail package"))
! (if (not (and (consp decode-map) (eq (car decode-map) 'decode-map)))
! (error "Invalid Quail decode map `%s'" decode-map))
! (setcar (nthcdr 10 quail-current-package) decode-map))
;;;###autoload
(defun quail-defrule (key translation &optional name append)
--- 1043,1055 ----
The installed decode map can be referred by the function `quail-decode-map'."
(if (null quail-current-package)
(error "No current Quail package"))
! (if (if (consp decode-map)
! (eq (car decode-map) 'decode-map)
! (if (char-table-p decode-map)
! (eq (char-table-subtype decode-map) 'quail-decode-map)))
! (setcar (nthcdr 10 quail-current-package) decode-map)
! (error "Invalid Quail decode map `%s'" decode-map)))
!
;;;###autoload
(defun quail-defrule (key translation &optional name append)
***************
*** 1218,1224 ****
(t
(error "Invalid object in Quail map: %s" def))))
! (defun quail-lookup-key (key &optional len)
"Lookup KEY of length LEN in the current Quail map and return the
definition.
The returned value is a Quail map specific to KEY."
(or len
--- 1222,1228 ----
(t
(error "Invalid object in Quail map: %s" def))))
! (defun quail-lookup-key (key &optional len not-reset-indices)
"Lookup KEY of length LEN in the current Quail map and return the
definition.
The returned value is a Quail map specific to KEY."
(or len
***************
*** 1256,1262 ****
(if (and (consp translation) (vectorp (cdr translation)))
(progn
(setq quail-current-translations translation)
! (if (quail-forget-last-selection)
(setcar (car quail-current-translations) 0))))))
;; We may have to reform cdr part of MAP.
(if (and (cdr map) (functionp (cdr map)))
--- 1260,1266 ----
(if (and (consp translation) (vectorp (cdr translation)))
(progn
(setq quail-current-translations translation)
! (if (and (not not-reset-indices) (quail-forget-last-selection))
(setcar (car quail-current-translations) 0))))))
;; We may have to reform cdr part of MAP.
(if (and (cdr map) (functionp (cdr map)))
***************
*** 1512,1517 ****
--- 1516,1543 ----
(let (pos)
(quail-delete-region)
(setq pos (point))
+ (or enable-multibyte-characters
+ (let (char)
+ (if (stringp quail-current-str)
+ (catch 'tag
+ (mapc #'(lambda (ch)
+ (when (/= (unibyte-char-to-multibyte
+ (multibyte-char-to-unibyte ch))
+ ch)
+ (setq char ch)
+ (throw 'tag nil)))
+ quail-current-str))
+ (if (/= (unibyte-char-to-multibyte
+ (multibyte-char-to-unibyte quail-current-str))
+ quail-current-str)
+ (setq char quail-current-str)))
+ (when char
+ (message "Can't input %c in the current unibyte buffer" char)
+ (ding)
+ (sit-for 2)
+ (message nil)
+ (setq quail-current-str nil)
+ (throw 'quail-tag nil))))
(insert quail-current-str)
(move-overlay quail-overlay pos (point))
(if (overlayp quail-conv-overlay)
***************
*** 2009,2015 ****
(defun quail-get-translations ()
"Return a string containing the current possible translations."
! (let ((map (quail-lookup-key quail-current-key))
(str (copy-sequence quail-current-key)))
(if quail-current-translations
(quail-update-current-translations))
--- 2035,2041 ----
(defun quail-get-translations ()
"Return a string containing the current possible translations."
! (let ((map (quail-lookup-key quail-current-key nil t))
(str (copy-sequence quail-current-key)))
(if quail-current-translations
(quail-update-current-translations))
***************
*** 2080,2086 ****
(quail-setup-completion-buf)
(let ((win (get-buffer-window quail-completion-buf 'visible))
(key quail-current-key)
! (map (quail-lookup-key quail-current-key))
(require-update nil))
(with-current-buffer quail-completion-buf
(if (and win
--- 2106,2112 ----
(quail-setup-completion-buf)
(let ((win (get-buffer-window quail-completion-buf 'visible))
(key quail-current-key)
! (map (quail-lookup-key quail-current-key nil t))
(require-update nil))
(with-current-buffer quail-completion-buf
(if (and win
***************
*** 2556,2561 ****
--- 2582,2724 ----
(quail-update-guidance)
))))
+ ;; Add KEY (string) to the element of TABLE (char-table) for CHAR if
+ ;; it is not yet stored. As a result, the element is a string or a
+ ;; list of strings.
+
+ (defsubst quail-store-decode-map-key (table char key)
+ (let ((elt (aref table char)))
+ (if elt
+ (if (consp elt)
+ (or (member key elt)
+ (aset table char (cons key elt)))
+ (or (string= key elt)
+ (aset table char (list key elt))))
+ (aset table char key))))
+
+ ;; Helper function for quail-gen-decode-map. Store key strings to
+ ;; type each character under MAP in TABLE (char-table). MAP is an
+ ;; element of the current Quail map reached by typing keys in KEY
+ ;; (string).
+
+ (defun quail-gen-decode-map1 (map key table)
+ (when (and (consp map) (listp (cdr map)))
+ (let ((trans (car map)))
+ (cond ((integerp trans)
+ (quail-store-decode-map-key table trans key))
+ ((stringp trans)
+ (dotimes (i (length trans))
+ (quail-store-decode-map-key table (aref trans i) key)))
+ ((or (vectorp trans)
+ (and (consp trans)
+ (setq trans (cdr trans))))
+ (dotimes (i (length trans))
+ (let ((elt (aref trans i)))
+ (if (stringp elt)
+ (if (= (length elt) 1)
+ (quail-store-decode-map-key table (aref elt 0) key))
+ (quail-store-decode-map-key table elt key)))))))
+ (if (> (length key) 1)
+ (dolist (elt (cdr map))
+ (quail-gen-decode-map1 (cdr elt) key table))
+ (dolist (elt (cdr map))
+ (quail-gen-decode-map1 (cdr elt) (format "%s%c" key (car elt))
+ table)))))
+
+ (put 'quail-decode-map 'char-table-extra-slots 0)
+
+ ;; Generate a halfly-cooked decode map (char-table) for the current
+ ;; Quail map. An element for a character C is a key string or a list
+ ;; of a key strings to type to input C. The lenth of key string is at
+ ;; most 2. If it is 2, more keys may be required to input C.
+
+ (defun quail-gen-decode-map ()
+ (let ((table (make-char-table 'quail-decode-map nil)))
+ (dolist (elt (cdr (quail-map)))
+ (quail-gen-decode-map1 (cdr elt) (string (car elt)) table))
+ table))
+
+ ;; Helper function for quail-find-key. Prepend key strings to type
+ ;; for inputting CHAR by the current input method to KEY-LIST and
+ ;; return the result. MAP is an element of the current Quail map
+ ;; reached by typing keys in KEY.
+
+ (defun quail-find-key1 (map key char key-list)
+ (let ((trans (car map))
+ (found-here nil))
+ (cond ((stringp trans)
+ (setq found-here
+ (and (= (length trans) 1) (= (aref trans 0) char))))
+ ((or (vectorp trans) (consp trans))
+ (if (consp trans)
+ (setq trans (cdr trans)))
+ (setq found-here
+ (catch 'tag
+ (dotimes (i (length trans))
+ (let ((target (aref trans i)))
+ (if (integerp target)
+ (if (= target char)
+ (throw 'tag t))
+ (if (and (= (length target) 1)
+ (= (aref target 0) char))
+ (throw 'tag t))))))))
+ ((integerp trans)
+ (if (= trans char)
+ (setq found-here t))))
+ (if found-here
+ (setq key-list (cons key key-list)))
+ (if (> (length key) 1)
+ (dolist (elt (cdr map))
+ (setq key-list
+ (quail-find-key1 (cdr elt) (format "%s%c" key (car elt))
+ char key-list))))
+ key-list))
+
+ (defun quail-find-key (char)
+ "Return a list of keys to type to input CHAR in the current input method.
+ If CHAR is an ASCII character and can be input by typing itself, return t."
+ (let ((decode-map (or (quail-decode-map)
+ (setcar (nthcdr 10 quail-current-package)
+ (quail-gen-decode-map))))
+ (key-list nil))
+ (if (consp decode-map)
+ (let ((str (string char)))
+ (mapc #'(lambda (elt)
+ (if (string= str (car elt))
+ (setq key-list (cons (cdr elt) key-list))))
+ (cdr decode-map)))
+ (let ((key-head (aref decode-map char)))
+ (if (stringp key-head)
+ (setq key-list (quail-find-key1
+ (quail-lookup-key key-head nil t)
+ key-head char nil))
+ (mapc #'(lambda (elt)
+ (setq key-list
+ (quail-find-key1
+ (quail-lookup-key elt nil t) elt char key-list)))
+ key-head))))
+ (or key-list
+ (and (< char 128)
+ (not (quail-lookup-key (string char) 1))))))
+
+ (defun quail-show-key ()
+ "Show a list of key strings to type for inputting a character at point."
+ (interactive)
+ (or current-input-method
+ (error "No input method is activated"))
+ (let* ((char (following-char))
+ (key-list (quail-find-key char)))
+ (cond ((consp key-list)
+ (message "To input `%c', type \"%s\""
+ char
+ (mapconcat 'identity key-list "\", \"")))
+ ((eq key-list t)
+ (message "To input `%s', just type it"
+ (single-key-description char)))
+ (t
+ (message "%c can't be input by the current input method" char)))))
+
+
;; Quail map generator from state transition table.
(defun quail-map-from-table (table)
***************
*** 2661,2667 ****
(translation-list nil)
map)
(while (> len 0)
! (setq map (quail-lookup-key key len)
len (1- len))
(if map
(let* ((def (quail-map-definition map))
--- 2824,2830 ----
(translation-list nil)
map)
(while (> len 0)
! (setq map (quail-lookup-key key len t)
len (1- len))
(if map
(let* ((def (quail-map-definition map))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] Changes to emacs/lisp/international/quail.el [emacs-unicode-2],
Miles Bader <=