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