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