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