From 52f8bab760e91cf0a6ede97fde95b5856d022ba7 Mon Sep 17 00:00:00 2001 From: Dave Love Date: Thu, 22 Nov 2001 10:37:24 +0000 Subject: [PATCH] (quail-keyboard-layout-alist): Add pc105-uk. (quail-keyboard-layout-type): Fix custom type. (quail-input-string-to-events): Use standard-translation-table-for-decode. (quail-choose-completion-string): Use choose-completion-string. (quail-update-leim-list-file): Avoid commented-out code. --- lisp/international/quail.el | 199 +++++++++++++++++++----------------- 1 file changed, 106 insertions(+), 93 deletions(-) diff --git a/lisp/international/quail.el b/lisp/international/quail.el index 4303edc011b..5447e56aa5d 100644 --- a/lisp/international/quail.el +++ b/lisp/international/quail.el @@ -1,12 +1,13 @@ -;;; quail.el --- Provides simple input method for multilingual text +;;; quail.el --- provides simple input method for multilingual text ;; Copyright (C) 1995, 2000 Electrotechnical Laboratory, JAPAN. ;; Licensed to the Free Software Foundation. +;; Copyright (C) 2001 Free Software Foundation, Inc. ;; Author: Kenichi HANDA ;; Naoto TAKAHASHI ;; Maintainer: Kenichi HANDA -;; Keywords: mule, multilingual, input method +;; Keywords: mule, multilingual, input method, i18n ;; This file is part of GNU Emacs. @@ -41,6 +42,14 @@ ;; Kanji-and-Kana mixed text or Katakana text by commands specified in ;; CONVERSION-KEYS argument of the Quail package. +;; [There was an input method for Mule 2.3 called `Tamago' from the +;; Japanese `TAkusan MAtasete GOmenasai', or `Sorry for having you +;; wait so long'; this couldn't be included in Emacs 20. `Tamago' is +;; Japanese for `egg' (implicitly a hen's egg). Handa-san made a +;; smaller and simpler system; the smaller quail egg is also eaten in +;; Japan. Maybe others will be egged on to write more sorts of input +;; methods.] + ;;; Code: (defgroup quail nil @@ -125,9 +134,25 @@ See the documentation of `quail-define-package' for the other elements.") (defsubst quail-name () "Return the name of the current Quail package." (nth 0 quail-current-package)) -(defsubst quail-title () +;;;###autoload +(defun quail-title () "Return the title of the current Quail package." - (nth 1 quail-current-package)) + (let ((title (nth 1 quail-current-package))) + ;; TITLE may be a string or a list. If it is a list, each element + ;; is a string or the form (VAR STR1 STR2), and the interpretation + ;; of the list is the same as that of mode-line-format. + (if (stringp title) + title + (condition-case nil + (mapconcat + (lambda (x) + (cond ((stringp x) x) + ((and (listp x) (symbolp (car x)) (= (length x) 3)) + (if (symbol-value (car x)) + (nth 1 x) (nth 2 x))) + (t ""))) + title "") + (error ""))))) (defsubst quail-map () "Return the translation map of the current Quail package." (nth 2 quail-current-package)) @@ -204,7 +229,10 @@ Conversion keymap is a keymap used while conversion region is active ;;;###autoload (defun quail-use-package (package-name &rest libraries) "Start using Quail package PACKAGE-NAME. -The remaining arguments are libraries to be loaded before using the package." +The remaining arguments are libraries to be loaded before using the package. + +This activates input method defined by PACKAGE-NAME by running +`quail-activate', which see." (let ((package (quail-package package-name))) (if (null package) ;; Perhaps we have not yet loaded necessary libraries. @@ -512,7 +540,9 @@ non-Quail commands." (kill-buffer quail-guidance-buf))) (defun quail-inactivate () - "Inactivate Quail input method." + "Inactivate Quail input method. + +This function runs the normal hook `quail-inactivate-hook'." (interactive) (quail-activate -1)) @@ -520,6 +550,9 @@ non-Quail commands." "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. + While this input method is active, the variable `input-method-function' is bound to the function `quail-input-method'." (if (and arg @@ -593,7 +626,7 @@ We assume there are six rows and each row has 15 keys (columns), the first column of the fifth row is left of key `z', the sixth row is below the `z' - `/' row. Nth (N is even) and (N+1)th characters in the string are non-shifted - and shifted characters respectively at the same location. +and shifted characters respectively at the same location. The location of Nth character is row (N / 30) and column ((N mod 30) / 2). The command `quail-set-keyboard-layout' usually sets this variable.") @@ -634,6 +667,13 @@ The command `quail-set-keyboard-layout' usually sets this variable.") aAsSdDfFgGhHjJkKlL;+:*]} \ zZxXcCvVbBnNmM,<.>/?\\_ \ ") + '("pc105-uk" . "\ + \ +`\2541!2\3\243$5%6^7&8*9(0)-_=+ \ + qQwWeErRtTyYuUiIoOpP[{]} \ + aAsSdDfFgGhHjJkKlL;:'@#~ \ +\\|zZxXcCvVbBnNmM,<.>/? \ + ") ) "Alist of keyboard names and corresponding layout strings. See the documentation of `quail-keyboard-layout' for the format of @@ -678,7 +718,9 @@ the layout string.") "Type of keyboard layout used in Quail base input method. Available types are listed in the variable `quail-keyboard-layout-alist'." :group 'quail - :type 'string + :type (cons 'choice (mapcar (lambda (elt) + (list 'const (car elt))) + quail-keyboard-layout-alist)) :set #'(lambda (symbol value) (quail-update-keyboard-layout value) (set symbol value))) @@ -733,9 +775,9 @@ you type is correctly handled." (mapcar (function (lambda (x) (quail-keyboard-translate x))) keyseq))) -;; Insert the visual keyboard layout table according to KBD-LAYOUT. -;; The format of KBD-LAYOUT is the same as `quail-keyboard-layout'. (defun quail-insert-kbd-layout (kbd-layout) +"Insert the visual keyboard layout table according to KBD-LAYOUT. +The format of KBD-LAYOUT is the same as `quail-keyboard-layout'." (let (done-list layout i ch) ;; At first, convert KBD-LAYOUT to the same size vector that ;; contains translated character or string. @@ -1208,7 +1250,7 @@ The returned value is a Quail map specific to KEY." (if (not (equal def translation)) ;; We must reflect TRANSLATION to car part of MAP. (setcar map translation))) - (if (and (consp translation) (vectorp (cdr translation))) + (if (and (consp translation) (vectorp (cdr translation))) (progn (setq quail-current-translations translation) (if (quail-forget-last-selection) @@ -1223,13 +1265,18 @@ The returned value is a Quail map specific to KEY." (signal 'quail-error (apply 'format args))) -;; Convert input string STR to a list of events while interleaving -;; with the following special events: -;; (compose-last-chars LEN COMPONENTS) -;; (quail-advice INPUT-STRING) - (defun quail-input-string-to-events (str) - (let* ((events (string-to-list str)) + "Convert input string STR to a list of events. +Do so while interleaving with the following special events: +\(compose-last-chars LEN COMPONENTS) +\(quail-advice INPUT-STRING)" + (let* ((events (mapcar + (lambda (c) + ;; This gives us the chance to unify on input + ;; (e.g. ucs-tables.el). + (or (aref standard-translation-table-for-decode c) + c)) + str)) (len (length str)) (idx len) composition from to) @@ -1419,6 +1466,7 @@ Return the input string." (setq unread-command-events (string-to-list (this-single-command-raw-keys))) (setq quail-converting nil)))) + (setq quail-translating nil) (if (overlay-start quail-conv-overlay) (delete-region (overlay-start quail-conv-overlay) (overlay-end quail-conv-overlay))) @@ -1444,15 +1492,14 @@ Return the input string." (interactive) (quail-terminate-translation)) -;; Update the current translation status according to CONTROL-FLAG. -;; If CONTROL-FLAG is integer value, it is the number of keys in the -;; head quail-current-key which can be translated. The remaining keys -;; are put back to unread-command-events to be handled again. If -;; CONTROL-FLAG is t, terminate the translation for the whole keys in -;; quail-current-key. If CONTROL-FLAG is nil, proceed the translation -;; with more keys. - (defun quail-update-translation (control-flag) +"Update the current translation status according to CONTROL-FLAG. +If CONTROL-FLAG is integer value, it is the number of keys in the +head `quail-current-key' which can be translated. The remaining keys +are put back to `unread-command-events' to be handled again. If +CONTROL-FLAG is t, terminate the translation for the whole keys in +`quail-current-key'. If CONTROL-FLAG is nil, proceed the translation +with more keys." (let ((func (quail-update-translation-function))) (if func (setq control-flag (funcall func control-flag)) @@ -1501,8 +1548,8 @@ Return the input string." ;; translation mode. (setq quail-translating nil))) -;; Return the actual definition part of Quail map MAP. (defun quail-map-definition (map) +"Return the actual definition part of Quail map MAP." (let ((def (car map))) (if (and (consp def) (not (vectorp (cdr def)))) (setq def (car def))) @@ -1510,10 +1557,10 @@ Return the input string." (setq def nil)) def)) -;; Return a string to be shown as the current translation of key -;; sequence of length LEN. DEF is a definition part of Quail map for -;; the sequence. (defun quail-get-current-str (len def) + "Return string to be shown as current translation of key sequence. +LEN is the length of the sequence. DEF is a definition part of the +Quail map for the sequence." (or (and (consp def) (aref (cdr def) (car (car def)))) def (and (> len 1) @@ -1527,9 +1574,9 @@ Return the input string." (defvar quail-guidance-translations-starting-column 20) -;; Update `quail-current-translations' to make RELATIVE-INDEX the -;; current translation. (defun quail-update-current-translations (&optional relative-index) + "Update `quail-current-translations'. +Make RELATIVE-INDEX the current translation." (let* ((indices (car quail-current-translations)) (cur (car indices)) (start (nth 1 indices)) @@ -1614,7 +1661,7 @@ sequence counting from the head." ;; giving up, we must check two possibilities. (cond ((and (quail-maximum-shortest) - (>= len 4) + (>= len 3) (setq def (quail-map-definition (quail-lookup-key quail-current-key (- len 2)))) (quail-lookup-key (substring quail-current-key -2) 2)) @@ -1807,8 +1854,8 @@ Remaining args are for FUNC." ;; Guidance, Completion, and Help buffer handlers. -;; Make a new one-line frame for Quail guidance buffer. (defun quail-make-guidance-frame (buf) + "Make a new one-line frame for Quail guidance buffer." (let* ((fparam (frame-parameters)) (top (cdr (assq 'top fparam))) (border (cdr (assq 'border-width fparam))) @@ -1825,8 +1872,8 @@ Remaining args are for FUNC." ;;(set-window-dedicated-p win t) ))) -;; Setup Quail completion buffer. (defun quail-setup-completion-buf () + "Setup Quail completion buffer." (unless (buffer-live-p quail-completion-buf) (let ((default-enable-multibyte-characters enable-multibyte-characters)) (setq quail-completion-buf (get-buffer-create "*Quail Completions*"))) @@ -1835,9 +1882,8 @@ Remaining args are for FUNC." (setq quail-overlay (make-overlay 1 1)) (overlay-put quail-overlay 'face 'highlight)))) -;; Return t iff the current Quail package requires showing guidance -;; buffer. (defun quail-require-guidance-buf () + "Return t iff the current Quail package requires showing guidance buffer." (and input-method-verbose-flag (if (eq input-method-verbose-flag 'default) (not (and (eq (selected-window) (minibuffer-window)) @@ -2094,8 +2140,8 @@ are shown (at most to the depth specified `quail-completion-max-depth')." (quail-update-guidance))) (setq this-command 'quail-completion)) -;; List all completions of KEY in MAP with indentation INDENT. (defun quail-completion-1 (key map indent) +"List all completions of KEY in MAP with indentation INDENT." (let ((len (length key))) (indent-to indent) (insert key ":") @@ -2115,14 +2161,14 @@ are shown (at most to the depth specified `quail-completion-max-depth')." (while (< i len) (aset newkey i (aref key i)) (setq i (1+ i))) + (setq l (reverse l)) (while l ; L = ((CHAR . DEFN) ....) ; (aset newkey len (car (car l))) (quail-completion-1 newkey (cdr (car l)) indent) (setq l (cdr l))))))) -;; List all possible translations of KEY in Quail map MAP with -;; indentation INDENT. (defun quail-completion-list-translations (map key indent) + "List all possible translations of KEY in Quail MAP with indentation INDENT." (let (beg (translations (quail-get-translation (car map) key (length key)))) (if (integerp translations) @@ -2156,16 +2202,14 @@ are shown (at most to the depth specified `quail-completion-max-depth')." (setq i (1+ i))) (insert "\n"))))) -;; Choose a completion in *Quail Completions* buffer with mouse-2. - (defun quail-mouse-choose-completion (event) "Click on an alternative in the `*Quail Completions*' buffer to choose it." (interactive "e") ;; This function is an exact copy of the mouse.el function - ;; `mouse-choose-completion' except that we: + ;; `mouse-choose-completion' except that we: ;; 1) add two lines from `choose-completion' in simple.el to give ;; the `mouse-2' click a little more leeway. - ;; 2) don't bury *Quail Completions* buffer so comment a section, and + ;; 2) don't bury *Quail Completions* buffer, so comment a section, and ;; 3) delete/terminate the current quail selection here. ;; Give temporary modes such as isearch a chance to turn off. (run-hooks 'mouse-leave-buffer-hook) @@ -2203,52 +2247,21 @@ are shown (at most to the depth specified `quail-completion-max-depth')." (quail-choose-completion-string choice buffer base-size) (quail-terminate-translation))) -;; Modify the simple.el function `choose-completion-string', because -;; the simple.el function `choose-completion-delete-max-match' breaks -;; on Mule data, since the semantics of `forward-char' have changed. - -(defun quail-choose-completion-string (choice &optional buffer base-size) - (let ((buffer (or buffer completion-reference-buffer))) - ;; If BUFFER is a minibuffer, barf unless it's the currently - ;; active minibuffer. - (if (and (string-match "\\` \\*Minibuf-[0-9]+\\*\\'" (buffer-name buffer)) - (or (not (active-minibuffer-window)) - (not (equal buffer - (window-buffer (active-minibuffer-window)))))) - (quail-error "Minibuffer is not active for completion") - ;; Store the completion in `quail-current-str', which will later - ;; be converted to a character event list, then inserted into - ;; the buffer where completion was requested. - (set-buffer buffer) -; (if base-size -; (delete-region (+ base-size (point-min)) (point)) -; (choose-completion-delete-max-match choice)) - (setq quail-current-str choice) - ;; Update point in the window that BUFFER is showing in. - (let ((window (get-buffer-window buffer t))) - (set-window-point window (point))) - ;; If completing for the minibuffer, exit it with this choice. - (and (not completion-no-auto-exit) - (equal buffer (window-buffer (minibuffer-window))) - minibuffer-completion-table - ;; If this is reading a file name, and the file name chosen - ;; is a directory, don't exit the minibuffer. - (if (and (eq minibuffer-completion-table 'read-file-name-internal) - (file-directory-p (buffer-string))) - (select-window (active-minibuffer-window)) - (exit-minibuffer)))))) - -;; Accumulate in the cdr part of DECODE-MAP all pairs of key sequences -;; vs the corresponding translations defined in the Quail map -;; specified by the first element MAP-LIST. Each pair has the form -;; (KEYSEQ . TRANSLATION). DECODE-MAP should have the form -;; (decode-map . ALIST), where ALIST is an alist of length NUM. KEY -;; is a key sequence to reach MAP. -;; Optional 5th arg MAXNUM limits the number of accumulated pairs. -;; Optional 6th arg IGNORES is a list of translations to ignore. +(defun quail-choose-completion-string (choice &optional buffer) + (setq quail-current-str choice) + (choose-completion-string choice buffer)) (defun quail-build-decode-map (map-list key decode-map num &optional maxnum ignores) + "Build a decoding map. +Accumulate in the cdr part of DECODE-MAP all pairs of key sequences +vs the corresponding translations defined in the Quail map +specified by the first element MAP-LIST. Each pair has the form +\(KEYSEQ . TRANSLATION). DECODE-MAP should have the form +\(decode-map . ALIST), where ALIST is an alist of length NUM. KEY +is a key sequence to reach MAP. +Optional 5th arg MAXNUM limits the number of accumulated pairs. +Optional 6th arg IGNORES is a list of translations to ignore." (let* ((map (car map-list)) (translation (quail-get-translation (car map) key (length key))) elt) @@ -2286,11 +2299,10 @@ are shown (at most to the depth specified `quail-completion-max-depth')." decode-map num maxnum ignores)))) num))) -;; Insert the pairs of key sequences vs the corresponding translations -;; stored in DECODE-MAP by the concise format. DECODE-MAP should be -;; made by `quail-build-decode-map' (which see). - (defun quail-insert-decode-map (decode-map) + "Insert pairs of key sequences vs the corresponding translations. +These are stored in DECODE-MAP using the concise format. DECODE-MAP +should be made by `quail-build-decode-map' (which see)." (setq decode-map (sort (cdr decode-map) (function (lambda (x y) @@ -2491,7 +2503,7 @@ KEY BINDINGS FOR CONVERSION ---------------------------\n")) (help-setup-xref (list #'quail-help (quail-name)) (interactive-p)) - (setq quail-current-package nil) + (setq quail-current-package nil) ;; Resize the help window again, now that it has all its contents. (save-selected-window (select-window (get-buffer-window (current-buffer))) @@ -2770,7 +2782,8 @@ of each directory." (with-temp-buffer (insert-file-contents (car pkg-list)) (goto-char (point-min)) - (while (search-forward "(quail-define-package" nil t) + ;; Don't get fooled by commented-out code. + (while (search-forward "^[ \t]*(quail-define-package" nil t) (goto-char (match-beginning 0)) (condition-case nil (let ((form (read (current-buffer)))) @@ -2807,7 +2820,7 @@ of each directory." (message "Updating %s ... done" leim-list))) (defun quail-advice (args) - "Advice users about the characters input by the current Quail package. + "Advise users about the characters input by the current Quail package. The argument is a parameterized event of the form: (quail-advice STRING) where STRING is a string containing the input characters. -- 2.39.5