Function: quail-translate-key

quail-translate-key is a byte-compiled function defined in quail.el.gz.

Signature

(quail-translate-key)

Documentation

Translate the current key sequence according to the current Quail map.

Return t if we can terminate the translation. Return nil if the current key sequence may be followed by more keys. Return number if we can't find any translation for the current key sequence. The number is the count of valid keys in the current sequence counting from the head.

Source Code

;; Defined in /usr/src/emacs/lisp/international/quail.el.gz
(defun quail-translate-key ()
  "Translate the current key sequence according to the current Quail map.
Return t if we can terminate the translation.
Return nil if the current key sequence may be followed by more keys.
Return number if we can't find any translation for the current key
sequence.  The number is the count of valid keys in the current
sequence counting from the head."
  (let* ((len (length quail-current-key))
	 (map (quail-lookup-key quail-current-key len))
	 def ch)
    (if map
	(let ((def (quail-map-definition map)))
	  (setq quail-current-str (quail-get-current-str len def))
	  ;; Return t only if we can terminate the current translation.
	  (and
	   ;; No alternative translations.
	   (or (null (consp def)) (= (length (cdr def)) 1))
	   ;; No translation for the longer key.
	   (null (cdr map))
	   ;; No shorter breaking point.
	   (or (null (quail-maximum-shortest))
	       (< len 3)
	       (null (quail-lookup-key quail-current-key (1- len)))
	       (null (quail-lookup-key
		      (substring quail-current-key -2 -1) 1)))))

      ;; There's no translation for the current key sequence.  Before
      ;; giving up, we must check two possibilities.
      (cond ((and
	      (quail-maximum-shortest)
	      (>= len 3)
	      (setq def (quail-map-definition
			 (quail-lookup-key quail-current-key (- len 2))))
	      (quail-lookup-key (substring quail-current-key -2) 2))
	     ;; Now the sequence is "...ABCD", which can be split into
	     ;; "...AB" and "CD..." to get valid translation.
	     ;; At first, get translation of "...AB".
	     (setq quail-current-str (quail-get-current-str (- len 2) def))
	     ;; Then, return the length of "...AB".
	     (- len 2))

	    ((and (> len 0)
		  (quail-lookup-key (substring quail-current-key 0 -1))
		  quail-current-translations
		  (not (quail-deterministic))
		  (setq ch (aref quail-current-key (1- len)))
		  (>= ch ?0) (<= ch ?9))
	     ;; A numeric key is entered to select a desirable translation.
	     (setq quail-current-key (substring quail-current-key 0 -1))
	     ;; We treat key 1,2..,9,0 as specifying 0,1,..8,9.
	     (setq ch (if (= ch ?0) 9 (- ch ?1)))
	     (quail-update-current-translations ch)
	     ;; 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
			(quail-lookup-key quail-current-key (1- len))))
	     (if def (setq quail-current-str
			   (quail-get-current-str (1- len) def)))
	     (1- len))))))