;;; quail.el --- provides simple input method for multilingual text
-;; Copyright (C) 1997-1998, 2000-2012 Free Software Foundation, Inc.
+;; Copyright (C) 1997-1998, 2000-2015 Free Software Foundation, Inc.
;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
;; 2005, 2006, 2007, 2008, 2009, 2010, 2011
;; National Institute of Advanced Industrial Science and Technology (AIST)
;;; Code:
(require 'help-mode)
-(eval-when-compile (require 'cl))
+(eval-when-compile (require 'cl-lib))
(defgroup quail nil
"Quail: multilingual input method."
documentation of `quail-keyboard-layout' and
`quail-keyboard-layout-standard' for more detail.
-SHOW-LAYOUT non-nil means the `quail-help' command should show
-the user's keyboard layout visually with translated characters.
-If KBD-TRANSLATE is set, it is desirable to set also this flag unless
-this package defines no translations for single character keys.
+SHOW-LAYOUT non-nil means the function `quail-help' (as used by
+the command `describe-input-method') should show the user's keyboard
+layout visually with translated characters. If KBD-TRANSLATE is
+set, it is desirable to also set this flag, unless this package
+defines no translations for single character keys.
CREATE-DECODE-MAP non-nil means decode map is also created. A decode
map is an alist of translations and corresponding original keys.
(setq translation-keymap (copy-keymap
(if simple quail-simple-translation-keymap
quail-translation-keymap)))
- (while translation-keys
- (define-key translation-keymap
- (car (car translation-keys)) (cdr (car translation-keys)))
- (setq translation-keys (cdr translation-keys))))
+ (dolist (trans translation-keys)
+ (define-key translation-keymap (car trans) (cdr trans))))
(setq translation-keymap
(if simple quail-simple-translation-keymap
quail-translation-keymap)))
(when conversion-keys
(setq conversion-keymap (copy-keymap quail-conversion-keymap))
- (while conversion-keys
- (define-key conversion-keymap
- (car (car conversion-keys)) (cdr (car conversion-keys)))
- (setq conversion-keys (cdr conversion-keys))))
+ (dolist (conv conversion-keys)
+ (define-key conversion-keymap (car conv) (cdr conv))))
(quail-add-package
(list name title (list nil) guidance (or docstring "")
translation-keymap
(if (and (overlayp quail-conv-overlay) (overlay-start quail-conv-overlay))
(delete-overlay quail-conv-overlay)))
-(defun quail-inactivate ()
- "Inactivate Quail input method.
+(defun quail-deactivate ()
+ "Deactivate Quail input method.
-This function runs the normal hook `quail-inactivate-hook'."
+This function runs the normal hook `quail-deactivate-hook'."
(interactive)
(quail-activate -1))
+(define-obsolete-function-alias 'quail-inactivate 'quail-deactivate "24.3")
+
(defun quail-activate (&optional arg)
"Activate Quail input method.
With ARG, activate Quail input method if and only if arg is positive.
This function runs `quail-activate-hook' if it activates the input
-method, `quail-inactivate-hook' if it deactivates it.
+method, `quail-deactivate-hook' if it deactivates it.
While this input method is active, the variable
`input-method-function' is bound to the function `quail-input-method'."
(if (and arg
(< (prefix-numeric-value arg) 0))
- ;; Let's inactivate Quail input method.
+ ;; Let's deactivate Quail input method.
(unwind-protect
(progn
(quail-delete-overlays)
(setq describe-current-input-method-function nil)
(quail-hide-guidance)
(remove-hook 'post-command-hook 'quail-show-guidance t)
- (run-hooks 'quail-inactivate-hook))
+ (run-hooks
+ 'quail-inactivate-hook ; for backward compatibility
+ 'quail-deactivate-hook))
(kill-local-variable 'input-method-function))
;; Let's activate Quail input method.
(if (null quail-current-package)
(setq name (car (car quail-package-alist)))
(error "No Quail package loaded"))
(quail-select-package name)))
- (setq inactivate-current-input-method-function 'quail-inactivate)
+ (setq deactivate-current-input-method-function 'quail-deactivate)
(setq describe-current-input-method-function 'quail-help)
(quail-delete-overlays)
(setq quail-guidance-str "")
(make-local-variable 'input-method-function)
(setq input-method-function 'quail-input-method)))
+(define-obsolete-variable-alias
+ 'quail-inactivate-hook
+ 'quail-deactivate-hook "24.3")
+
(defun quail-exit-from-minibuffer ()
- (inactivate-input-method)
+ (deactivate-input-method)
(if (<= (minibuffer-depth) 1)
(remove-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer)))
(setq quail-keyboard-layout-substitution subst-list)
;; If there are additional key locations, map them to missing
;; key locations.
- (while missing-list
+ (dolist (missing missing-list)
(while (and subst-list (cdr (car subst-list)))
(setq subst-list (cdr subst-list)))
(if subst-list
- (setcdr (car subst-list) (car missing-list)))
- (setq missing-list (cdr missing-list))))))
+ (setcdr (car subst-list) missing))))))
(defcustom quail-keyboard-layout-type "standard"
"Type of keyboard layout used in Quail base input method.
(if translation
(progn
(if (consp translation)
- (if (> (length (cdr translation)) 0)
- (setq translation (aref (cdr translation) 0))
- (setq translation " ")))
+ (setq translation
+ (if (> (length (cdr translation)) 0)
+ (aref (cdr translation) 0)
+ " ")))
(setq done-list (cons translation done-list)))
(setq translation (aref kbd-layout i)))
(aset layout i translation))
(setq lower (aref layout i)
upper (aref layout (1+ i)))
(insert bar)
- (if (= (if (stringp lower) (string-width lower) (char-width lower)) 1)
+ (if (< (if (stringp lower) (string-width lower) (char-width lower)) 2)
(insert " "))
- (insert lower upper)
- (if (= (if (stringp upper) (string-width upper) (char-width upper)) 1)
+ (if (characterp lower)
+ (setq lower
+ (if (eq (get-char-code-property lower 'general-category) 'Mn)
+ ;; Pad the left and right of non-spacing characters.
+ (compose-string (string lower) 0 1
+ (format "\t%c\t" lower))
+ (string lower))))
+ (if (characterp upper)
+ (setq upper
+ (if (eq (get-char-code-property upper 'general-category) 'Mn)
+ ;; Pad the left and right of non-spacing characters.
+ (compose-string (string upper) 0 1
+ (format "\t%c\t" upper))
+ (string upper))))
+ (insert (bidi-string-mark-left-to-right lower)
+ (propertize " " 'invisible t)
+ (bidi-string-mark-left-to-right upper))
+ (if (< (string-width upper) 2)
(insert " "))
(setq i (+ i 2))
(if (= (% i 30) 0)
;;(delete-region pos (point)))
(let ((from1 100) (to1 0) from2 to2)
(while (not (eobp))
- (if (looking-at "[| ]*$")
+ (if (looking-at "[| \u202c\u202d]*$")
;; The entire row is blank.
(delete-region (point) (match-end 0))
;; Delete blank key columns at the head.
- (if (looking-at " *\\(| \\)+")
+ (if (looking-at "\u202d? *\\(| \\)+")
(subst-char-in-region (point) (match-end 0) ?| ? ))
;; Delete blank key columns at the tail.
- (if (re-search-forward "\\( |\\)+$" (line-end-position) t)
+ (if (re-search-forward "\\( |\\)+\u202c?$"
+ (line-end-position) t)
(delete-region (match-beginning 0) (point)))
(beginning-of-line))
;; Calculate the start and end columns of a horizontal line.
(if (eolp)
(setq from2 from1 to2 to1)
- (skip-chars-forward " ")
+ (skip-chars-forward " \u202d")
(setq from2 (current-column))
(end-of-line)
(setq to2 (current-column))
(let ((map (list nil))
(decode-map (if (not no-decode-map) (list 'decode-map)))
key trans)
- (while l
- (setq key (car (car l)) trans (car (cdr (car l))) l (cdr l))
+ (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))
(if (stringp trans)
(setq trans (string-to-vector trans))))
(let ((new (quail-vunion prevchars trans)))
- (setq trans
+ (setq trans
(if (equal new prevchars)
;; Nothing to change, get back to orig value.
prev
the translation, and INDEX points into VECTOR to specify the currently
selected translation."
(if (and def (symbolp def))
- (if (functionp def)
- ;; DEF is a symbol of a function which returns valid translation.
- (setq def (funcall def key len))
- (setq def nil)))
+ ;; DEF is a symbol of a function which returns valid translation.
+ (setq def (if (functionp def) (funcall def key len))))
(if (and (consp def) (not (vectorp (cdr def))))
(setq def (car def)))
(setcdr map (funcall (cdr map) key len)))
map))
-(put 'quail-error 'error-conditions '(quail-error error))
+(define-error 'quail-error nil)
(defun quail-error (&rest args)
(signal 'quail-error (apply 'format args)))
(let ((last-col-elt (or (nth (1- (* (1+ col) newrows))
single-list)
(car (last single-list)))))
- (incf width (+ (max 3 (length (car last-col-elt)))
- 1 single-trans-width 1))))
+ (cl-incf width (+ (max 3 (length (car last-col-elt)))
+ 1 single-trans-width 1))))
(< width window-width))
- (incf cols))
+ (cl-incf cols))
(setq rows (/ (+ len cols -1) cols)) ;Round up.
(let ((key-width (max 3 (length (car (nth (1- rows) single-list))))))
(insert "key")
"Show brief description of the current Quail package.
Optional arg PACKAGE specifies the name of alternative Quail
package to describe."
- (interactive)
(require 'help-mode)
(let ((help-xref-mule-regexp help-xref-mule-regexp-template)
(mb enable-multibyte-characters)
;; the width of the window in which the buffer displayed.
(with-current-buffer (help-buffer)
(setq buffer-read-only nil)
+ ;; Without this, a keyboard layout with R2L characters might be
+ ;; displayed reversed, right to left. See the thread starting at
+ ;; http://lists.gnu.org/archive/html/emacs-devel/2012-03/msg00062.html
+ ;; for a description of one such situation.
+ (setq bidi-paragraph-direction 'left-to-right)
(insert "Input method: " (quail-name)
" (mode line indicator:"
(quail-title)
'quail-keyboard-layout-button
quail-keyboard-layout-type)
(insert "' layout,
-translation results in the following \"virtual\" keyboard layout:
+translation results in the following \"virtual\" keyboard layout
+\(the labels on the keys indicate what character will be produced
+by each key, with and without holding Shift):
")
(setq done-list
(quail-insert-kbd-layout quail-keyboard-layout))