Function: quail-define-rules

quail-define-rules is an autoloaded macro defined in quail.el.gz.

Signature

(quail-define-rules &rest RULES)

Documentation

Define translation rules of the current Quail package.

Each argument is a list of KEY and TRANSLATION. KEY is a string meaning a sequence of keystrokes to be translated. TRANSLATION is a character, a string, a vector, a Quail map, or a function. If it is a character, it is the sole translation of KEY. If it is a string, each character is a candidate for the translation. If it is a vector, each element (string or character) is a candidate
  for the translation.
In these cases, a key specific Quail map is generated and assigned to KEY.

If TRANSLATION is a Quail map or a function symbol which returns a Quail map,
 it is used to handle KEY.

The first argument may be an alist of annotations for the following rules. Each element has the form (ANNOTATION . VALUE), where ANNOTATION is a symbol indicating the annotation type. Currently the following annotation types are supported.

  append -- the value non-nil means that the following rules should
be appended to the rules of the current Quail package.

  face -- the value is a face to use for displaying TRANSLATIONs in
candidate list.

  advice -- the value is a function to call after one of RULES is
selected. The function is called with one argument, the
selected TRANSLATION string, after the TRANSLATION is
inserted.

  no-decode-map --- the value non-nil means that decoding map is not
generated for the following translations.

Source Code

;; Defined in /usr/src/emacs/lisp/international/quail.el.gz
;;;###autoload
(defmacro quail-define-rules (&rest rules)
  "Define translation rules of the current Quail package.
Each argument is a list of KEY and TRANSLATION.
KEY is a string meaning a sequence of keystrokes to be translated.
TRANSLATION is a character, a string, a vector, a Quail map, or a function.
If it is a character, it is the sole translation of KEY.
If it is a string, each character is a candidate for the translation.
If it is a vector, each element (string or character) is a candidate
  for the translation.
In these cases, a key specific Quail map is generated and assigned to KEY.

If TRANSLATION is a Quail map or a function symbol which returns a Quail map,
 it is used to handle KEY.

The first argument may be an alist of annotations for the following
rules.  Each element has the form (ANNOTATION . VALUE), where
ANNOTATION is a symbol indicating the annotation type.  Currently
the following annotation types are supported.

  append -- the value non-nil means that the following rules should
	be appended to the rules of the current Quail package.

  face -- the value is a face to use for displaying TRANSLATIONs in
	candidate list.

  advice -- the value is a function to call after one of RULES is
	selected.  The function is called with one argument, the
	selected TRANSLATION string, after the TRANSLATION is
	inserted.

  no-decode-map --- the value non-nil means that decoding map is not
	generated for the following translations."
  (let ((l rules)
	append no-decode-map props)
    ;; If the first argument is an alist of annotations, handle them.
    (if (consp (car (car l)))
	(let ((annotations (car l)))
	  (setq append (assq 'append annotations))
	  (if append
	      (setq annotations (delete append annotations)
		    append (cdr append)))
	  (setq no-decode-map (assq 'no-decode-map annotations))
	  (if no-decode-map
	      (setq annotations (delete no-decode-map annotations)
		    no-decode-map (cdr no-decode-map)))
	  ;; Convert the remaining annotations to property list PROPS.
	  (dolist (annotation annotations)
	    (setq props
		  (cons (car annotation)
			(cons (cdr annotation)
			      props))))
	  (setq l (cdr l))))
    ;; Process the remaining arguments one by one.
    (if append
	;; There's no way to add new rules at compiling time.
	`(let ((tail ',l)
	       (map (quail-map))
	       (decode-map (and (quail-decode-map) (not ,no-decode-map)))
	       (properties ',props)
	       key trans)
	   (while tail
	     (setq key (car (car tail)) trans (car (cdr (car tail)))
		   tail (cdr tail))
	     (quail-defrule-internal key trans map t decode-map properties)))
      ;; We can build up quail map and decode map at compiling time.
      (let ((map (list nil))
	    (decode-map (if (not no-decode-map) (list 'decode-map)))
	    key trans)
	(dolist (el l)
	  (setq key (car el) trans (car (cdr el)))
	  (quail-defrule-internal key trans map t decode-map props))
	`(if (prog1 (quail-decode-map)
	       (quail-install-map ',map))
	   (quail-install-decode-map ',decode-map))))))