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