changeset 23401:a83ca83c8626

(quail-defrule): New optional arg APPEND. (quail-defrule-internal): Fix bug of handling the argument APPEND.
author Kenichi Handa <handa@m17n.org>
date Thu, 08 Oct 1998 06:45:36 +0000
parents 8a51c720f8d7
children 6905813a49c6
files lisp/international/quail.el
diffstat 1 files changed, 21 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/international/quail.el	Thu Oct 08 06:45:36 1998 +0000
+++ b/lisp/international/quail.el	Thu Oct 08 06:45:36 1998 +0000
@@ -683,7 +683,7 @@
   (setcar (cdr (cdr quail-current-package)) map))
 
 ;;;###autoload
-(defun quail-defrule (key translation &optional name)
+(defun quail-defrule (key translation &optional name append)
   "Add one translation rule, KEY to TRANSLATION, in the current Quail package.
 KEY is a string meaning a sequence of keystrokes to be translated.
 TRANSLATION is a character, a string, a vector, a Quail map,
@@ -700,15 +700,19 @@
 
 If TRANSLATION is a Quail map or a function symbol which returns a Quail map,
  it is used to handle KEY.
-Optional argument NAME, if specified, says which Quail package
+
+Optional 3rd argument NAME, if specified, says which Quail package
 to define this translation rule in.  The default is to define it in the
-current Quail package."
+current Quail package.
+
+Optional 4th argument APPEND, if non-nil, appends TRANSLATION
+to the current translations for KEY instead of replacing them."
   (if name
       (let ((package (quail-package name)))
 	(if (null package)
 	    (error "No Quail package `%s'" name))
 	(setq quail-current-package package)))
-  (quail-defrule-internal key translation (quail-map)))
+  (quail-defrule-internal key translation (quail-map) append))
 
 ;;;###autoload
 (defun quail-defrule-internal (key trans map &optional append)
@@ -761,9 +765,19 @@
 		    (error "Quail key %s is too short" key)
 		  (setcdr entry trans))
 	      (setcdr entry (append trans (cdr map)))))
-	(if (and append (stringp (car map)) (stringp trans))
-	    (setcar map (concat (car map) trans))
-	  (setcar map trans))))))
+	(if (and (car map) append)
+	    (let ((prev (quail-get-translation (car map) key len)))
+	      (if (integerp prev)
+		  (setq prev (vector prev))
+		(setq prev (cdr prev)))
+	      (if (integerp trans)
+		  (setq trans (vector trans))
+		(if (stringp trans)
+		    (setq trans (string-to-vector trans))))
+	      (setq trans
+		    (cons (list 0 0 0 0 nil)
+			  (vconcat prev trans)))))
+	(setcar map trans)))))
 
 (defun quail-get-translation (def key len)
   "Return the translation specified as DEF for KEY of length LEN.