Mercurial > emacs
annotate lisp/international/kkc.el @ 19805:e804ac04eec1
(c-mode-base-map): Don't define C-c C-e here.
(c-mode-map, c++-mode-map): Define C-c C-e here.
(objc-mode-map): Define C-c C-e, not /.
(java-mode-map, idl-mode-map): Don't define /.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 08 Sep 1997 03:20:17 +0000 |
parents | 0933bf4b82c9 |
children | 3c4025f3be8f |
rev | line source |
---|---|
17315
a3ca5e15c82a
Fix the format of the first line.
Kenichi Handa <handa@m17n.org>
parents:
17082
diff
changeset
|
1 ;;; kkc.el --- Kana Kanji converter |
17052 | 2 |
3 ;; Copyright (C) 1995 Electrotechnical Laboratory, JAPAN. | |
18377
8b4a66c66dd6
Change copyright notice.
Richard M. Stallman <rms@gnu.org>
parents:
18198
diff
changeset
|
4 ;; Licensed to the Free Software Foundation. |
17052 | 5 |
6 ;; Keywords: mule, multilingual, Japanese, SKK | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
17071 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
17052 | 24 |
25 ;;; Commentary: | |
26 | |
27 ;; These routines provide a simple and easy-to-use converter from | |
28 ;; Kana-string to Kana-Kanji-mixed-string. This converter (here after | |
29 ;; KKC) uses a SKK dictionary to get information how to convert | |
30 ;; Kana-string. Since KKC can't be fully automated, we need an | |
31 ;; interaction with a user to decide the correct conversion. For | |
32 ;; that, we provide KKC major mode. | |
33 | |
34 ;;; Code: | |
35 | |
36 (require 'skkdic-utl) | |
37 | |
38 (defvar kkc-input-method-title "漢" | |
39 "String denoting KKC input method. | |
40 This string is shown at mode line when users are in KKC mode.") | |
41 | |
42 (defvar kkc-init-file-name "~/.kkcrc" | |
43 "Name of a file which contains user's initial setup code for KKC.") | |
44 | |
45 ;; A flag to control a file specified by `kkc-init-file-name'. | |
46 ;; The value nil means the file is not yet consulted. | |
47 ;; The value t means the file has already been consulted but there's | |
48 ;; no need of updating it yet. | |
49 ;; Any other value means that we must update the file before exiting Emacs. | |
50 (defvar kkc-init-file-flag nil) | |
51 | |
52 ;; Cash data for `kkc-lookup-key'. This may be initialized by loading | |
53 ;; a file specified by `kkc-init-file-name'. If any elements are | |
54 ;; modified, the data is written out to the file when exiting Emacs. | |
55 (defvar kkc-lookup-cache '(kkc-lookup-cache)) | |
56 | |
57 (defun kkc-save-init-file () | |
58 "Save initial setup code for KKC to a file specified by `kkc-init-file-name'" | |
59 (if (and kkc-init-file-flag | |
60 (not (eq kkc-init-file-flag t))) | |
18198
8286b2dd4db6
(kkc-save-init-file): Coding system name changed from
Kenichi Handa <handa@m17n.org>
parents:
17315
diff
changeset
|
61 (let ((coding-system-for-write 'iso-2022-7bit)) |
17052 | 62 (write-region (format "(setq kkc-lookup-cache '%S)\n" kkc-lookup-cache) |
63 nil | |
64 kkc-init-file-name)))) | |
65 | |
66 ;; Sequence of characters to be used for indexes for shown list. The | |
67 ;; Nth character is for the Nth conversion in the list currently shown. | |
68 (defvar kkc-show-conversion-list-index-chars | |
69 "1234567890abcdefghijklmnopqrsuvwxyz") | |
70 | |
71 (defvar kkc-mode-map | |
72 (let ((map (make-keymap)) | |
73 (i 0)) | |
74 (while (< i ? ) | |
75 (define-key map (char-to-string i) 'undefined) | |
76 (setq i (1+ i))) | |
77 (while (< i 128) | |
78 (define-key map (char-to-string i) 'kkc-non-kkc-command) | |
79 (setq i (1+ i))) | |
80 (setq i 0) | |
81 (let ((len (length kkc-show-conversion-list-index-chars))) | |
82 (while (< i len) | |
83 (define-key map | |
84 (char-to-string (aref kkc-show-conversion-list-index-chars i)) | |
85 'kkc-select-from-list) | |
86 (setq i (1+ i)))) | |
87 (define-key map " " 'kkc-next) | |
88 (define-key map (char-to-string help-char) 'help-command) | |
89 (define-key map "\r" 'kkc-terminate) | |
90 (define-key map "\C-@" 'kkc-first-char-only) | |
91 (define-key map "\C-n" 'kkc-next) | |
92 (define-key map "\C-p" 'kkc-prev) | |
93 (define-key map "\C-i" 'kkc-shorter) | |
94 (define-key map "\C-o" 'kkc-longer) | |
95 (define-key map "\C-c" 'kkc-cancel) | |
96 (define-key map "\C-?" 'kkc-cancel) | |
97 (define-key map "\C-f" 'kkc-next-phrase) | |
98 (define-key map "K" 'kkc-katakana) | |
99 (define-key map "H" 'kkc-hiragana) | |
100 (define-key map "l" 'kkc-show-conversion-list-or-next-group) | |
101 (define-key map "L" 'kkc-show-conversion-list-or-prev-group) | |
102 (define-key map [?\C-\ ] 'kkc-first-char-only) | |
103 (define-key map [delete] 'kkc-cancel) | |
104 (define-key map [return] 'kkc-terminate) | |
105 (append map '((t . kkc-non-kkc-command)))) | |
106 "Keymap for KKC (Kana Kanji Conversion) mode.") | |
107 | |
108 (defun kkc-mode () | |
109 "Major mode for converting Kana string to Kanji-Kana mixed string. | |
110 Commands: | |
111 \\{kkc-mode-map}" | |
112 (setq major-mode 'kkc-mode) | |
113 (setq mode-name "KKC") | |
114 (use-local-map kkc-mode-map) | |
115 (run-hooks 'kkc-mode-hook)) | |
116 | |
117 ;;; Internal variables used in KKC. | |
118 | |
119 ;; The current Kana string to be converted. | |
120 (defvar kkc-original-kana nil) | |
121 | |
122 ;; The current key sequence (vector of Kana characters) generated from | |
123 ;; `kkc-original-kana'. | |
124 (defvar kkc-current-key nil) | |
125 | |
126 ;; List of the current conversions for `kkc-current-key'. | |
127 (defvar kkc-current-conversions nil) | |
128 | |
129 ;; Vector of the same length as `kkc-current-conversion'. The first | |
130 ;; element is a vector of: | |
131 ;; o index number of the first conversion shown previously, | |
132 ;; o index number of a conversion next of the last one shown previously, | |
133 ;; o the shown string itself. | |
134 ;; The remaining elements are widths (including columns for index | |
135 ;; numbers) of conversions stored in the same order as in | |
136 ;; `kkc-current-conversion'. | |
137 (defvar kkc-current-conversions-width nil) | |
138 | |
139 (defvar kkc-show-conversion-list-count 4 | |
140 "Count of successive `kkc-next' or `kkc-prev' to show conversion list.") | |
141 | |
142 ;; Provided that `kkc-current-key' is [A B C D E F G H I], the current | |
143 ;; conversion target is [A B C D E F], the sequence of which | |
144 ;; conversion is found is [A B C D]: | |
145 ;; | |
146 ;; A B C D E F G H I | |
147 ;; kkc-overlay-head (black): |<--------->| | |
148 ;; kkc-overlay-tail (underline): |<------->| | |
149 ;; kkc-length-head: |<--------->| | |
150 ;; kkc-length-converted: |<----->| | |
151 ;; | |
152 (defvar kkc-overlay-head nil) | |
153 (defvar kkc-overlay-tail nil) | |
154 (defvar kkc-length-head nil) | |
155 (defvar kkc-length-converted nil) | |
156 | |
157 ;; Cursor type (`box' or `bar') of the current frame. | |
158 (defvar kkc-cursor-type nil) | |
159 | |
160 ;; Flag to tell if the current conversion is canceled. If non-nil, | |
161 ;; the value is a buffer position of the head of currently active | |
162 ;; conversion region. | |
163 (defvar kkc-canceled nil) | |
164 | |
165 ;; Lookup SKK dictionary to set list of conversions in | |
166 ;; kkc-current-conversions for key sequence kkc-current-key of length | |
167 ;; LEN. If no conversion is found in the dictionary, don't change | |
168 ;; kkc-current-conversions and return nil. | |
169 ;; Postfixes are handled only if POSTFIX is non-nil. | |
18644
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
170 (defun kkc-lookup-key (len &optional postfix prefer-noun) |
17052 | 171 ;; At first, prepare cache data if any. |
172 (if (not kkc-init-file-flag) | |
173 (progn | |
174 (setq kkc-init-file-flag t) | |
175 (add-hook 'kill-emacs-hook 'kkc-save-init-file) | |
176 (if (file-readable-p kkc-init-file-name) | |
177 (condition-case nil | |
178 (load-file "~/.kkcrc") | |
179 (error (message "Invalid data in %s" kkc-init-file-name) | |
180 (ding)))))) | |
181 (let ((entry (lookup-nested-alist kkc-current-key kkc-lookup-cache len 0 t))) | |
182 (if (consp (car entry)) | |
183 (setq kkc-length-converted len | |
184 kkc-current-conversions-width nil | |
185 kkc-current-conversions (car entry)) | |
18644
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
186 (setq entry (skkdic-lookup-key kkc-current-key len postfix prefer-noun)) |
17052 | 187 (if entry |
188 (progn | |
189 (setq kkc-length-converted len | |
190 kkc-current-conversions-width nil | |
191 kkc-current-conversions (cons 1 entry)) | |
192 (if postfix | |
193 ;; Store this conversions in the cache. | |
194 (progn | |
195 (set-nested-alist kkc-current-key kkc-current-conversions | |
196 kkc-lookup-cache kkc-length-converted) | |
197 (setq kkc-init-file-flag 'kkc-lookup-cache))) | |
198 t) | |
199 (if (= len 1) | |
200 (setq kkc-length-converted 1 | |
201 kkc-current-conversions-width nil | |
202 kkc-current-conversions (cons 0 nil))))))) | |
203 | |
204 ;;;###autoload | |
19406 | 205 (defun kkc-region (from to &optional kkc-mode-exit-function) |
17052 | 206 "Convert Kana string in the current region to Kanji-Kana mixed string. |
207 After one candidate of conversion is shown in the region, users are | |
19406 | 208 put in KKC major mode to select a desirable conversion. |
209 Optional arg KKC-MODE-EXIT-FUNCTION if non-nil is called on exiting KKC mode." | |
17052 | 210 (interactive "r") |
211 (setq kkc-original-kana (buffer-substring from to)) | |
212 (goto-char from) | |
213 | |
214 ;; Setup overlays. | |
215 (if (overlayp kkc-overlay-head) | |
216 (move-overlay kkc-overlay-head from to) | |
217 (setq kkc-overlay-head (make-overlay from to nil nil t)) | |
218 (overlay-put kkc-overlay-head 'face 'highlight)) | |
219 (if (overlayp kkc-overlay-tail) | |
220 (move-overlay kkc-overlay-tail to to) | |
221 (setq kkc-overlay-tail (make-overlay to to nil nil t)) | |
222 (overlay-put kkc-overlay-tail 'face 'underline)) | |
223 | |
224 ;; After updating the conversion region with the first candidate of | |
225 ;; conversion, jump into a recursive editing environment with KKC | |
18644
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
226 ;; mode. |
17052 | 227 (let ((overriding-local-map nil) |
228 (previous-local-map (current-local-map)) | |
229 (minor-mode-alist nil) | |
230 (minor-mode-map-alist nil) | |
231 (current-input-method-title kkc-input-method-title) | |
232 major-mode mode-name) | |
233 (unwind-protect | |
18644
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
234 (let (len) |
17052 | 235 (setq kkc-canceled nil) |
236 (setq kkc-current-key (string-to-vector kkc-original-kana)) | |
237 (setq kkc-length-head (length kkc-current-key)) | |
18644
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
238 (setq len kkc-length-head) |
17052 | 239 (setq kkc-length-converted 0) |
18644
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
240 (while (not (kkc-lookup-key kkc-length-head nil |
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
241 (< kkc-length-head len))) |
17052 | 242 (setq kkc-length-head (1- kkc-length-head))) |
243 (goto-char to) | |
244 (kkc-update-conversion 'all) | |
245 (kkc-mode) | |
246 (recursive-edit)) | |
247 (goto-char (overlay-end kkc-overlay-tail)) | |
248 (delete-overlay kkc-overlay-head) | |
249 (delete-overlay kkc-overlay-tail) | |
19406 | 250 (use-local-map previous-local-map) |
251 (if (and kkc-mode-exit-function | |
252 (fboundp kkc-mode-exit-function)) | |
253 (funcall kkc-mode-exit-function (if kkc-canceled | |
254 (cons kkc-canceled (point)))))))) | |
17052 | 255 |
256 (defun kkc-terminate () | |
257 "Exit from KKC mode by fixing the current conversion." | |
258 (interactive) | |
259 (throw 'exit nil)) | |
260 | |
261 (defun kkc-non-kkc-command () | |
262 "Exit from KKC mode by fixing the current conversion. | |
263 After that, handle the event which invoked this command." | |
264 (interactive) | |
265 (setq unread-command-events (list last-input-event)) | |
266 (kkc-terminate)) | |
267 | |
268 (defun kkc-cancel () | |
269 "Exit from KKC mode by canceling any conversions." | |
270 (interactive) | |
271 (setq kkc-canceled (overlay-start kkc-overlay-head)) | |
272 (goto-char kkc-canceled) | |
273 (delete-region (overlay-start kkc-overlay-head) | |
274 (overlay-end kkc-overlay-tail)) | |
275 (insert kkc-original-kana) | |
276 (kkc-terminate)) | |
277 | |
278 (defun kkc-first-char-only () | |
279 "Select only the first character currently converted." | |
280 (interactive) | |
281 (goto-char (overlay-start kkc-overlay-head)) | |
282 (forward-char 1) | |
283 (delete-region (point) (overlay-end kkc-overlay-tail)) | |
284 (kkc-terminate)) | |
285 | |
286 ;; Count of successive invocations of `kkc-next'. | |
287 (defvar kkc-next-count nil) | |
288 | |
289 (defun kkc-next () | |
290 "Select the next candidate of conversion." | |
291 (interactive) | |
292 (if (eq this-command last-command) | |
293 (setq kkc-next-count (1+ kkc-next-count)) | |
294 (setq kkc-next-count 1)) | |
295 (let ((idx (1+ (car kkc-current-conversions)))) | |
296 (if (< idx 0) | |
297 (setq idx 1)) | |
298 (if (>= idx (length kkc-current-conversions)) | |
299 (setq idx 0)) | |
300 (setcar kkc-current-conversions idx) | |
301 (if (> idx 1) | |
302 (progn | |
303 (set-nested-alist kkc-current-key kkc-current-conversions | |
304 kkc-lookup-cache kkc-length-converted) | |
305 (setq kkc-init-file-flag 'kkc-lookup-cache))) | |
306 (if (or kkc-current-conversions-width | |
307 (>= kkc-next-count kkc-show-conversion-list-count)) | |
308 (kkc-show-conversion-list-update)) | |
309 (kkc-update-conversion))) | |
310 | |
311 ;; Count of successive invocations of `kkc-next'. | |
312 (defvar kkc-prev-count nil) | |
313 | |
314 (defun kkc-prev () | |
315 "Select the previous candidate of conversion." | |
316 (interactive) | |
317 (if (eq this-command last-command) | |
318 (setq kkc-prev-count (1+ kkc-prev-count)) | |
319 (setq kkc-prev-count 1)) | |
320 (let ((idx (1- (car kkc-current-conversions)))) | |
321 (if (< idx 0) | |
322 (setq idx (1- (length kkc-current-conversions)))) | |
323 (setcar kkc-current-conversions idx) | |
324 (if (> idx 1) | |
325 (progn | |
326 (set-nested-alist kkc-current-key kkc-current-conversions | |
327 kkc-lookup-cache kkc-length-converted) | |
328 (setq kkc-init-file-flag 'kkc-lookup-cache))) | |
329 (if (or kkc-current-conversions-width | |
330 (>= kkc-prev-count kkc-show-conversion-list-count)) | |
331 (kkc-show-conversion-list-update)) | |
332 (kkc-update-conversion))) | |
333 | |
334 (defun kkc-select-from-list () | |
335 "Select one candidate from the list currently shown in echo area." | |
336 (interactive) | |
337 (let (idx) | |
338 (if kkc-current-conversions-width | |
339 (let ((len (length kkc-show-conversion-list-index-chars)) | |
340 (maxlen (- (aref (aref kkc-current-conversions-width 0) 1) | |
341 (aref (aref kkc-current-conversions-width 0) 0))) | |
342 (i 0)) | |
343 (if (> len maxlen) | |
344 (setq len maxlen)) | |
345 (while (< i len) | |
346 (if (= (aref kkc-show-conversion-list-index-chars i) | |
347 last-input-char) | |
348 (setq idx i i len) | |
349 (setq i (1+ i)))))) | |
350 (if idx | |
351 (progn | |
352 (setcar kkc-current-conversions | |
353 (+ (aref (aref kkc-current-conversions-width 0) 0) idx)) | |
354 (kkc-show-conversion-list-update) | |
355 (kkc-update-conversion)) | |
356 (setq unread-command-events (list last-input-event)) | |
357 (kkc-terminate)))) | |
358 | |
359 (defun kkc-katakana () | |
360 "Convert to Katakana." | |
361 (interactive) | |
362 (setcar kkc-current-conversions -1) | |
363 (kkc-update-conversion 'all)) | |
364 | |
365 (defun kkc-hiragana () | |
366 "Convert to hiragana." | |
367 (interactive) | |
368 (setcar kkc-current-conversions 0) | |
369 (kkc-update-conversion)) | |
370 | |
371 (defun kkc-shorter () | |
372 "Make the Kana string to be converted shorter." | |
373 (interactive) | |
374 (if (<= kkc-length-head 1) | |
375 (error "Can't be shorter") | |
376 (setq kkc-length-head (1- kkc-length-head)) | |
377 (if (> kkc-length-converted kkc-length-head) | |
378 (let ((len kkc-length-head)) | |
379 (setq kkc-length-converted 0) | |
380 (while (not (kkc-lookup-key len)) | |
381 (setq len (1- len))))) | |
382 (kkc-update-conversion 'all))) | |
383 | |
384 (defun kkc-longer () | |
385 "Make the Kana string to be converted longer." | |
386 (interactive) | |
387 (if (>= kkc-length-head (length kkc-current-key)) | |
388 (error "Can't be longer") | |
389 (setq kkc-length-head (1+ kkc-length-head)) | |
390 ;; This time, try also entries with postfixes. | |
391 (kkc-lookup-key kkc-length-head 'postfix) | |
392 (kkc-update-conversion 'all))) | |
393 | |
394 (defun kkc-next-phrase () | |
395 "Fix the currently converted string and try to convert the remaining string." | |
396 (interactive) | |
397 (if (>= kkc-length-head (length kkc-current-key)) | |
398 (kkc-terminate) | |
399 (setq kkc-length-head (- (length kkc-current-key) kkc-length-head)) | |
400 (goto-char (overlay-end kkc-overlay-head)) | |
401 (while (and (< (point) (overlay-end kkc-overlay-tail)) | |
402 (looking-at "\\CH")) | |
403 (goto-char (match-end 0)) | |
404 (setq kkc-length-head (1- kkc-length-head))) | |
405 (if (= kkc-length-head 0) | |
406 (kkc-terminate) | |
407 (let ((newkey (make-vector kkc-length-head 0)) | |
408 (idx (- (length kkc-current-key) kkc-length-head)) | |
18644
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
409 (len kkc-length-head) |
17052 | 410 (i 0)) |
411 ;; For the moment, (setq kkc-original-kana (concat newkey)) | |
412 ;; doesn't work. | |
413 (setq kkc-original-kana "") | |
414 (while (< i kkc-length-head) | |
415 (aset newkey i (aref kkc-current-key (+ idx i))) | |
416 (setq kkc-original-kana | |
417 (concat kkc-original-kana (char-to-string (aref newkey i)))) | |
418 (setq i (1+ i))) | |
419 (setq kkc-current-key newkey) | |
420 (setq kkc-length-converted 0) | |
18644
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
421 (while (and (not (kkc-lookup-key kkc-length-head nil |
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
422 (< kkc-length-head len))) |
17052 | 423 (> kkc-length-head 1)) |
424 (setq kkc-length-head (1- kkc-length-head))) | |
425 (let ((pos (point)) | |
426 (tail (overlay-end kkc-overlay-tail))) | |
427 (move-overlay kkc-overlay-head pos tail) | |
428 (move-overlay kkc-overlay-tail tail tail)) | |
429 (kkc-update-conversion 'all))))) | |
430 | |
431 ;; We'll show users a list of available conversions in echo area with | |
432 ;; index numbers so that users can select one conversion with the | |
433 ;; number. | |
434 | |
435 ;; Set `kkc-current-conversions-width'. | |
436 (defun kkc-setup-current-conversions-width () | |
437 (let ((convs (cdr kkc-current-conversions)) | |
438 (len (length kkc-current-conversions)) | |
439 (idx 1)) | |
440 (setq kkc-current-conversions-width (make-vector len nil)) | |
441 ;; To tell `kkc-show-conversion-list-update' to generate | |
442 ;; message from scratch. | |
443 (aset kkc-current-conversions-width 0 (vector len -2 nil)) | |
444 ;; Fill the remaining slots. | |
445 (while convs | |
446 (aset kkc-current-conversions-width idx | |
447 (+ (string-width (car convs)) 4)) | |
448 (setq convs (cdr convs) | |
449 idx (1+ idx))))) | |
450 | |
451 (defun kkc-show-conversion-list-or-next-group () | |
452 "Show list of available conversions in echo area with index numbers. | |
453 If the list is already shown, show the next group of conversions, | |
454 and change the current conversion to the first one in the group." | |
455 (interactive) | |
456 (if (< (length kkc-current-conversions) 3) | |
457 (error "No alternative")) | |
458 (if kkc-current-conversions-width | |
459 (let ((next-idx (aref (aref kkc-current-conversions-width 0) 1))) | |
460 (if (< next-idx (length kkc-current-conversions-width)) | |
461 (setcar kkc-current-conversions next-idx) | |
462 (setcar kkc-current-conversions 1)) | |
463 (kkc-show-conversion-list-update) | |
464 (kkc-update-conversion)) | |
465 (kkc-setup-current-conversions-width) | |
466 (kkc-show-conversion-list-update))) | |
467 | |
468 (defun kkc-show-conversion-list-or-prev-group () | |
469 "Show list of available conversions in echo area with index numbers. | |
470 If the list is already shown, show the previous group of conversions, | |
471 and change the current conversion to the last one in the group." | |
472 (interactive) | |
473 (if (< (length kkc-current-conversions) 3) | |
474 (error "No alternative")) | |
475 (if kkc-current-conversions-width | |
476 (let ((this-idx (aref (aref kkc-current-conversions-width 0) 0))) | |
477 (if (> this-idx 1) | |
478 (setcar kkc-current-conversions (1- this-idx)) | |
479 (setcar kkc-current-conversions | |
480 (1- (length kkc-current-conversions-width)))) | |
481 (kkc-show-conversion-list-update) | |
482 (kkc-update-conversion)) | |
483 (kkc-setup-current-conversions-width) | |
484 (kkc-show-conversion-list-update))) | |
485 | |
486 ;; Update the conversion list shown in echo area. | |
487 (defun kkc-show-conversion-list-update () | |
488 (or kkc-current-conversions-width | |
489 (kkc-setup-current-conversions-width)) | |
490 (let* ((current-idx (car kkc-current-conversions)) | |
491 (first-slot (aref kkc-current-conversions-width 0)) | |
492 (this-idx (aref first-slot 0)) | |
493 (next-idx (aref first-slot 1)) | |
494 (msg (aref first-slot 2))) | |
495 (if (< current-idx this-idx) | |
496 ;; The currently selected conversion is before the list shown | |
497 ;; previously. We must start calculation of message width | |
498 ;; from the start again. | |
499 (setq this-idx 1 msg nil) | |
500 (if (>= current-idx next-idx) | |
501 ;; The currently selected conversion is after the list shown | |
502 ;; previously. We start calculation of message width from | |
503 ;; the conversion next of TO. | |
504 (setq this-idx next-idx msg nil) | |
505 ;; The current conversion is in MSG. Just clear brackets | |
506 ;; around index number. | |
507 (if (string-match "<.>" msg) | |
508 (progn | |
509 (aset msg (match-beginning 0) ?\ ) | |
510 (aset msg (1- (match-end 0)) ?\ ))))) | |
511 (if (not msg) | |
512 (let ((len (length kkc-current-conversions)) | |
513 (max-width (window-width (minibuffer-window))) | |
514 (width-table kkc-current-conversions-width) | |
515 (width 0) | |
516 (idx this-idx) | |
517 l) | |
518 (while (< idx current-idx) | |
519 (if (<= (+ width (aref width-table idx)) max-width) | |
520 (setq width (+ width (aref width-table idx))) | |
521 (setq this-idx idx width (aref width-table idx))) | |
522 (setq idx (1+ idx) | |
523 l (cdr l))) | |
524 (aset first-slot 0 this-idx) | |
525 (while (and (< idx len) | |
526 (<= (+ width (aref width-table idx)) max-width)) | |
527 (setq width (+ width (aref width-table idx)) | |
528 idx (1+ idx) | |
529 l (cdr l))) | |
530 (aset first-slot 1 (setq next-idx idx)) | |
531 (setq l (nthcdr this-idx kkc-current-conversions)) | |
532 (setq msg "") | |
533 (setq idx this-idx) | |
534 (while (< idx next-idx) | |
535 (setq msg (format "%s %c %s " | |
536 msg | |
537 (aref kkc-show-conversion-list-index-chars | |
538 (- idx this-idx)) | |
539 (car l))) | |
540 (setq idx (1+ idx) | |
541 l (cdr l))) | |
542 (aset first-slot 2 msg))) | |
543 (if (> current-idx 0) | |
544 (progn | |
545 ;; Highlight the current conversion by brackets. | |
546 (string-match (format " \\(%c\\) " | |
547 (aref kkc-show-conversion-list-index-chars | |
548 (- current-idx this-idx))) | |
549 msg) | |
550 (aset msg (match-beginning 0) ?<) | |
551 (aset msg (1- (match-end 0)) ?>))) | |
552 (message "%s" msg))) | |
553 | |
554 ;; Update the conversion area with the latest conversion selected. | |
555 ;; ALL if non nil means to update the whole area, else update only | |
556 ;; inside quail-overlay-head. | |
557 | |
558 (defun kkc-update-conversion (&optional all) | |
559 (goto-char (overlay-start kkc-overlay-head)) | |
560 (cond ((= (car kkc-current-conversions) 0) ; Hiragana | |
561 (let ((i 0)) | |
562 (while (< i kkc-length-converted) | |
563 (insert (aref kkc-current-key i)) | |
564 (setq i (1+ i))))) | |
565 ((= (car kkc-current-conversions) -1) ; Katakana | |
566 (let ((i 0)) | |
567 (while (< i kkc-length-converted) | |
568 (insert (japanese-katakana (aref kkc-current-key i))) | |
569 (setq i (1+ i))))) | |
570 (t | |
571 (insert (nth (car kkc-current-conversions) kkc-current-conversions)))) | |
572 (delete-region (point) (overlay-start kkc-overlay-tail)) | |
573 (if all | |
574 (let ((len (length kkc-current-key)) | |
575 (i kkc-length-converted)) | |
576 (delete-region (overlay-start kkc-overlay-tail) | |
577 (overlay-end kkc-overlay-head)) | |
578 (while (< i kkc-length-head) | |
579 (if (= (car kkc-current-conversions) -1) | |
580 (insert (japanese-katakana (aref kkc-current-key i))) | |
581 (insert (aref kkc-current-key i))) | |
582 (setq i (1+ i))) | |
583 (let ((pos (point))) | |
584 (while (< i len) | |
585 (insert (aref kkc-current-key i)) | |
586 (setq i (1+ i))) | |
587 (move-overlay kkc-overlay-head | |
588 (overlay-start kkc-overlay-head) pos) | |
589 (delete-region (point) (overlay-end kkc-overlay-tail))))) | |
590 (goto-char (overlay-end kkc-overlay-tail))) | |
591 | |
592 ;; | |
593 (provide 'kkc) | |
594 | |
595 ;; kkc.el ends here |