annotate lisp/international/quail.el @ 19649:b2bf3c43c86a

(get-language-info): Accept a symbol as the arg LANGUAGE-NAME. (set-language-info): Likewise. (set-language-info-alist): Likewise. (register-input-method): Accept a symbol as the args INPUT-METHOD and LANGUAGE-NAME. (activate-input-method): Accept a symbol as the args INPUT-METHOD. (describe-input-method): Likewise. (read-multilingual-string): Likewise. (set-language-environment): Accept a symbol as the arg LANGUAGE-NAME. (describe-language-environment): Likewise.
author Kenichi Handa <handa@m17n.org>
date Mon, 01 Sep 1997 07:19:38 +0000
parents 9b9af28bee8d
children 47d11f4bbc6c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17315
a3ca5e15c82a Fix the format of the first line.
Kenichi Handa <handa@m17n.org>
parents: 17174
diff changeset
1 ;;; quail.el --- Provides simple input method for multilingual text
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
2
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN.
18377
8b4a66c66dd6 Change copyright notice.
Richard M. Stallman <rms@gnu.org>
parents: 18349
diff changeset
4 ;; Licensed to the Free Software Foundation.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
5
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
6 ;; Author: Kenichi HANDA <handa@etl.go.jp>
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
7 ;; Naoto TAKAHASHI <ntakahas@etl.go.jp>
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
8 ;; Maintainer: Kenichi HANDA <handa@etl.go.jp>
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
9 ;; Keywords: mule, multilingual, input method
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
10
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
12
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
16 ;; any later version.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
17
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
22
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
17071
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
70194012fb3a Fix FSF address in comment.
Karl Heuer <kwzh@gnu.org>
parents: 17052
diff changeset
26 ;; Boston, MA 02111-1307, USA.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
27
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
28 ;;; Commentary:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
29
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
30 ;; In Quail minor mode, you can input multilingual text easily. By
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
31 ;; defining a translation table (named Quail map) which maps ASCII key
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
32 ;; string to multilingual character or string, you can input any text
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
33 ;; from ASCII keyboard.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
34 ;;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
35 ;; We use words "translation" and "conversion" differently. The
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
36 ;; former is done by Quail package itself, the latter is the further
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
37 ;; process of converting a translated text to some more desirable
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
38 ;; text. For instance, Quail package for Japanese (`quail-jp')
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
39 ;; translates Roman text (transliteration of Japanese in Latin
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
40 ;; alphabets) to Hiragana text, which is then converted to
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
41 ;; Kanji-and-Kana mixed text or Katakana text by commands specified in
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
42 ;; CONVERSION-KEYS argument of the Quail package.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
43
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
44 ;;; Code:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
45
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
46 (require 'faces)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
47
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
48 ;; Buffer local variables
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
49
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
50 (defvar quail-current-package nil
19391
763bc03e7797 (quail-guidance-buf): Now a permanent local.
Richard M. Stallman <rms@gnu.org>
parents: 19327
diff changeset
51 "The current Quail package, which depends on the current input method.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
52 See the documentation of `quail-package-alist' for the format.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
53 (make-variable-buffer-local 'quail-current-package)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
54 (put 'quail-current-package 'permanent-local t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
55
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
56 ;; Quail uses the following two buffers to assist users.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
57 ;; A buffer to show available key sequence or translation list.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
58 (defvar quail-guidance-buf nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
59 ;; A buffer to show completion list of the current key sequence.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
60 (defvar quail-completion-buf nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
61
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
62 ;; Each buffer in which Quail is activated should use different
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
63 ;; guidance buffers.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
64 (make-variable-buffer-local 'quail-guidance-buf)
19391
763bc03e7797 (quail-guidance-buf): Now a permanent local.
Richard M. Stallman <rms@gnu.org>
parents: 19327
diff changeset
65 (put 'quail-guidance-buf 'permanent-local t)
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
66
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
67 ;; A main window showing Quail guidance buffer.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
68 (defvar quail-guidance-win nil)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
69 (make-variable-buffer-local 'quail-guidance-win)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
70
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
71 (defvar quail-mode nil
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
72 "Non-nil if in Quail minor mode.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
73 (make-variable-buffer-local 'quail-mode)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
74 (put 'quail-mode 'permanent-local t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
75
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
76 (defvar quail-overlay nil
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
77 "Overlay which covers the current translation region of Quail.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
78 (make-variable-buffer-local 'quail-overlay)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
79
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
80 (defvar quail-conv-overlay nil
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
81 "Overlay which covers the text to be converted in Quail mode.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
82 (make-variable-buffer-local 'quail-conv-overlay)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
83
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
84 (defvar quail-current-key nil
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
85 "Current key for translation in Quail mode.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
86
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
87 (defvar quail-current-str nil
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
88 "Currently selected translation of the current key.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
89
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
90 (defvar quail-current-translations nil
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
91 "Cons of indices and vector of possible translations of the current key.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
92 Indices is a list of (CURRENT START END BLOCK BLOCKS), where
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
93 CURRENT is an index of the current translation,
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
94 START and END are indices of the start and end of the current block,
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
95 BLOCK is the current block index,
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
96 BLOCKS is a number of blocks of translation.")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
97
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
98 (defvar quail-current-data nil
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
99 "Any Lisp object holding information of current translation status.
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
100 When a key sequence is mapped to TRANS and TRANS is a cons
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
101 of actual translation and some Lisp object to be refered
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
102 for translating the longer key sequence, this variable is set
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
103 to that Lisp object.")
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
104 (make-variable-buffer-local 'quail-current-data)
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
105
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
106 ;; A flag to control conversion region. Normally nil, but if set to
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
107 ;; t, it means we must start the new conversion region if new key to
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
108 ;; be translated is input.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
109 (defvar quail-reset-conversion-region nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
110
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
111 ;; Quail package handlers.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
112
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
113 (defvar quail-package-alist nil
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
114 "List of Quail packages.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
115 A Quail package is a list of these elements:
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
116 NAME, TITLE, QUAIL-MAP, GUIDANCE, DOCSTRING, TRANSLATION-KEYS,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
117 FORGET-LAST-SELECTION, DETERMINISTIC, KBD-TRANSLATE, SHOW-LAYOUT,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
118 DECODE-MAP, MAXIMUM-SHORTEST, OVERLAY-PLIST, UPDATE-TRANSLATION-FUNCTION,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
119 CONVERSION-KEYS.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
120
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
121 QUAIL-MAP is a data structure to map key strings to translations. For
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
122 the format, see the documentation of `quail-map-p'.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
123
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
124 DECODE-MAP is an alist of translations and corresponding keys.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
125
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
126 See the documentation of `quail-define-package' for the other elements.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
127
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
128 ;; Return various slots in the current quail-package.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
129
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
130 (defsubst quail-name ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
131 "Return the name of the current Quail package."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
132 (nth 0 quail-current-package))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
133 (defsubst quail-title ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
134 "Return the title of the current Quail package."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
135 (nth 1 quail-current-package))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
136 (defsubst quail-map ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
137 "Return the translation map of the current Quail package."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
138 (nth 2 quail-current-package))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
139 (defsubst quail-guidance ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
140 "Return an object used for `guidance' feature of the current Quail package.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
141 See also the documentation of `quail-define-package'."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
142 (nth 3 quail-current-package))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
143 (defsubst quail-docstring ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
144 "Return the documentation string of the current Quail package."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
145 (nth 4 quail-current-package))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
146 (defsubst quail-translation-keymap ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
147 "Return translation keymap in the current Quail package.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
148 Translation keymap is a keymap used while translation region is active."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
149 (nth 5 quail-current-package))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
150 (defsubst quail-forget-last-selection ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
151 "Return `forget-last-selection' flag of the current Quail package.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
152 See also the documentation of `quail-define-package'."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
153 (nth 6 quail-current-package))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
154 (defsubst quail-deterministic ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
155 "Return `deterministic' flag of the current Quail package.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
156 See also the documentation of `quail-define-package'."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
157 (nth 7 quail-current-package))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
158 (defsubst quail-kbd-translate ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
159 "Return `kbd-translate' flag of the current Quail package.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
160 See also the documentation of `quail-define-package'."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
161 (nth 8 quail-current-package))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
162 (defsubst quail-show-layout ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
163 "Return `show-layout' flag of the current Quail package.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
164 See also the documentation of `quail-define-package'."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
165 (nth 9 quail-current-package))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
166 (defsubst quail-decode-map ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
167 "Return decode map of the current Quail package.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
168 It is an alist of translations and corresponding keys."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
169 (nth 10 quail-current-package))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
170 (defsubst quail-maximum-shortest ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
171 "Return `maximum-shortest' flag of the current Quail package.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
172 See also the documentation of `quail-define-package'."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
173 (nth 11 quail-current-package))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
174 (defsubst quail-overlay-plist ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
175 "Return property list of an overly used in the current Quail package."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
176 (nth 12 quail-current-package))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
177 (defsubst quail-update-translation-function ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
178 "Return a function for updating translation in the current Quail package."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
179 (nth 13 quail-current-package))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
180 (defsubst quail-conversion-keymap ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
181 "Return conversion keymap in the current Quail package.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
182 Conversion keymap is a keymap used while conversion region is active
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
183 but translation region is not active."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
184 (nth 14 quail-current-package))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
185
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
186 (defsubst quail-package (name)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
187 "Return Quail package named NAME."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
188 (assoc name quail-package-alist))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
189
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
190 (defun quail-add-package (package)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
191 "Add Quail package PACKAGE to `quail-package-alist'."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
192 (let ((pac (quail-package (car package))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
193 (if pac
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
194 (setcdr pac (cdr package))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
195 (setq quail-package-alist (cons package quail-package-alist)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
196
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
197 (defun quail-select-package (name)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
198 "Select Quail package named NAME as the current Quail package."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
199 (let ((package (quail-package name)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
200 (if (null package)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
201 (error "No Quail package `%s'" name))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
202 (setq quail-current-package package)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
203 (setq-default quail-current-package package)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
204 name))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
205
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
206 ;;;###autoload
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
207 (defun quail-use-package (package-name &rest libraries)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
208 "Start using Quail package PACKAGE-NAME.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
209 The remaining arguments are libraries to be loaded before using the package."
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
210 (let ((package (quail-package package-name)))
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
211 (if (null package)
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
212 ;; Perhaps we have not yet loaded necessary libraries.
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
213 (while libraries
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
214 (if (not (load (car libraries) t))
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
215 (progn
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
216 (with-output-to-temp-buffer "*Help*"
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
217 (princ "Quail package \"")
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
218 (princ package-name)
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
219 (princ "\" can't be activated\n because library \"")
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
220 (princ (car libraries))
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
221 (princ "\" is not in `load-path'.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
222
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
223 The most common case is that you have not yet installed appropriate
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
224 libraries in LEIM (Libraries of Emacs Input Method) which is
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
225 distributed separately from Emacs.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
226
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
227 LEIM is available from the same ftp directory as Emacs."))
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
228 (error "Can't use the Quail package `%s'" package-name))
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
229 (setq libraries (cdr libraries))))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
230 (quail-select-package package-name)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
231 (setq current-input-method-title (quail-title))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
232 (quail-mode 1))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
233
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
234 (defun quail-inactivate ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
235 "Turn off Quail input method."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
236 (interactive)
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
237 (setq overriding-terminal-local-map nil)
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
238 (quail-mode -1))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
239
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
240 (or (assq 'quail-mode minor-mode-alist)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
241 (setq minor-mode-alist
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
242 (cons '(quail-mode " Quail") minor-mode-alist)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
243
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
244 (defvar quail-mode-map
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
245 (let ((map (make-keymap))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
246 (i ? ))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
247 (while (< i 127)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
248 (define-key map (char-to-string i) 'quail-start-translation)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
249 (setq i (1+ i)))
19647
9b9af28bee8d (quail-translation-keymap): Do not bind
Kenichi Handa <handa@m17n.org>
parents: 19619
diff changeset
250 (setq i 128)
9b9af28bee8d (quail-translation-keymap): Do not bind
Kenichi Handa <handa@m17n.org>
parents: 19619
diff changeset
251 (while (< i 256)
9b9af28bee8d (quail-translation-keymap): Do not bind
Kenichi Handa <handa@m17n.org>
parents: 19619
diff changeset
252 (define-key map (vector i) 'quail-start-translation)
9b9af28bee8d (quail-translation-keymap): Do not bind
Kenichi Handa <handa@m17n.org>
parents: 19619
diff changeset
253 (setq i (1+ i)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
254 map)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
255 "Keymap for Quail mode.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
256
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
257 (or (assq 'quail-mode minor-mode-map-alist)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
258 (setq minor-mode-map-alist
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
259 (cons (cons 'quail-mode quail-mode-map) minor-mode-map-alist)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
260
17095
b57415dcc114 Add quail-mode to default value of
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
261 ;; Since some Emacs Lisp programs (e.g. viper.el) make
b57415dcc114 Add quail-mode to default value of
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
262 ;; minor-mode-map-alist buffer-local, we must be sure to register
b57415dcc114 Add quail-mode to default value of
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
263 ;; quail-mode-map in default-value of minor-mode-map-alist.
b57415dcc114 Add quail-mode to default value of
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
264 (if (local-variable-p 'minor-mode-map-alist)
b57415dcc114 Add quail-mode to default value of
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
265 (let ((map (default-value 'minor-mode-map-alist)))
b57415dcc114 Add quail-mode to default value of
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
266 (or (assq 'quail-mode map)
b57415dcc114 Add quail-mode to default value of
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
267 (set-default 'minor-mode-map-alist (cons 'quail-mode map)))))
b57415dcc114 Add quail-mode to default value of
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
268
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
269 (defvar quail-translation-keymap
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
270 (let ((map (make-keymap))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
271 (i 0))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
272 (while (< i ?\ )
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
273 (define-key map (char-to-string i) 'quail-execute-non-quail-command)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
274 (setq i (1+ i)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
275 (while (< i 127)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
276 (define-key map (char-to-string i) 'quail-self-insert-command)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
277 (setq i (1+ i)))
19647
9b9af28bee8d (quail-translation-keymap): Do not bind
Kenichi Handa <handa@m17n.org>
parents: 19619
diff changeset
278 (setq i 128)
9b9af28bee8d (quail-translation-keymap): Do not bind
Kenichi Handa <handa@m17n.org>
parents: 19619
diff changeset
279 (while (< i 127)
9b9af28bee8d (quail-translation-keymap): Do not bind
Kenichi Handa <handa@m17n.org>
parents: 19619
diff changeset
280 (define-key map (vector i) 'quail-self-insert-command)
9b9af28bee8d (quail-translation-keymap): Do not bind
Kenichi Handa <handa@m17n.org>
parents: 19619
diff changeset
281 (setq i (1+ i)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
282 (define-key map "\177" 'quail-delete-last-char)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
283 (define-key map "\C-f" 'quail-next-translation)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
284 (define-key map "\C-b" 'quail-prev-translation)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
285 (define-key map "\C-n" 'quail-next-translation-block)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
286 (define-key map "\C-p" 'quail-prev-translation-block)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
287 (define-key map "\C-i" 'quail-completion)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
288 (define-key map "\C-@" 'quail-select-current)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
289 (define-key map "\C-h" 'quail-translation-help)
17174
9c1191812679 (quail-translation-keymap): Add entry for escape key.
Kenichi Handa <handa@m17n.org>
parents: 17095
diff changeset
290 (define-key map "\e" '(keymap (t . quail-execute-non-quail-command)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
291 (define-key map [tab] 'quail-completion)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
292 (define-key map [delete] 'quail-delete-last-char)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
293 (define-key map [backspace] 'quail-delete-last-char)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
294 ;; At last, define default key binding.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
295 (append map '((t . quail-execute-non-quail-command))))
19619
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
296 "Keymap used processing translation in complex Quail modes.
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
297 Only a few especially complex input methods use this map;
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
298 most use `quail-simple-translation-keymap' instead.
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
299 This map is activated while translation region is active.")
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
300
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
301 (defvar quail-simple-translation-keymap
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
302 (let ((map (make-keymap))
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
303 (i 0))
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
304 (while (< i ?\ )
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
305 (define-key map (char-to-string i) 'quail-execute-non-quail-command)
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
306 (setq i (1+ i)))
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
307 (while (< i 127)
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
308 (define-key map (char-to-string i) 'quail-self-insert-command)
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
309 (setq i (1+ i)))
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
310 (define-key map "\177" 'quail-delete-last-char)
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
311 (define-key map "\e" '(keymap (t . quail-execute-non-quail-command)))
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
312 ;; At last, define default key binding.
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
313 (append map '((t . quail-execute-non-quail-command))))
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
314 "Keymap used while processing translation in simple Quail modes.
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
315 A few especially complex input methods use `quail--translation-keymap' instead.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
316 This map is activated while translation region is active.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
317
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
318 (defvar quail-conversion-keymap
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
319 (let ((map (make-keymap))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
320 (i 0))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
321 (while (< i ?\ )
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
322 (define-key map (char-to-string i) 'quail-execute-non-quail-command)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
323 (setq i (1+ i)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
324 (while (< i 127)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
325 (define-key map (char-to-string i)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
326 'quail-start-translation-in-conversion-mode)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
327 (setq i (1+ i)))
19647
9b9af28bee8d (quail-translation-keymap): Do not bind
Kenichi Handa <handa@m17n.org>
parents: 19619
diff changeset
328 (setq i 128)
9b9af28bee8d (quail-translation-keymap): Do not bind
Kenichi Handa <handa@m17n.org>
parents: 19619
diff changeset
329 (while (< i 127)
9b9af28bee8d (quail-translation-keymap): Do not bind
Kenichi Handa <handa@m17n.org>
parents: 19619
diff changeset
330 (define-key map (vector i) 'quail-start-translation-in-conversion-mode)
9b9af28bee8d (quail-translation-keymap): Do not bind
Kenichi Handa <handa@m17n.org>
parents: 19619
diff changeset
331 (setq i (1+ i)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
332 (define-key map "\C-b" 'quail-conversion-backward-char)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
333 (define-key map "\C-f" 'quail-conversion-forward-char)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
334 (define-key map "\C-a" 'quail-conversion-beginning-of-region)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
335 (define-key map "\C-e" 'quail-conversion-end-of-region)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
336 (define-key map "\C-d" 'quail-conversion-delete-char)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
337 (define-key map "\C-h" 'quail-conversion-help)
17174
9c1191812679 (quail-translation-keymap): Add entry for escape key.
Kenichi Handa <handa@m17n.org>
parents: 17095
diff changeset
338 (define-key map "\e" '(keymap (t . quail-execute-non-quail-command)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
339 (define-key map "\177" 'quail-conversion-backward-delete-char)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
340 (define-key map [delete] 'quail-conversion-backward-delete-char)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
341 (define-key map [backspace] 'quail-conversion-backward-delete-char)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
342 ;; At last, define default key binding.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
343 (append map '((t . quail-execute-non-quail-command))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
344 "Keymap used for processing conversion in Quail mode.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
345 This map is activated while convesion region is active but translation
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
346 region is not active.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
347
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
348 ;;;###autoload
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
349 (defun quail-define-package (name language title
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
350 &optional guidance docstring translation-keys
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
351 forget-last-selection deterministic
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
352 kbd-translate show-layout create-decode-map
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
353 maximum-shortest overlay-plist
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
354 update-translation-function
19619
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
355 conversion-keys simple)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
356 "Define NAME as a new Quail package for input LANGUAGE.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
357 TITLE is a string to be displayed at mode-line to indicate this package.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
358 Optional arguments are GUIDANCE, DOCSTRING, TRANLSATION-KEYS,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
359 FORGET-LAST-SELECTION, DETERMINISTIC, KBD-TRANSLATE, SHOW-LAYOUT,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
360 CREATE-DECODE-MAP, MAXIMUM-SHORTEST, OVERLAY-PLIST,
19619
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
361 UPDATE-TRANSLATION-FUNCTION, CONVERSION-KEYS and SIMPLE.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
362
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
363 GUIDANCE specifies how a guidance string is shown in echo area.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
364 If it is t, list of all possible translations for the current key is shown
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
365 with the currently selected translation being highlighted.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
366 If it is an alist, the element has the form (CHAR . STRING). Each character
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
367 in the current key is searched in the list and the corresponding string is
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
368 shown.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
369 If it is nil, the current key is shown.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
370
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
371 DOCSTRING is the documentation string of this package.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
372
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
373 TRANSLATION-KEYS specifies additional key bindings used while translation
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
374 region is active. It is an alist of single key character vs. corresponding
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
375 command to be called.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
376
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
377 FORGET-LAST-SELECTION non-nil means a selected translation is not kept
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
378 for the future to translate the same key. If this flag is nil, a
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
379 translation selected for a key is remembered so that it can be the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
380 first candidate when the same key is entered later.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
381
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
382 DETERMINISTIC non-nil means the first candidate of translation is
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
383 selected automatically without allowing users to select another
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
384 translation for a key. In this case, unselected translations are of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
385 no use for an interactive use of Quail but can be used by some other
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
386 programs. If this flag is non-nil, FORGET-LAST-SELECTION is also set
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
387 to t.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
388
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
389 KBD-TRANSLATE non-nil means input characters are translated from a
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
390 user's keyboard layout to the standard keyboard layout. See the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
391 documentation of `quail-keyboard-layout' and
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
392 `quail-keyboard-layout-standard' for more detail.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
393
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
394 SHOW-LAYOUT non-nil means the `quail-help' command should show
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
395 the user's keyboard layout visually with translated characters.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
396 If KBD-TRANSLATE is set, it is desirable to set also this flag unless
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
397 this package defines no translations for single character keys.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
398
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
399 CREATE-DECODE-MAP non-nil means decode map is also created. A decode
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
400 map is an alist of translations and corresponding original keys.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
401 Although this map is not used by Quail itself, it can be used by some
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
402 other programs. For instance, Vietnamese supporting needs this map to
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
403 convert Vietnamese text to VIQR format which uses only ASCII
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
404 characters to represent Vietnamese characters.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
405
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
406 MAXIMUM-SHORTEST non-nil means break key sequence to get maximum
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
407 length of the shortest sequence. When we don't have a translation of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
408 key \"..ABCD\" but have translations of \"..AB\" and \"CD..\", break
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
409 the key at \"..AB\" and start translation of \"CD..\". Hangul
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
410 packages, for instance, use this facility. If this flag is nil, we
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
411 break the key just at \"..ABC\" and start translation of \"D..\".
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
412
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
413 OVERLAY-PLIST if non-nil is a property list put on an overlay which
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
414 covers Quail translation region.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
415
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
416 UPDATE-TRANSLATION-FUNCTION if non-nil is a function to call to update
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
417 the current translation region accoding to a new translation data. By
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
418 default, a tranlated text or a user's key sequence (if no transltion
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
419 for it) is inserted.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
420
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
421 CONVERSION-KEYS specifies additional key bindings used while
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
422 conversion region is active. It is an alist of single key character
19619
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
423 vs. corresponding command to be called.
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
424
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
425 If SIMPLE is non-nil, then we do not alter the meanings of
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
426 commands such as C-f, C-b, C-n, C-p and TAB; they are treated as
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
427 non-Quail commands."
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
428 (let (translation-keymap conversion-keymap)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
429 (if deterministic (setq forget-last-selection t))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
430 (if translation-keys
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
431 (progn
19619
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
432 (setq translation-keymap (copy-keymap
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
433 (if simple quail-simple-translation-keymap
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
434 quail-translation-keymap)))
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
435 (while translation-keys
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
436 (define-key translation-keymap
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
437 (car (car translation-keys)) (cdr (car translation-keys)))
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
438 (setq translation-keys (cdr translation-keys))))
19619
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
439 (setq translation-keymap
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
440 (if simple quail-simple-translation-keymap
b033d0b34c71 (quail-define-package): New arg SIMPLE.
Richard M. Stallman <rms@gnu.org>
parents: 19605
diff changeset
441 quail-translation-keymap)))
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
442 (when conversion-keys
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
443 (setq conversion-keymap (copy-keymap quail-conversion-keymap))
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
444 (while conversion-keys
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
445 (define-key conversion-keymap
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
446 (car (car conversion-keys)) (cdr (car conversion-keys)))
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
447 (setq conversion-keys (cdr conversion-keys))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
448 (quail-add-package
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
449 (list name title (list nil) guidance (or docstring "")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
450 translation-keymap
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
451 forget-last-selection deterministic kbd-translate show-layout
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
452 (if create-decode-map (list 'decode-map) nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
453 maximum-shortest overlay-plist update-translation-function
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
454 conversion-keymap))
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
455
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
456 ;; Update input-method-alist.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
457 (let ((slot (assoc name input-method-alist))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
458 (val (list language 'quail-use-package title docstring)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
459 (if slot (setcdr slot val)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
460 (setq input-method-alist (cons (cons name val) input-method-alist)))))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
461
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
462 (quail-select-package name))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
463
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
464 ;; Quail minor mode handlers.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
465
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
466 ;; Setup overlays used in Quail mode.
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
467 (defun quail-setup-overlays (conversion-mode)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
468 (let ((pos (point)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
469 (if (overlayp quail-overlay)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
470 (move-overlay quail-overlay pos pos)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
471 (setq quail-overlay (make-overlay pos pos nil nil t))
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
472 (if input-method-highlight-flag
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
473 (overlay-put quail-overlay 'face 'underline))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
474 (let ((l (quail-overlay-plist)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
475 (while l
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
476 (overlay-put quail-overlay (car l) (car (cdr l)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
477 (setq l (cdr (cdr l))))))
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
478 (if conversion-mode
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
479 (if (overlayp quail-conv-overlay)
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
480 (if (not (overlay-start quail-conv-overlay))
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
481 (move-overlay quail-conv-overlay pos pos))
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
482 (setq quail-conv-overlay (make-overlay pos pos nil nil t))
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
483 (if input-method-highlight-flag
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
484 (overlay-put quail-conv-overlay 'face 'underline))))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
485
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
486 ;; Delete overlays used in Quail mode.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
487 (defun quail-delete-overlays ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
488 (if (overlayp quail-overlay)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
489 (delete-overlay quail-overlay))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
490 (if (overlayp quail-conv-overlay)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
491 (delete-overlay quail-conv-overlay)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
492
19432
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
493 ;; Kill Quail guidance buffer. Set in kill-buffer-hook.
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
494 (defun quail-kill-guidance-buf ()
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
495 (if (buffer-live-p quail-guidance-buf)
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
496 (kill-buffer quail-guidance-buf)))
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
497
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
498 (defun quail-mode (&optional arg)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
499 "Toggle Quail minor mode.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
500 With arg, turn Quail mode on if and only if arg is positive.
19432
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
501
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
502 You should not turn on and off Quail mode manually, instead use
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
503 the commands `toggle-input-method' or `select-input-methods' (which
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
504 see). They automatically turn on or off this mode.
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
505
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
506 Try \\[describe-bindings] in Quail mode to see the available key bindings.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
507 The command \\[describe-input-method] describes the current Quail package."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
508 (setq quail-mode
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
509 (if (null arg) (null quail-mode)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
510 (> (prefix-numeric-value arg) 0)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
511 (if (null quail-mode)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
512 ;; Let's turn off Quail mode.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
513 (progn
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
514 (quail-hide-guidance-buf)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
515 (quail-delete-overlays)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
516 (setq describe-current-input-method-function nil)
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
517 (run-hooks 'quail-mode-exit-hook))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
518 ;; Let's turn on Quail mode.
17764
561a8476368f (use-quail-package): Error message added.
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
519 ;; At first, be sure that quail-mode is at the first element of
561a8476368f (use-quail-package): Error message added.
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
520 ;; minor-mode-map-alist.
561a8476368f (use-quail-package): Error message added.
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
521 (or (eq (car minor-mode-map-alist) 'quail-mode)
561a8476368f (use-quail-package): Error message added.
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
522 (let ((l minor-mode-map-alist))
561a8476368f (use-quail-package): Error message added.
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
523 (while (cdr l)
561a8476368f (use-quail-package): Error message added.
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
524 (if (eq (car (cdr l)) 'quail-mode)
561a8476368f (use-quail-package): Error message added.
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
525 (progn
561a8476368f (use-quail-package): Error message added.
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
526 (setcdr l (cdr (cdr l)))
561a8476368f (use-quail-package): Error message added.
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
527 (setq l nil))
561a8476368f (use-quail-package): Error message added.
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
528 (setq l (cdr l))))
561a8476368f (use-quail-package): Error message added.
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
529 (setq minor-mode-map-alist (cons 'quail-mode minor-mode-map-alist))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
530 (if (null quail-current-package)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
531 ;; Quail package is not yet selected. Select one now.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
532 (let (name)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
533 (if quail-package-alist
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
534 (setq name (car (car quail-package-alist)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
535 (setq quail-mode nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
536 (error "No Quail package loaded"))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
537 (quail-select-package name)))
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
538 (setq inactivate-current-input-method-function 'quail-inactivate)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
539 (setq describe-current-input-method-function 'quail-help)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
540 (quail-delete-overlays)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
541 (quail-show-guidance-buf)
19432
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
542 ;; If we are in minibuffer, turn off the current input method
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
543 ;; before exiting.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
544 (if (eq (selected-window) (minibuffer-window))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
545 (add-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
546 (make-local-hook 'post-command-hook)
19432
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
547 (make-local-hook 'kill-buffer-hook)
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
548 (add-hook 'kill-buffer-hook 'quail-kill-guidance-buf nil t)
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
549 (run-hooks 'quail-mode-hook))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
550 (force-mode-line-update))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
551
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
552 (defun quail-exit-from-minibuffer ()
19432
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
553 (inactivate-input-method)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
554 (if (<= (minibuffer-depth) 1)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
555 (remove-hook 'minibuffer-exit-hook 'quail-exit-from-minibuffer)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
556
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
557 (defvar quail-saved-current-map nil)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
558 (defvar quail-saved-current-buffer nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
559
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
560 ;; Toggle Quail mode. This function is added to `post-command-hook'
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
561 ;; in Quail mode, to turn Quail mode temporarily off, or back on after
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
562 ;; one non-Quail command.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
563 (defun quail-toggle-mode-temporarily ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
564 (if quail-mode
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
565 ;; We are going to handle following events out of Quail mode.
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
566 (setq quail-saved-current-buffer (current-buffer)
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
567 quail-saved-current-map overriding-terminal-local-map
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
568 quail-mode nil
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
569 overriding-terminal-local-map nil)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
570 ;; We have just executed one non-Quail command. We don't need
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
571 ;; this hook any more.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
572 (remove-hook 'post-command-hook 'quail-toggle-mode-temporarily t)
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
573 (if (eq (current-buffer) quail-saved-current-buffer)
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
574 ;; We should go back to Quail mode only when the current input
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
575 ;; method was not turned off by the last command.
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
576 (when current-input-method
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
577 (setq quail-mode t
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
578 overriding-terminal-local-map quail-saved-current-map)
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
579 (if input-method-exit-on-invalid-key
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
580 (inactivate-input-method)))
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
581 ;; The last command changed the current buffer, we should not go
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
582 ;; back to Quail mode in this new buffer, but should turn on
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
583 ;; Quail mode in the original buffer.
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
584 (save-excursion
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
585 (set-buffer quail-saved-current-buffer)
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
586 (setq quail-mode t)
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
587 (quail-delete-overlays)))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
588
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
589 (defun quail-execute-non-quail-command ()
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
590 "Execute one non-Quail command out of Quail mode.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
591 The current translation and conversion are terminated."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
592 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
593 (setq unread-command-events (cons last-input-event unread-command-events))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
594 (quail-delete-overlays)
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
595 (setq overriding-terminal-local-map nil)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
596 (if (buffer-live-p quail-guidance-buf)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
597 (save-excursion
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
598 (set-buffer quail-guidance-buf)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
599 (erase-buffer)))
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
600 (add-hook 'post-command-hook 'quail-toggle-mode-temporarily nil t))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
601
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
602 ;; Keyboard layout translation handlers.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
603
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
604 ;; Some Quail packages provide localized keyboard simulation which
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
605 ;; requires a particular keyboard layout. In this case, what we need
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
606 ;; is locations of keys the user entered, not character codes
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
607 ;; generated by those keys. However, for the moment, there's no
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
608 ;; common way to get such information. So, we ask a user to give
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
609 ;; information of his own keyboard layout, then translate it to the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
610 ;; standard layout which we defined so that all Quail packages depend
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
611 ;; just on it.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
612
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
613 (defconst quail-keyboard-layout-standard
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
614 "\
17174
9c1191812679 (quail-translation-keymap): Add entry for escape key.
Kenichi Handa <handa@m17n.org>
parents: 17095
diff changeset
615 \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
616 1!2@3#4$5%6^7&8*9(0)-_=+`~ \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
617 qQwWeErRtTyYuUiIoOpP[{]} \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
618 aAsSdDfFgGhHjJkKlL;:'\"\\| \
17174
9c1191812679 (quail-translation-keymap): Add entry for escape key.
Kenichi Handa <handa@m17n.org>
parents: 17095
diff changeset
619 zZxXcCvVbBnNmM,<.>/? \
9c1191812679 (quail-translation-keymap): Add entry for escape key.
Kenichi Handa <handa@m17n.org>
parents: 17095
diff changeset
620 "
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
621 "Standard keyboard layout of printable characters Quail assumes.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
622 See the documentation of `quail-keyboard-layout' for this format.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
623 This layout is almost the same as that of VT100,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
624 but the location of key \\ (backslash) is just right of key ' (single-quote),
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
625 not right of RETURN key.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
626
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
627 (defvar quail-keyboard-layout quail-keyboard-layout-standard
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
628 "A string which represents physical key layout of a particular keyboard.
17174
9c1191812679 (quail-translation-keymap): Add entry for escape key.
Kenichi Handa <handa@m17n.org>
parents: 17095
diff changeset
629 We assume there are six rows and each row has 15 keys (columns),
9c1191812679 (quail-translation-keymap): Add entry for escape key.
Kenichi Handa <handa@m17n.org>
parents: 17095
diff changeset
630 the first row is above the `1' - `0' row,
9c1191812679 (quail-translation-keymap): Add entry for escape key.
Kenichi Handa <handa@m17n.org>
parents: 17095
diff changeset
631 the first column of the second row is left of key `1',
9c1191812679 (quail-translation-keymap): Add entry for escape key.
Kenichi Handa <handa@m17n.org>
parents: 17095
diff changeset
632 the first column of the third row is left of key `q',
9c1191812679 (quail-translation-keymap): Add entry for escape key.
Kenichi Handa <handa@m17n.org>
parents: 17095
diff changeset
633 the first column of the fourth row is left of key `a',
9c1191812679 (quail-translation-keymap): Add entry for escape key.
Kenichi Handa <handa@m17n.org>
parents: 17095
diff changeset
634 the first column of the fifth row is left of key `z',
9c1191812679 (quail-translation-keymap): Add entry for escape key.
Kenichi Handa <handa@m17n.org>
parents: 17095
diff changeset
635 the sixth row is below the `z' - `/' row.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
636 Nth (N is even) and (N+1)th characters in the string are non-shifted
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
637 and shifted characters respectively at the same location.
19391
763bc03e7797 (quail-guidance-buf): Now a permanent local.
Richard M. Stallman <rms@gnu.org>
parents: 19327
diff changeset
638 The location of Nth character is row (N / 30) and column ((N mod 30) / 2).
763bc03e7797 (quail-guidance-buf): Now a permanent local.
Richard M. Stallman <rms@gnu.org>
parents: 19327
diff changeset
639 The command `quail-set-keyboard-layout' usually sets this variable.")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
640
17174
9c1191812679 (quail-translation-keymap): Add entry for escape key.
Kenichi Handa <handa@m17n.org>
parents: 17095
diff changeset
641 (defconst quail-keyboard-layout-len 180)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
642
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
643 ;; Here we provide several examples of famous keyboard layouts.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
644
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
645 (defvar quail-keyboard-layout-alist
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
646 (list
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
647 '("sun-type3" . "\
17174
9c1191812679 (quail-translation-keymap): Add entry for escape key.
Kenichi Handa <handa@m17n.org>
parents: 17095
diff changeset
648 \
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
649 1!2@3#4$5%6^7&8*9(0)-_=+\\|`~\
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
650 qQwWeErRtTyYuUiIoOpP[{]} \
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
651 aAsSdDfFgGhHjJkKlL;:'\" \
17174
9c1191812679 (quail-translation-keymap): Add entry for escape key.
Kenichi Handa <handa@m17n.org>
parents: 17095
diff changeset
652 zZxXcCvVbBnNmM,<.>/? \
9c1191812679 (quail-translation-keymap): Add entry for escape key.
Kenichi Handa <handa@m17n.org>
parents: 17095
diff changeset
653 ")
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
654 (cons "standard" quail-keyboard-layout-standard))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
655 "Alist of keyboard names and corresponding layout strings.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
656 See the documentation of `quail-keyboard-layout' for the format of
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
657 the layout string.")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
658
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
659 (defun quail-set-keyboard-layout (kbd-type)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
660 "Set the current keyboard layout to the same as keyboard KBD-TYPE.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
661
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
662 Since some Quail packages depends on a physical layout of keys (not
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
663 characters generated by them), those are created by assuming the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
664 standard layout defined in `quail-keyboard-layout-standard'. This
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
665 function tells Quail system the layout of your keyboard so that what
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
666 you type is correctly handled."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
667 (interactive
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
668 (let* ((completing-ignore-case t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
669 (type (completing-read "Keyboard type: "
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
670 quail-keyboard-layout-alist)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
671 (list type)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
672 (let ((layout (assoc kbd-type quail-keyboard-layout-alist)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
673 (if (null layout)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
674 ;; Here, we had better ask a user to define his own keyboard
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
675 ;; layout interactively.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
676 (error "Unknown keyboard type `%s'" kbd-type))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
677 (setq quail-keyboard-layout (cdr layout))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
678
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
679 (defun quail-keyboard-translate (ch)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
680 "Translate CHAR according to `quail-keyboard-layout' and return the result."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
681 (if (eq quail-keyboard-layout quail-keyboard-layout-standard)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
682 ch
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
683 (let ((i 0))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
684 (while (and (< i quail-keyboard-layout-len)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
685 (/= ch (aref quail-keyboard-layout i)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
686 (setq i (1+ i)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
687 (if (= i quail-keyboard-layout-len)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
688 (error "Character `%c' not found in your keyboard layout" ch))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
689 (aref quail-keyboard-layout-standard i))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
690
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
691 ;; Quail map
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
692
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
693 (defsubst quail-map-p (object)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
694 "Return t if OBJECT is a Quail map.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
695
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
696 A Quail map holds information how a particular key should be translated.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
697 Its format is (TRANSLATION . ALIST).
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
698 TRANSLATION is either a character, or a cons (INDEX . VECTOR).
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
699 In the latter case, each element of VECTOR is a candidate for the translation,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
700 and INDEX points the currently selected translation.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
701
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
702 ALIST is normally a list of elements that look like (CHAR . DEFN),
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
703 where DEFN is another Quail map for a longer key (CHAR added to the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
704 current key). It may also be a symbol of a function which returns an
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
705 alist of the above format.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
706
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
707 Just after a Quail package is read, TRANSLATION may be a string or a
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
708 vector. Then each element of the string or vector is a candidate for
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
709 the translation. These objects are transformed to cons cells in the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
710 format \(INDEX . VECTOR), as described above."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
711 (and (consp object)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
712 (let ((translation (car object)))
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
713 (or (integerp translation) (null translation)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
714 (vectorp translation) (stringp translation)
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
715 (symbolp translation)
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
716 (and (consp translation) (not (vectorp (cdr translation))))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
717 (let ((alist (cdr object)))
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
718 (or (and (listp alist) (consp (car alist)))
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
719 (symbolp alist)))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
720
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
721 ;;;###autoload
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
722 (defmacro quail-define-rules (&rest rules)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
723 "Define translation rules of the current Quail package.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
724 Each argument is a list of KEY and TRANSLATION.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
725 KEY is a string meaning a sequence of keystrokes to be translated.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
726 TRANSLATION is a character, a string, a vector, a Quail map, or a function.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
727 It it is a character, it is the sole translation of KEY.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
728 If it is a string, each character is a candidate for the translation.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
729 If it is a vector, each element (string or character) is a candidate
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
730 for the translation.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
731 In these cases, a key specific Quail map is generated and assigned to KEY.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
732
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
733 If TRANSLATION is a Quail map or a function symbol which returns a Quail map,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
734 it is used to handle KEY."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
735 `(quail-install-map
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
736 ',(let ((l rules)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
737 (map (list nil)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
738 (while l
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
739 (quail-defrule-internal (car (car l)) (car (cdr (car l))) map)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
740 (setq l (cdr l)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
741 map)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
742
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
743 ;;;###autoload
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
744 (defun quail-install-map (map)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
745 "Install the Quail map MAP in the current Quail package.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
746 The installed map can be referred by the function `quail-map'."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
747 (if (null quail-current-package)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
748 (error "No current Quail package"))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
749 (if (null (quail-map-p map))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
750 (error "Invalid Quail map `%s'" map))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
751 (setcar (cdr (cdr quail-current-package)) map))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
752
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
753 ;;;###autoload
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
754 (defun quail-defrule (key translation &optional name)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
755 "Add one translation rule, KEY to TRANSLATION, in the current Quail package.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
756 KEY is a string meaning a sequence of keystrokes to be translated.
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
757 TRANSLATION is a character, a string, a vector, a Quail map,
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
758 a function, or a cons.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
759 It it is a character, it is the sole translation of KEY.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
760 If it is a string, each character is a candidate for the translation.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
761 If it is a vector, each element (string or character) is a candidate
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
762 for the translation.
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
763 If it is a cons, the car is one of the above and the cdr is a function
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
764 to call when translating KEY (the return value is assigned to the
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
765 variable `quail-current-data'). If the cdr part is not a function,
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
766 the value itself is assigned to `quail-current-data'.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
767 In these cases, a key specific Quail map is generated and assigned to KEY.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
768
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
769 If TRANSLATION is a Quail map or a function symbol which returns a Quail map,
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
770 it is used to handle KEY.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
771 Optional argument NAME, if specified, says which Quail package
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
772 to define this translation rule in. The default is to define it in the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
773 current Quail package."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
774 (if name
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
775 (let ((package (quail-package name)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
776 (if (null package)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
777 (error "No Quail package `%s'" name))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
778 (setq quail-current-package package)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
779 (quail-defrule-internal key translation (quail-map)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
780
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
781 ;;;###autoload
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
782 (defun quail-defrule-internal (key trans map)
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
783 "Define KEY as TRANS in a Quail map MAP."
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
784 (if (null (stringp key))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
785 "Invalid Quail key `%s'" key)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
786 (if (not (or (numberp trans) (stringp trans) (vectorp trans)
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
787 (consp trans)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
788 (symbolp trans)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
789 (quail-map-p trans)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
790 (error "Invalid Quail translation `%s'" trans))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
791 (if (null (quail-map-p map))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
792 (error "Invalid Quail map `%s'" map))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
793 (let ((len (length key))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
794 (idx 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
795 ch entry)
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
796 ;; Make a map for registering TRANS if necessary.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
797 (while (< idx len)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
798 (if (null (consp map))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
799 ;; We come here, for example, when we try to define a rule
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
800 ;; for "ABC" but a rule for "AB" is already defined as a
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
801 ;; symbol.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
802 (error "Quail key %s is too long" key))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
803 (setq ch (aref key idx)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
804 entry (assq ch (cdr map)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
805 (if (null entry)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
806 (progn
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
807 (setq entry (cons ch (list nil)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
808 (setcdr map (cons entry (cdr map)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
809 (setq map (cdr entry))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
810 (setq idx (1+ idx)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
811 (if (symbolp trans)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
812 (if (cdr map)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
813 ;; We come here, for example, when we try to define a rule
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
814 ;; for "AB" as a symbol but a rule for "ABC" is already
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
815 ;; defined.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
816 (error "Quail key %s is too short" key)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
817 (setcdr entry trans))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
818 (if (quail-map-p trans)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
819 (if (not (listp (cdr map)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
820 ;; We come here, for example, when we try to define a rule
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
821 ;; for "AB" as a symbol but a rule for "ABC" is already
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
822 ;; defined.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
823 (error "Quail key %s is too short" key)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
824 (if (not (listp (cdr trans)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
825 (if (cdr map)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
826 ;; We come here, for example, when we try to
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
827 ;; define a rule for "AB" as a symbol but a rule
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
828 ;; for "ABC" is already defined.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
829 (error "Quail key %s is too short" key)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
830 (setcdr entry trans))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
831 (setcdr entry (append trans (cdr map)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
832 (setcar map trans)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
833
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
834 (defun quail-get-translation (def key len)
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
835 "Return the translation specified as DEF for KEY of length LEN.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
836 The translation is either a character or a cons of the form (INDEX . VECTOR),
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
837 where VECTOR is a vector of candidates (character or string) for
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
838 the translation, and INDEX points into VECTOR to specify the currently
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
839 selected translation."
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
840 (if (and def (symbolp def))
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
841 ;; DEF is a symbol of a function which returns valid translation.
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
842 (setq def (funcall def key len)))
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
843 (if (and (consp def) (not (vectorp (cdr def))))
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
844 (setq def (car def)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
845
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
846 (cond
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
847 ((or (integerp def) (consp def))
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
848 def)
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
849
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
850 ((null def)
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
851 ;; No translation.
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
852 nil)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
853
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
854 ((stringp def)
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
855 ;; Each character in DEF is a candidate of translation. Reform
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
856 ;; it as (INDICES . VECTOR).
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
857 (setq def (string-to-vector def))
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
858 ;; But if the length is 1, we don't need vector but a single
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
859 ;; candidate as the translation.
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
860 (if (= (length def) 1)
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
861 (aref def 0)
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
862 (cons (list 0 0 0 0 nil) def)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
863
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
864 ((vectorp def)
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
865 ;; Each element (string or character) in DEF is a candidate of
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
866 ;; translation. Reform it as (INDICES . VECTOR).
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
867 (cons (list 0 0 0 0 nil) def))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
868
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
869 (t
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
870 (error "Invalid object in Quail map: %s" def))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
871
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
872 (defun quail-lookup-key (key &optional len)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
873 "Lookup KEY of length LEN in the current Quail map and return the definition.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
874 The returned value is a Quail map specific to KEY."
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
875 (or len
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
876 (setq len (length key)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
877 (let ((idx 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
878 (map (quail-map))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
879 (kbd-translate (quail-kbd-translate))
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
880 slot ch translation def)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
881 (while (and map (< idx len))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
882 (setq ch (if kbd-translate (quail-keyboard-translate (aref key idx))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
883 (aref key idx)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
884 (setq idx (1+ idx))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
885 (if (and (cdr map) (symbolp (cdr map)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
886 (setcdr map (funcall (cdr map) key idx)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
887 (setq slot (assq ch (cdr map)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
888 (if (and (cdr slot) (symbolp (cdr slot)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
889 (setcdr slot (funcall (cdr slot) key idx)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
890 (setq map (cdr slot)))
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
891 (setq def (car map))
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
892 (setq quail-current-translations nil)
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
893 (if (and map (setq translation (quail-get-translation def key len)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
894 (progn
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
895 (if (and (consp def) (not (vectorp (cdr def))))
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
896 (progn
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
897 (if (not (equal (car def) translation))
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
898 ;; We must reflect TRANSLATION to car part of DEF.
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
899 (setcar def translation))
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
900 (setq quail-current-data
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
901 (if (functionp (cdr def))
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
902 (funcall (cdr def))
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
903 (cdr def))))
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
904 (if (not (equal def translation))
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
905 ;; We must reflect TRANSLATION to car part of MAP.
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
906 (setcar map translation)))
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
907 (if (and (consp translation) (vectorp (cdr translation)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
908 (progn
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
909 (setq quail-current-translations translation)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
910 (if (quail-forget-last-selection)
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
911 (setcar (car quail-current-translations) 0))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
912 ;; We may have to reform cdr part of MAP.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
913 (if (and (cdr map) (symbolp (cdr map)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
914 (progn
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
915 (setcdr map (funcall (cdr map) key len))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
916 ))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
917 map))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
918
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
919 ;; If set to non-nil, exit conversion mode before starting new translation.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
920 (defvar quail-exit-conversion-mode nil)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
921
18201
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
922 (defvar quail-prefix-arg nil)
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
923
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
924 (defun quail-start-translation (arg)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
925 "Start translating the typed character in Quail mode."
18201
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
926 (interactive "*p")
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
927 (setq prefix-arg arg)
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
928 (setq quail-prefix-arg arg)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
929 (setq unread-command-events
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
930 (cons last-command-event unread-command-events))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
931 ;; Check the possibility of translating the last key.
19432
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
932 (if (and (integerp last-command-event)
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
933 (assq (if (quail-kbd-translate)
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
934 (quail-keyboard-translate last-command-event)
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
935 last-command-event)
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
936 (cdr (quail-map))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
937 ;; Ok, we can start translation.
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
938 (if (quail-conversion-keymap)
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
939 ;; We must start translation in conversion mode.
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
940 (setq quail-exit-conversion-mode nil
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
941 overriding-terminal-local-map (quail-conversion-keymap))
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
942 (quail-setup-overlays nil)
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
943 (setq quail-current-key "")
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
944 (setq overriding-terminal-local-map (quail-translation-keymap)))
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
945 ;; Since the last event doesn't start any translation, handle it
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
946 ;; out of Quail mode. We come back to Quail mode later by setting
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
947 ;; function `quail-toggle-mode-temporarily' in
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
948 ;; `post-command-hook'.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
949 (add-hook 'post-command-hook 'quail-toggle-mode-temporarily nil t)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
950
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
951 (defsubst quail-point-in-conversion-region ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
952 "Return non-nil value if the point is in conversion region of Quail mode."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
953 (let (start pos)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
954 (and (setq start (overlay-start quail-conv-overlay))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
955 (>= (setq pos (point)) start)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
956 (<= pos (overlay-end quail-conv-overlay)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
957
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
958 (defun quail-start-translation-in-conversion-mode ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
959 "Start translating the typed character in conversion mode of Quail mode."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
960 (interactive "*")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
961 (setq unread-command-events
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
962 (cons last-command-event unread-command-events))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
963 ;; Check the possibility of translating the last key.
19432
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
964 (if (and (integerp last-command-event)
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
965 (assq (if (quail-kbd-translate)
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
966 (quail-keyboard-translate last-command-event)
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
967 last-command-event)
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
968 (cdr (quail-map))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
969 ;; Ok, we can start translation.
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
970 (progn
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
971 (quail-setup-overlays t)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
972 (setq quail-current-key "")
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
973 (setq overriding-terminal-local-map (quail-translation-keymap))
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
974 (move-overlay quail-overlay (point) (point)))
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
975 ;; Since the last event doesn't start any translation, handle it
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
976 ;; out of Quail mode. We come back to Quail mode later by setting
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
977 ;; function `quail-toggle-mode-temporarily' in
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
978 ;; `post-command-hook'.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
979 (add-hook 'post-command-hook 'quail-toggle-mode-temporarily nil t)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
980
18201
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
981 (defsubst quail-delete-region ()
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
982 "Delete the text in the current translation region of Quail."
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
983 (if (overlay-start quail-overlay)
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
984 (delete-region (overlay-start quail-overlay)
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
985 (overlay-end quail-overlay))))
18201
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
986
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
987 (defun quail-terminate-translation ()
19519
1c0ecc266e38 (quail-terminate-translation): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 19453
diff changeset
988 "Terminate the translation of the current key."
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
989 (let ((start (overlay-start quail-overlay)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
990 (if (and start
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
991 (< start (overlay-end quail-overlay)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
992 ;; Here we simulate self-insert-command.
18201
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
993 (let ((seq (string-to-sequence
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
994 (buffer-substring (overlay-start quail-overlay)
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
995 (overlay-end quail-overlay))
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
996 'list))
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
997 last-command-char)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
998 (goto-char start)
18201
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
999 (quail-delete-region)
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
1000 (setq last-command-char (car seq))
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
1001 (self-insert-command (or quail-prefix-arg 1))
19519
1c0ecc266e38 (quail-terminate-translation): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 19453
diff changeset
1002 (setq quail-prefix-arg nil)
18201
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
1003 (setq seq (cdr seq))
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
1004 (while seq
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
1005 (setq last-command-char (car seq))
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
1006 (self-insert-command 1)
feea31893155 (quail-prefix-arg): New variable.
Kenichi Handa <handa@m17n.org>
parents: 17764
diff changeset
1007 (setq seq (cdr seq))))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1008 (delete-overlay quail-overlay)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1009 (if (buffer-live-p quail-guidance-buf)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1010 (save-excursion
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1011 (set-buffer quail-guidance-buf)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1012 (erase-buffer)))
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
1013 (setq overriding-terminal-local-map
19453
e6134c179b4c (quail-terminate-translation): Run
Kenichi Handa <handa@m17n.org>
parents: 19432
diff changeset
1014 (quail-conversion-keymap))
e6134c179b4c (quail-terminate-translation): Run
Kenichi Handa <handa@m17n.org>
parents: 19432
diff changeset
1015 ;; Run this hook only when the current input method doesn't require
19519
1c0ecc266e38 (quail-terminate-translation): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 19453
diff changeset
1016 ;; conversion. When conversion is required, the conversion function
1c0ecc266e38 (quail-terminate-translation): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 19453
diff changeset
1017 ;; should run this hook at a proper timing.
19453
e6134c179b4c (quail-terminate-translation): Run
Kenichi Handa <handa@m17n.org>
parents: 19432
diff changeset
1018 (unless (quail-conversion-keymap)
e6134c179b4c (quail-terminate-translation): Run
Kenichi Handa <handa@m17n.org>
parents: 19432
diff changeset
1019 (run-hooks 'input-method-after-insert-chunk-hook)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1020
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1021 (defun quail-select-current ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1022 "Select the current text shown in Quail translation region."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1023 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1024 (quail-terminate-translation))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1025
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1026 ;; Update the current translation status according to CONTROL-FLAG.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1027 ;; If CONTROL-FLAG is integer value, it is the number of keys in the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1028 ;; head quail-current-key which can be translated. The remaining keys
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1029 ;; are put back to unread-command-events to be handled again.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1030 ;; If CONTROL-FLAG is t, terminate the translation for the whole keys
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1031 ;; in quail-current-key.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1032 ;; If CONTROL-FLAG is nil, proceed the translation with more keys.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1033
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1034 (defun quail-update-translation (control-flag)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1035 (quail-delete-region)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1036 (let ((func (quail-update-translation-function)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1037 (if func
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1038 (funcall func control-flag)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1039 (if (numberp control-flag)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1040 (let ((len (length quail-current-key)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1041 (while (> len control-flag)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1042 (setq len (1- len))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1043 (setq unread-command-events
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1044 (cons (aref quail-current-key len)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1045 unread-command-events)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1046 (insert (or quail-current-str
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1047 (substring quail-current-key 0 len))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1048 (insert (or quail-current-str quail-current-key)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1049 (quail-update-guidance)
19432
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
1050 (if control-flag
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
1051 (quail-terminate-translation)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1053 (defun quail-self-insert-command ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1054 "Add the typed character to the key for translation."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1055 (interactive "*")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1056 (setq quail-current-key
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1057 (concat quail-current-key (char-to-string last-command-event)))
19519
1c0ecc266e38 (quail-terminate-translation): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 19453
diff changeset
1058 (unless (catch 'quail-tag
1c0ecc266e38 (quail-terminate-translation): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 19453
diff changeset
1059 (quail-update-translation (quail-translate-key))
1c0ecc266e38 (quail-terminate-translation): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 19453
diff changeset
1060 t)
1c0ecc266e38 (quail-terminate-translation): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 19453
diff changeset
1061 ;; If someone throws for `quail-tag' by value nil, we exit from
1c0ecc266e38 (quail-terminate-translation): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 19453
diff changeset
1062 ;; translation mode.
1c0ecc266e38 (quail-terminate-translation): Doc-string
Kenichi Handa <handa@m17n.org>
parents: 19453
diff changeset
1063 (setq overriding-terminal-local-map nil)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1064
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1065 ;; Return the actual definition part of Quail map MAP.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1066 (defun quail-map-definition (map)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1067 (let ((def (car map)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1068 (if (and (consp def) (not (vectorp (cdr def))))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1069 (setq def (car def)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1070 def))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1071
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1072 ;; Return a string to be shown as the current translation of key
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1073 ;; sequence of length LEN. DEF is a definition part of Quail map for
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1074 ;; the sequence.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1075 (defun quail-get-current-str (len def)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1076 (or (and (consp def) (aref (cdr def) (car (car def))))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1077 def
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1078 (and (> len 1)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1079 (let ((str (quail-get-current-str
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1080 (1- len)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1081 (quail-map-definition (quail-lookup-key
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1082 quail-current-key (1- len))))))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1083 (if str
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1084 (concat (if (stringp str) str (char-to-string str))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1085 (substring quail-current-key (1- len) len)))))))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1086
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1087 (defvar quail-guidance-translations-starting-column 20)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1088
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1089 ;; Update `quail-current-translations' to make RELATIVE-INDEX the
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1090 ;; current translation.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1091 (defun quail-update-current-translations (&optional relative-index)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1092 (let* ((indices (car quail-current-translations))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1093 (cur (car indices))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1094 (start (nth 1 indices))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1095 (end (nth 2 indices)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1096 ;; Validate the index number of current translation.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1097 (if (< cur 0)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1098 (setcar indices (setq cur 0))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1099 (if (>= cur (length (cdr quail-current-translations)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1100 (setcar indices
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1101 (setq cur (1- (length (cdr quail-current-translations)))))))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1102
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1103 (if (or (null end) ; We have not yet calculated END.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1104 (< cur start) ; We moved to the previous block.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1105 (>= cur end)) ; We moved to the next block.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1106 (let ((len (length (cdr quail-current-translations)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1107 (maxcol (- (window-width quail-guidance-win)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1108 quail-guidance-translations-starting-column))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1109 (block (nth 3 indices))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1110 col idx width trans num-items blocks)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1111 (if (< cur start)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1112 ;; We must calculate from the head.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1113 (setq start 0 block 0)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1114 (if end ; i.e. (>= cur end)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1115 (setq start end)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1116 (setq idx start col 0 end start num-items 0)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1117 ;; Loop until we hit the tail, or reach the block of CUR.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1118 (while (and (< idx len) (>= cur end))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1119 (if (= num-items 0)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1120 (setq start idx col 0 block (1+ block)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1121 (setq trans (aref (cdr quail-current-translations) idx))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1122 (setq width (if (integerp trans) (char-width trans)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1123 (string-width trans)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1124 (setq col (+ col width 3) num-items (1+ num-items))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1125 (if (and (> num-items 0)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1126 (or (>= col maxcol) (> num-items 10)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1127 (setq end idx num-items 0)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1128 (setq idx (1+ idx))))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1129 (setcar (nthcdr 3 indices) block)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1130 (if (>= idx len)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1131 (progn
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1132 ;; We hit the tail before reaching MAXCOL.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1133 (setq end idx)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1134 (setcar (nthcdr 4 indices) block)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1135 (setcar (cdr indices) start)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1136 (setcar (nthcdr 2 indices) end)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1137 (if relative-index
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1138 (if (>= (+ start relative-index) end)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1139 (setcar indices end)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1140 (setcar indices (+ start relative-index))))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1141 (setq quail-current-str
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1142 (aref (cdr quail-current-translations) (car indices)))))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1143
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1144 (defun quail-translate-key ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1145 "Translate the current key sequence according to the current Quail map.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1146 Return t if we can terminate the translation.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1147 Return nil if the current key sequence may be followed by more keys.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1148 Return number if we can't find any translation for the current key
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1149 sequence. The number is the count of valid keys in the current
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1150 sequence counting from the head."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1151 (let* ((len (length quail-current-key))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1152 (map (quail-lookup-key quail-current-key len))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1153 def ch)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1154 (if map
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1155 (let ((def (quail-map-definition map)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1156 (setq quail-current-str (quail-get-current-str len def))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1157 ;; Return t only if we can terminate the current translation.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1158 (and
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1159 ;; No alternative translations.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1160 (or (null (consp def)) (= (length (cdr def)) 1))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1161 ;; No translation for the longer key.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1162 (null (cdr map))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1163 ;; No shorter breaking point.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1164 (or (null (quail-maximum-shortest))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1165 (< len 3)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1166 (null (quail-lookup-key quail-current-key (1- len)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1167 (null (quail-lookup-key
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1168 (substring quail-current-key -2 -1) 1)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1169
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1170 ;; There's no translation for the current key sequence. Before
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1171 ;; giving up, we must check two possibilities.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1172 (cond ((and
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1173 (quail-maximum-shortest)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1174 (>= len 4)
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1175 (setq def (quail-map-definition
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1176 (quail-lookup-key quail-current-key (- len 2))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1177 (quail-lookup-key (substring quail-current-key -2) 2))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1178 ;; Now the sequence is "...ABCD", which can be split into
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1179 ;; "...AB" and "CD..." to get valid translation.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1180 ;; At first, get translation of "...AB".
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1181 (setq quail-current-str (quail-get-current-str (- len 2) def))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1182 ;; Then, return the length of "...AB".
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1183 (- len 2))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1184
18797
e9aa787f0154 (quail-translate-key): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 18642
diff changeset
1185 ((and (> len 0)
e9aa787f0154 (quail-translate-key): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 18642
diff changeset
1186 (quail-lookup-key (substring quail-current-key 0 -1))
e9aa787f0154 (quail-translate-key): Fix previous change.
Kenichi Handa <handa@m17n.org>
parents: 18642
diff changeset
1187 quail-current-translations
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1188 (not (quail-deterministic))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1189 (setq ch (aref quail-current-key (1- len)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1190 (>= ch ?0) (<= ch ?9))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1191 ;; A numeric key is entered to select a desirable translation.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1192 (setq quail-current-key (substring quail-current-key 0 -1))
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1193 ;; We treat key 1,2..,9,0 as specifying 0,1,..8,9.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1194 (setq ch (if (= ch ?0) 9 (- ch ?1)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1195 (quail-update-current-translations ch)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1196 ;; And, we can terminate the current translation.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1197 t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1198
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1199 (t
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1200 ;; No way to handle the last character in this context.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1201 (1- len))))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1202
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1203 (defun quail-next-translation ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1204 "Select next translation in the current batch of candidates."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1205 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1206 (if quail-current-translations
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1207 (let ((indices (car quail-current-translations)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1208 (if (= (1+ (car indices)) (length (cdr quail-current-translations)))
19084
9f4b95f30c4f (quail-next-translation): Call
Kenichi Handa <handa@m17n.org>
parents: 18983
diff changeset
1209 ;; We are already at the tail.
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1210 (beep)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1211 (setcar indices (1+ (car indices)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1212 (quail-update-current-translations)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1213 (quail-update-translation nil)))
19084
9f4b95f30c4f (quail-next-translation): Call
Kenichi Handa <handa@m17n.org>
parents: 18983
diff changeset
1214 (quail-execute-non-quail-command)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1215
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1216 (defun quail-prev-translation ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1217 "Select previous translation in the current batch of candidates."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1218 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1219 (if quail-current-translations
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1220 (let ((indices (car quail-current-translations)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1221 (if (= (car indices) 0)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1222 ;; We are already at the head.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1223 (beep)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1224 (setcar indices (1- (car indices)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1225 (quail-update-current-translations)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1226 (quail-update-translation nil)))
19084
9f4b95f30c4f (quail-next-translation): Call
Kenichi Handa <handa@m17n.org>
parents: 18983
diff changeset
1227 (quail-execute-non-quail-command)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1228
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1229 (defun quail-next-translation-block ()
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1230 "Select from the next block of translations."
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1231 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1232 (if quail-current-translations
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1233 (let* ((indices (car quail-current-translations))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1234 (offset (- (car indices) (nth 1 indices))))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1235 (if (>= (nth 2 indices) (length (cdr quail-current-translations)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1236 ;; We are already at the last block.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1237 (beep)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1238 (setcar indices (+ (nth 2 indices) offset))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1239 (quail-update-current-translations)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1240 (quail-update-translation nil)))
19084
9f4b95f30c4f (quail-next-translation): Call
Kenichi Handa <handa@m17n.org>
parents: 18983
diff changeset
1241 (quail-execute-non-quail-command)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1242
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1243 (defun quail-prev-translation-block ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1244 "Select the previous batch of 10 translation candidates."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1245 (interactive)
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1246 (if quail-current-translations
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1247 (let* ((indices (car quail-current-translations))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1248 (offset (- (car indices) (nth 1 indices))))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1249 (if (= (nth 1 indices) 0)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1250 ;; We are already at the first block.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1251 (beep)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1252 (setcar indices (1- (nth 1 indices)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1253 (quail-update-current-translations)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1254 (if (< (+ (nth 1 indices) offset) (nth 2 indices))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1255 (progn
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1256 (setcar indices (+ (nth 1 indices) offset))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1257 (quail-update-current-translations)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1258 (quail-update-translation nil)))
19084
9f4b95f30c4f (quail-next-translation): Call
Kenichi Handa <handa@m17n.org>
parents: 18983
diff changeset
1259 (quail-execute-non-quail-command)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1260
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1261 (defun quail-abort-translation ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1262 "Abort translation and delete the current Quail key sequence."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1263 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1264 (quail-delete-region)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1265 (quail-terminate-translation))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1266
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1267 (defun quail-delete-last-char ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1268 "Delete the last input character from the current Quail key sequence."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1269 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1270 (if (= (length quail-current-key) 1)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1271 (quail-abort-translation)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1272 (setq quail-current-key (substring quail-current-key 0 -1))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1273 (quail-update-translation (quail-translate-key))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1274
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1275 ;; For conversion mode.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1276
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1277 (defun quail-conversion-backward-char ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1278 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1279 (if (<= (point) (overlay-start quail-conv-overlay))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1280 (error "Beginning of conversion region"))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1281 (forward-char -1))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1282
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1283 (defun quail-conversion-forward-char ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1284 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1285 (if (>= (point) (overlay-end quail-conv-overlay))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1286 (error "End of conversion region"))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1287 (forward-char 1))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1288
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1289 (defun quail-conversion-beginning-of-region ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1290 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1291 (goto-char (overlay-start quail-conv-overlay)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1292
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1293 (defun quail-conversion-end-of-region ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1294 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1295 (goto-char (overlay-end quail-conv-overlay)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1296
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1297 (defun quail-conversion-delete-char ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1298 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1299 (if (>= (point) (overlay-end quail-conv-overlay))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1300 (error "End of conversion region"))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1301 (delete-char 1)
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
1302 (when (= (overlay-start quail-conv-overlay)
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
1303 (overlay-end quail-conv-overlay))
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
1304 (quail-delete-overlays)
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
1305 (setq overriding-terminal-local-map nil)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1306
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1307 (defun quail-conversion-backward-delete-char ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1308 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1309 (if (<= (point) (overlay-start quail-conv-overlay))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1310 (error "Beginning of conversion region"))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1311 (delete-char -1)
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
1312 (when (= (overlay-start quail-conv-overlay)
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
1313 (overlay-end quail-conv-overlay))
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
1314 (quail-delete-overlays)
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
1315 (setq overriding-terminal-local-map nil)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1316
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1317 (defun quail-do-conversion (func &rest args)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1318 "Call FUNC to convert text in the current conversion region of Quail.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1319 Remaining args are for FUNC."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1320 (delete-overlay quail-overlay)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1321 (apply func args))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1322
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1323 (defun quail-no-conversion ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1324 "Do no conversion of the current conversion region of Quail."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1325 (interactive)
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
1326 (quail-delete-overlays)
19453
e6134c179b4c (quail-terminate-translation): Run
Kenichi Handa <handa@m17n.org>
parents: 19432
diff changeset
1327 (setq overriding-terminal-local-map nil)
e6134c179b4c (quail-terminate-translation): Run
Kenichi Handa <handa@m17n.org>
parents: 19432
diff changeset
1328 (run-hooks 'input-method-after-insert-chunk-hook))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1329
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1330 ;; Guidance, Completion, and Help buffer handlers.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1331
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1332 ;; Make a new one-line frame for Quail guidance buffer.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1333 (defun quail-make-guidance-frame (buf)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1334 (let* ((fparam (frame-parameters))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1335 (top (cdr (assq 'top fparam)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1336 (border (cdr (assq 'border-width fparam)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1337 (internal-border (cdr (assq 'internal-border-width fparam)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1338 (newtop (- top
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1339 (frame-char-height) (* internal-border 2) (* border 2))))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1340 (if (< newtop 0)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1341 (setq newtop (+ top (frame-pixel-height))))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1342 (let* ((frame (make-frame (append '((user-position . t) (height . 1)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1343 (minibuffer) (menu-bar-lines . 0))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1344 (cons (cons 'top newtop) fparam))))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1345 (win (frame-first-window frame)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1346 (set-window-buffer win buf)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1347 (set-window-dedicated-p win t))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1348
19432
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
1349 ;; Setup Quail completion buffer.
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
1350 (defun quail-setup-completion-buf ()
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
1351 (unless (buffer-live-p quail-completion-buf)
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
1352 (setq quail-completion-buf (get-buffer-create "*Quail Completions*"))
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
1353 (save-excursion
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
1354 (set-buffer quail-completion-buf)
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
1355 (setq quail-overlay (make-overlay 1 1))
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
1356 (overlay-put quail-overlay 'face 'highlight))))
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
1357
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1358 (defun quail-show-guidance-buf ()
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1359 "Display a guidance buffer for Quail input method in some window.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1360 Create the buffer if it does not exist yet.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1361 The buffer is normally displayed at the echo area,
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1362 but if the current buffer is a minibuffer, it is shown in
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1363 the bottom-most ordinary window of the same frame,
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1364 or in a newly created frame (if the selected frame has no other windows)."
19391
763bc03e7797 (quail-guidance-buf): Now a permanent local.
Richard M. Stallman <rms@gnu.org>
parents: 19327
diff changeset
1365 (if (and (not input-method-verbose-flag)
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1366 (eq (selected-window) (minibuffer-window)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1367 ;; We don't need the guidance buffer.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1368 nil
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1369 ;; At first, setup a guidance buffer.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1370 (or (buffer-live-p quail-guidance-buf)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1371 (setq quail-guidance-buf (generate-new-buffer " *Quail-guidance*")))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1372 (let ((title (quail-title)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1373 (save-excursion
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1374 (set-buffer quail-guidance-buf)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1375 ;; To show the title of Quail package.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1376 (setq current-input-method t
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1377 current-input-method-title title)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1378 (erase-buffer)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1379 (or (overlayp quail-overlay)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1380 (progn
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1381 (setq quail-overlay (make-overlay 1 1))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1382 (overlay-put quail-overlay 'face 'highlight)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1383 (delete-overlay quail-overlay)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1384 (set-buffer-modified-p nil)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1385 (bury-buffer quail-guidance-buf)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1386
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1387 ;; Then, display it in an appropriate window.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1388 (let ((win (minibuffer-window)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1389 (if (eq (selected-window) win)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1390 ;; Since we are in minibuffer, we can't use it for guidance.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1391 (if (eq win (frame-root-window))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1392 ;; Create a frame. It is sure that we are using some
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1393 ;; window system.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1394 (quail-make-guidance-frame quail-guidance-buf)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1395 ;; Find the bottom window and split it if necessary.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1396 (let (height)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1397 (setq win (window-at 0 (- (frame-height) 2)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1398 (setq height (window-height win))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1399 ;; If WIN is tall enough, split it vertically and use
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1400 ;; the lower one.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1401 (if (>= height 4)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1402 (let ((window-min-height 2))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1403 ;; Here, `split-window' returns a lower window
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1404 ;; which is what we wanted.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1405 (setq win (split-window win (- height 2)))))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1406 (set-window-buffer win quail-guidance-buf)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1407 (set-window-dedicated-p win t)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1408 (set-window-buffer win quail-guidance-buf))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1409 (setq quail-guidance-win win)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1410
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1411 ;; And, create a buffer for completion.
19432
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
1412 (quail-setup-completion-buf)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1413 (bury-buffer quail-completion-buf))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1414
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1415 (defun quail-hide-guidance-buf ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1416 "Hide the Quail guidance buffer."
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1417 (if (buffer-live-p quail-guidance-buf)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1418 (let ((win-list (get-buffer-window-list quail-guidance-buf t t))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1419 win)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1420 (while win-list
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1421 (setq win (car win-list) win-list (cdr win-list))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1422 (if (eq win (minibuffer-window))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1423 ;; We are using echo area for the guidance buffer.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1424 ;; Vacate it to the deepest minibuffer.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1425 (set-window-buffer win
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1426 (format " *Minibuf-%d*" (minibuffer-depth)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1427 (if (eq win (frame-root-window (window-frame win)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1428 (progn
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1429 ;; We are using a separate frame for guidance buffer.
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1430 ;;(set-window-dedicated-p win nil)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1431 (delete-frame (window-frame win)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1432 (set-window-dedicated-p win nil)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1433 (delete-window win)))))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1434
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1435 (defun quail-update-guidance ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1436 "Update the Quail guidance buffer and completion buffer (if displayed now)."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1437 ;; Update guidance buffer.
19391
763bc03e7797 (quail-guidance-buf): Now a permanent local.
Richard M. Stallman <rms@gnu.org>
parents: 19327
diff changeset
1438 (if (or input-method-verbose-flag
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1439 (not (eq (selected-window) (minibuffer-window))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1440 (let ((guidance (quail-guidance)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1441 (cond ((eq guidance t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1442 ;; Show the current possible translations.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1443 (quail-show-translations))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1444 ((null guidance)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1445 ;; Show the current input keys.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1446 (let ((key quail-current-key))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1447 (save-excursion
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1448 (set-buffer quail-guidance-buf)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1449 (erase-buffer)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1450 (insert key))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1451 ((listp guidance)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1452 ;; Show alternative characters specified in this alist.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1453 (let* ((key quail-current-key)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1454 (len (length key))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1455 (i 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1456 ch alternative)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1457 (save-excursion
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1458 (set-buffer quail-guidance-buf)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1459 (erase-buffer)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1460 (while (< i len)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1461 (setq ch (aref key i))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1462 (setq alternative (cdr (assoc ch guidance)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1463 (insert (or alternative ch))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1464 (setq i (1+ i)))))))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1465
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1466 ;; Update completion buffer if displayed now. We highlight the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1467 ;; selected candidate string in *Completion* buffer if any.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1468 (let ((win (get-buffer-window quail-completion-buf))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1469 key str pos)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1470 (if win
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1471 (save-excursion
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1472 (setq str (if (stringp quail-current-str)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1473 quail-current-str
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1474 (if (numberp quail-current-str)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1475 (char-to-string quail-current-str)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1476 key quail-current-key)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1477 (set-buffer quail-completion-buf)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1478 (goto-char (point-min))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1479 (if (null (search-forward (concat " " key ":") nil t))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1480 (delete-overlay quail-overlay)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1481 (setq pos (point))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1482 (if (and str (search-forward (concat "." str) nil t))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1483 (move-overlay quail-overlay (1+ (match-beginning 0)) (point))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1484 (move-overlay quail-overlay (match-beginning 0) (point)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1485 ;; Now POS points end of KEY and (point) points end of STR.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1486 (if (pos-visible-in-window-p (point) win)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1487 ;; STR is already visible.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1488 nil
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1489 ;; We want to make both KEY and STR visible, but if the
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1490 ;; window is too short, make at least STR visible.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1491 (setq pos (progn (point) (goto-char pos)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1492 (beginning-of-line)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1493 (set-window-start win (point))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1494 (if (not (pos-visible-in-window-p pos win))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1495 (set-window-start win pos))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1496 ))))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1497
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1498 (defun quail-show-translations ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1499 "Show the current possible translations."
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
1500 (let* ((key quail-current-key)
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1501 (map (quail-lookup-key quail-current-key)))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1502 (if quail-current-translations
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1503 (quail-update-current-translations))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1504 (save-excursion
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1505 (set-buffer quail-guidance-buf)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1506 (erase-buffer)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1507
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1508 ;; Show the current key.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1509 (insert key)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1510
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1511 ;; Show followable keys.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1512 (if (cdr map)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1513 (let ((l (cdr map)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1514 (insert "[")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1515 (while l
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1516 (insert (car (car l)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1517 (setq l (cdr l)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1518 (insert "]")))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1519
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1520 ;; Show list of translations.
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1521 (if quail-current-translations
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1522 (let* ((indices (car quail-current-translations))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1523 (cur (car indices))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1524 (start (nth 1 indices))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1525 (end (nth 2 indices))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1526 (idx start))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1527 (indent-to (- quail-guidance-translations-starting-column 7))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1528 (insert (format "(%02d/"(nth 3 indices))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1529 (if (nth 4 indices)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1530 (format "%02d)" (nth 4 indices))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1531 "??)"))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1532 (while (< idx end)
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1533 (insert (format " %d." (if (= (- idx start) 9) 0
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1534 (1+ (- idx start)))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1535 (let ((pos (point)))
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1536 (insert (aref (cdr quail-current-translations) idx))
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1537 (if (= idx cur)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1538 (move-overlay quail-overlay pos (point))))
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1539 (setq idx (1+ idx)))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1540 )))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1541
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1542 (defun quail-completion ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1543 "List all completions for the current key.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1544 All possible translations of the current key and whole possible longer keys
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1545 are shown."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1546 (interactive)
19432
4492653b04e8 (quail-exit-from-minibuffer): Call
Kenichi Handa <handa@m17n.org>
parents: 19404
diff changeset
1547 (quail-setup-completion-buf)
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1548 (let ((key quail-current-key)
18556
99e8ae18137f (quail-guidance-buf): Make it buffer
Kenichi Handa <handa@m17n.org>
parents: 18377
diff changeset
1549 (map (quail-lookup-key quail-current-key)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1550 (save-excursion
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1551 (set-buffer quail-completion-buf)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1552 (erase-buffer)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1553 (insert "Possible completion and corresponding translations are:\n")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1554 (quail-completion-1 key map 1)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1555 (goto-char (point-min))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1556 (display-buffer (current-buffer)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1557 (quail-update-guidance)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1558
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1559 ;; List all completions of KEY in MAP with indentation INDENT.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1560 (defun quail-completion-1 (key map indent)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1561 (let ((len (length key)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1562 (indent-to indent)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1563 (insert key ":")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1564 (if (and (symbolp map) (fboundp map))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1565 (setq map (funcall map key len)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1566 (if (car map)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1567 (quail-completion-list-translations map key (+ indent len 1))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1568 (insert " -\n"))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1569 (setq indent (+ indent 2))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1570 (if (cdr map)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1571 (let ((l (cdr map))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1572 (newkey (make-string (1+ len) 0))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1573 (i 0))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1574 ;; Set KEY in the first LEN characters of NEWKEY.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1575 (while (< i len)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1576 (aset newkey i (aref key i))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1577 (setq i (1+ i)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1578 (while l ; L = ((CHAR . DEFN) ....) ;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1579 (aset newkey len (car (car l)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1580 (quail-completion-1 newkey (cdr (car l)) indent)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1581 (setq l (cdr l)))))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1582
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1583 ;; List all possible translations of KEY in Quail map MAP with
17764
561a8476368f (use-quail-package): Error message added.
Kenichi Handa <handa@m17n.org>
parents: 17315
diff changeset
1584 ;; indentation INDENT.
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1585 (defun quail-completion-list-translations (map key indent)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1586 (let ((translations
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
1587 (quail-get-translation (car map) key (length key))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1588 (if (integerp translations)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1589 (insert "(1/1) 1." translations "\n")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1590 ;; We need only vector part.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1591 (setq translations (cdr translations))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1592 ;; Insert every 10 elements with indices in a line.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1593 (let ((len (length translations))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1594 (i 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1595 (first t)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1596 num)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1597 (while (< i len)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1598 (if first
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1599 (progn
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1600 (insert "(1/1)")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1601 (setq first nil))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1602 (if (= (% i 10) 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1603 (progn
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1604 (newline)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1605 (indent-to indent)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1606 (insert (format "(%d/%d)" (1+ (/ i 10)) (1+ (/ len 10)))))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1607 ;; We show the last digit of FROM while converting
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1608 ;; 0,1,..,9 to 1,2,..,0.
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1609 (insert (format " %d." (if (= (% i 10) 9) 0 (1+ (% i 10)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1610 (insert (aref translations i))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1611 (setq i (1+ i)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1612 (newline)))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1613
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1614 (defun quail-help ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1615 "Show brief description of the current Quail package."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1616 (interactive)
18349
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1617 (let ((package quail-current-package))
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1618 (with-output-to-temp-buffer "*Quail-Help*"
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1619 (save-excursion
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1620 (set-buffer standard-output)
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1621 (let ((quail-current-package package))
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1622 (insert "Quail input method (name:"
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1623 (quail-name)
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1624 ", mode line indicator:["
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1625 (quail-title)
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1626 "])\n---- Documentation ----\n"
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1627 (quail-docstring))
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1628 (newline)
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1629 (if (quail-show-layout) (quail-show-kbd-layout))
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1630 (quail-help-insert-keymap-description
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1631 quail-mode-map
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1632 "---- Key bindings (before starting translation) ----
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1633 key binding
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1634 --- -------\n")
18349
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1635 (quail-help-insert-keymap-description
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1636 (quail-translation-keymap)
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1637 "--- Key bindings (while translating) ---
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1638 key binding
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1639 --- -------\n")
18349
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1640 (if (quail-conversion-keymap)
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1641 (quail-help-insert-keymap-description
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1642 (quail-conversion-keymap)
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1643 "--- Key bindings (while converting) ---
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1644 key binding
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1645 --- -------\n"))
18349
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1646 (help-mode))))))
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1647
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1648 (defun quail-help-insert-keymap-description (keymap &optional header)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1649 (let (from to)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1650 (if header
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1651 (insert header))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1652 (save-excursion
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1653 (save-window-excursion
19404
8901359ae445 (quail-inactivate): Turn Quail mode off
Kenichi Handa <handa@m17n.org>
parents: 19391
diff changeset
1654 (let ((overriding-terminal-local-map keymap))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1655 (describe-bindings))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1656 (set-buffer "*Help*")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1657 (goto-char (point-min))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1658 (forward-line 4)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1659 (setq from (point))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1660 (search-forward "Global Bindings:" nil 'move)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1661 (beginning-of-line)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1662 (setq to (point))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1663 (insert-buffer-substring "*Help*" from to)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1664
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1665 (defun quail-show-kbd-layout ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1666 "Show keyboard layout with key tops of multilingual characters."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1667 (insert "--- Keyboard layout ---\n")
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1668 (let* ((i 0) ch)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1669 (while (< i quail-keyboard-layout-len)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1670 (if (= (% i 30) 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1671 (progn
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1672 (newline)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1673 (indent-to (/ i 30)))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1674 (if (= (% i 2) 0)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1675 (insert " ")))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1676 (setq ch (aref quail-keyboard-layout i))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1677 (if (= ch ?\ )
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1678 (insert ch)
17095
b57415dcc114 Add quail-mode to default value of
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
1679 (let* ((map (cdr (assq ch (cdr (quail-map)))))
b57415dcc114 Add quail-mode to default value of
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
1680 (translation (and map (quail-get-translation
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
1681 (car map) (char-to-string ch) 1))))
17095
b57415dcc114 Add quail-mode to default value of
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
1682 (if (integerp translation)
b57415dcc114 Add quail-mode to default value of
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
1683 (insert translation)
b57415dcc114 Add quail-mode to default value of
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
1684 (if (consp translation)
b57415dcc114 Add quail-mode to default value of
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
1685 (insert (aref (cdr translation) (car translation)))
b57415dcc114 Add quail-mode to default value of
Kenichi Handa <handa@m17n.org>
parents: 17071
diff changeset
1686 (insert ch)))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1687 (setq i (1+ i))))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1688 (newline))
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1689
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1690 (defun quail-translation-help ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1691 "Show help message while translating in Quail mode."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1692 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1693 (let ((package quail-current-package)
18349
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1694 (current-key quail-current-key))
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1695 (with-output-to-temp-buffer "*Quail-Help*"
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1696 (save-excursion
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1697 (set-buffer standard-output)
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1698 (let ((quail-current-package package))
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1699 (princ "You are translating the key sequence ")
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1700 (prin1 quail-current-key)
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1701 (princ" in Quail mode.\n")
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1702 (quail-help-insert-keymap-description
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1703 (quail-translation-keymap)
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1704 "-----------------------
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1705 key binding
18349
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1706 --- -------\n"))
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1707 (help-mode)))))
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1708
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1709 (defun quail-conversion-help ()
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1710 "Show help message while converting in Quail mode."
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1711 (interactive)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1712 (let ((package quail-current-package)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1713 (str (buffer-substring (overlay-start quail-conv-overlay)
18642
0fc832264117 (quail-conversion-help): Source code indentation changed.
Kenichi Handa <handa@m17n.org>
parents: 18556
diff changeset
1714 (overlay-end quail-conv-overlay))))
18349
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1715 (with-output-to-temp-buffer "*Quail-Help*"
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1716 (save-excursion
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1717 (set-buffer standard-output)
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1718 (let ((quail-current-package package))
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1719 (princ "You are converting the string ")
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1720 (prin1 str)
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1721 (princ " in Quail mode.\n")
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1722 (quail-help-insert-keymap-description
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1723 (quail-conversion-keymap)
18642
0fc832264117 (quail-conversion-help): Source code indentation changed.
Kenichi Handa <handa@m17n.org>
parents: 18556
diff changeset
1724 "-----------------------
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1725 key binding
18349
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1726 --- -------\n"))
f468344dd2bd (quail-help): Use with-output-to-temp-buffer.
Kenichi Handa <handa@m17n.org>
parents: 18297
diff changeset
1727 (help-mode)))))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1728
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
1729
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
1730 (defvar quail-directory-name "quail"
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
1731 "Name of Quail directory which cotains Quail packages.
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
1732 This is a sub-directory of LEIM directory.")
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
1733
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
1734 ;;;###autoload
19605
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1735 (defun quail-update-leim-list-file (dirname &rest dirnames)
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1736 "Update entries for Quail packages in `LEIM' list file in directory DIRNAME.
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1737 DIRNAME is a directory containing Emacs input methods;
19200
74ec766c0ada (quail-update-leim-list-file):
Richard M. Stallman <rms@gnu.org>
parents: 19144
diff changeset
1738 normally, it should specify the `leim' subdirectory
19605
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1739 of the Emacs source tree.
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1740
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1741 It searches for Quail packages under `quail' subdirectory of DIRNAME,
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1742 and update the file \"leim-list.el\" in DIRNAME.
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1743
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1744 When called from a program, the remaining arguments are additional
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1745 directory names to search for Quail packages under `quail' subdirectory
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1746 of each directory."
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
1747 (interactive "FDirectory of LEIM: ")
19605
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1748 (setq dirname (expand-file-name dirname))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1749 (let ((leim-list (expand-file-name leim-list-file-name dirname))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1750 quail-dirs list-buf pkg-list pkg-buf pos)
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1751 (if (not (file-writable-p leim-list))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1752 (error "Can't write to file \"%s\"" leim-list))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1753 (message "Updating %s ..." leim-list)
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1754 (setq list-buf (find-file-noselect leim-list))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1755
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1756 ;; At first, clean up the file.
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1757 (save-excursion
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1758 (set-buffer list-buf)
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1759 (goto-char 1)
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
1760
19605
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1761 ;; Insert the correct header.
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1762 (if (looking-at (regexp-quote leim-list-header))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1763 (goto-char (match-end 0))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1764 (insert leim-list-header))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1765 (setq pos (point))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1766 (if (not (re-search-forward leim-list-entry-regexp nil t))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1767 nil
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1768
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1769 ;; Remove garbages after the header.
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1770 (goto-char (match-beginning 0))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1771 (if (< pos (point))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1772 (delete-region pos (point)))
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
1773
19605
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1774 ;; Remove all entries for Quail.
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1775 (while (re-search-forward leim-list-entry-regexp nil 'move)
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1776 (goto-char (match-beginning 0))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1777 (setq pos (point))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1778 (condition-case nil
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1779 (let ((form (read list-buf)))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1780 (when (equal (nth 3 form) ''quail-use-package)
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1781 (if (eolp) (forward-line 1))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1782 (delete-region pos (point))))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1783 (error
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1784 ;; Delete the remaining contents because it seems that
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1785 ;; this file is broken.
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1786 (message "Garbages in %s deleted" leim-list)
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1787 (delete-region pos (point-max)))))))
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
1788
19605
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1789 ;; Search for `quail' subdirector under each DIRNAMES.
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1790 (setq dirnames (cons dirname dirnames))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1791 (let ((l dirnames))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1792 (while l
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1793 (setcar l (expand-file-name (car l)))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1794 (setq dirname (expand-file-name quail-directory-name (car l)))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1795 (if (file-readable-p dirname)
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1796 (setq quail-dirs (cons dirname quail-dirs))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1797 (message "%s doesn't has `%s' subdirectory, just ignored"
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1798 (car l) quail-directory-name)
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1799 (setq quail-dirs (cons nil quail-dirs)))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1800 (setq l (cdr l)))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1801 (setq quail-dirs (nreverse quail-dirs)))
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
1802
19605
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1803 ;; Insert input method registering forms.
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1804 (while quail-dirs
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1805 (setq dirname (car quail-dirs))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1806 (when dirname
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1807 (setq pkg-list (directory-files dirname 'full "\\.el$" 'nosort))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1808 (while pkg-list
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1809 (message "Checking %s ..." (car pkg-list))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1810 (with-temp-buffer
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1811 (insert-file-contents (car pkg-list))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1812 (goto-char (point-min))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1813 (while (search-forward "(quail-define-package" nil t)
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1814 (goto-char (match-beginning 0))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1815 (condition-case nil
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1816 (let ((form (read (current-buffer))))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1817 (save-excursion
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1818 (set-buffer list-buf)
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1819 (insert
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1820 (format "(register-input-method
18297
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
1821 %S %S '%s
5c8e37591da5 (quail-current-data): New variable.
Kenichi Handa <handa@m17n.org>
parents: 18201
diff changeset
1822 %S %S
19200
74ec766c0ada (quail-update-leim-list-file):
Richard M. Stallman <rms@gnu.org>
parents: 19144
diff changeset
1823 %S)\n"
19605
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1824 (nth 1 form) ; PACKAGE-NAME
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1825 (nth 2 form) ; LANGUAGE
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1826 'quail-use-package ; ACTIVATE-FUNC
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1827 (nth 3 form) ; PACKAGE-TITLE
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1828 (progn ; PACKAGE-DESCRIPTION (one line)
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1829 (string-match ".*" (nth 5 form))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1830 (match-string 0 (nth 5 form)))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1831 (file-relative-name ; PACKAGE-FILENAME
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1832 (file-name-sans-extension (car pkg-list))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1833 (car dirnames))))))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1834 (error
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1835 ;; Ignore the remaining contents of this file.
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1836 (goto-char (point-max))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1837 (message "Some part of \"%s\" is broken" dirname)))))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1838 (setq pkg-list (cdr pkg-list)))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1839 (setq quail-dirs (cdr quail-dirs) dirnames (cdr dirnames))))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1840
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1841 ;; At last, write out LEIM list file.
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1842 (save-excursion
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1843 (set-buffer list-buf)
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1844 (setq buffer-file-coding-system 'iso-2022-7bit)
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1845 (save-buffer 0))
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1846 (kill-buffer list-buf)
3b700b203cfd (quail-update-leim-list-file): Make it
Kenichi Handa <handa@m17n.org>
parents: 19519
diff changeset
1847 (message "Updating %s ... done" leim-list)))
17052
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1848 ;;
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1849 (provide 'quail)
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1850
d0d7b244b1d0 Initial revision
Karl Heuer <kwzh@gnu.org>
parents:
diff changeset
1851 ;;; quail.el ends here