;;; quail.el --- provides simple input method for multilingual text
-;; Copyright (C) 1997, 1998, 2000, 2001, 2002 Free Software Foundation, Inc.
-;; Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2003, 2004
+;; Copyright (C) 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005,
+;; 2006, 2007 Free Software Foundation, Inc.
+;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+;; 2005, 2006, 2007
;; National Institute of Advanced Industrial Science and Technology (AIST)
;; Registration Number H14PRO021
Optional 6th arg PROPS is a property list annotating TRANS. See the
function `quail-define-rules' for the detail."
- (if (null (stringp key))
- "Invalid Quail key `%s'" key)
+ (if (not (or (stringp key) (vectorp key)))
+ (error "Invalid Quail key `%s'" key))
(if (not (or (numberp trans) (stringp trans) (vectorp trans)
(consp trans)
(symbolp trans)
(or (and (consp def) (aref (cdr def) (car (car def))))
def
(and (> len 1)
- (let ((str (quail-get-current-str
- (1- len)
- (quail-map-definition (quail-lookup-key
- quail-current-key (1- len))))))
+ (let* ((str (quail-get-current-str
+ (1- len)
+ (quail-map-definition (quail-lookup-key
+ quail-current-key (1- len)))))
+ (substr1 (substring quail-current-key (1- len) len))
+ (str1 (and (quail-deterministic)
+ (quail-get-current-str
+ 1
+ (quail-map-definition (quail-lookup-key
+ substr1 1))))))
(if str
(concat (if (stringp str) str (char-to-string str))
- (substring quail-current-key (1- len) len)))))))
+ (if str1
+ (if (stringp str1) str1 (char-to-string str1))
+ substr1)))))))
(defvar quail-guidance-translations-starting-column 20)
;; And, we can terminate the current translation.
t)
+ ((quail-deterministic)
+ ;; No way to handle the last character in this context.
+ ;; Commit the longest successfully translated characters, and
+ ;; handle the remaining characters in a new loop.
+ (setq def nil)
+ (while (and (not def) (> len 1))
+ (setq len (1- len))
+ (setq def (quail-map-definition
+ (quail-lookup-key quail-current-key len))))
+ (if def (setq quail-current-str
+ (quail-get-current-str len def))
+ (setq quail-current-str (aref quail-current-key 0)))
+ len)
+
(t
;; No way to handle the last character in this context.
(setq def (quail-map-definition
(let ((default-enable-multibyte-characters enable-multibyte-characters))
(setq quail-completion-buf (get-buffer-create "*Quail Completions*")))
(with-current-buffer quail-completion-buf
+ (setq buffer-read-only t)
(setq quail-overlay (make-overlay 1 1))
(overlay-put quail-overlay 'face 'highlight))))
(minibuffer-scroll-window nil))
(scroll-other-window)))
(setq quail-current-key key)
- (erase-buffer)
- (insert "Possible completion and corresponding characters are:\n")
- (quail-completion-1 key map 1)
+ (let ((inhibit-read-only t))
+ (erase-buffer)
+ (insert "Possible completion and corresponding characters are:\n")
+ (quail-completion-1 key map 1)
+ (set-buffer-modified-p nil))
(goto-char (point-min))
(display-buffer (current-buffer))
(setq require-update t)))
(aset table char (cons key elt)))
(or (string= key elt)
(aset table char (list key elt))))
- (aset table char key))))
+ (aset table char key))
+ (if (and translation-table-for-input
+ (setq char (aref translation-table-for-input char)))
+ (let ((translation-table-for-input nil))
+ (quail-store-decode-map-key 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
(quail-gen-decode-map1 (cdr elt) (string (car elt)) table))
table))
+;; Check if CHAR equals to TARGET while also trying to translate CHAR
+;; by translation-table-for-input.
+
+(defsubst quail-char-equal-p (char target)
+ (or (= char target)
+ (and translation-table-for-input
+ (setq char (aref translation-table-for-input char))
+ (= char target))))
+
;; 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
(found-here nil))
(cond ((stringp trans)
(setq found-here
- (and (= (length trans) 1) (= (aref trans 0) char))))
+ (and (= (length trans) 1)
+ (quail-char-equal-p (aref trans 0) char))))
((or (vectorp trans) (consp trans))
(if (consp trans)
(setq trans (cdr trans)))
(dotimes (i (length trans))
(let ((target (aref trans i)))
(if (integerp target)
- (if (= target char)
+ (if (quail-char-equal-p target char)
(throw 'tag t))
(if (and (= (length target) 1)
- (= (aref target 0) char))
+ (quail-char-equal-p (aref target 0) char))
(throw 'tag t))))))))
((integerp trans)
- (if (= trans char)
- (setq found-here t))))
+ (setq found-here (quail-char-equal-p trans char))))
(if found-here
(setq key-list (cons key key-list)))
(if (> (length key) 1)
char key-list))))
key-list))
+;; If non-nil, the value has the form (QUAIL-MAP . CODING-SYSTEM)
+;; where QUAIL-MAP is a quail-map of which decode map was generated
+;; while buffer-file-coding-system was CODING-SYSTEM.
+
+(defvar quail-decode-map-generated nil)
+
(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))))
+ (let ((decode-map (or (and (or (not quail-decode-map-generated)
+ (and (eq (car quail-decode-map-generated) (quail-map))
+ (eq (cdr quail-decode-map-generated)
+ (or buffer-file-coding-system t))))
+ (quail-decode-map))
+ (let ((map (quail-gen-decode-map)))
+ (setq quail-decode-map-generated
+ (cons (quail-map) (or buffer-file-coding-system t)))
+ (setcar (nthcdr 10 quail-current-package) map)
+ map)))
(key-list nil))
(if (consp decode-map)
(let ((str (string char)))
(interactive)
(or current-input-method
(error "No input method is activated"))
+ (or (assoc current-input-method quail-package-alist)
+ (error "The current input method does not use Quail"))
(let* ((char (following-char))
(key-list (quail-find-key char)))
(cond ((consp key-list)