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