Mercurial > emacs
annotate lisp/international/kkc.el @ 30251:9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
(kkc-region): Update kkc-next-count and kkc-prev-count here. Show
the conversion list at first if appropriate.
(kkc-next): Don't update kkc-next-count here.
(kkc-prev): Don't update kkc-prev-count here.
(kkc-show-conversion-list-update): Fix setting up of conversion
list message.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Mon, 17 Jul 2000 01:22:09 +0000 |
parents | ded7fa3de6db |
children | e4b4bca5087a |
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. | |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
55 (defvar kkc-lookup-cache nil) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
56 |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
57 ;; Tag symbol of `kkc-lookup-cache'. |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
58 (defconst kkc-lookup-cache-tag 'kkc-lookup-cache-2) |
17052 | 59 |
60 (defun kkc-save-init-file () | |
61 "Save initial setup code for KKC to a file specified by `kkc-init-file-name'" | |
62 (if (and kkc-init-file-flag | |
63 (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
|
64 (let ((coding-system-for-write 'iso-2022-7bit)) |
17052 | 65 (write-region (format "(setq kkc-lookup-cache '%S)\n" kkc-lookup-cache) |
66 nil | |
67 kkc-init-file-name)))) | |
68 | |
69 ;; Sequence of characters to be used for indexes for shown list. The | |
70 ;; Nth character is for the Nth conversion in the list currently shown. | |
71 (defvar kkc-show-conversion-list-index-chars | |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
72 "1234567890") |
17052 | 73 |
23032 | 74 (defun kkc-help () |
75 "Show key bindings available while converting by KKC." | |
76 (interactive) | |
77 (with-output-to-temp-buffer "*Help*" | |
78 (princ (substitute-command-keys "\\{kkc-keymap}")))) | |
79 | |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
80 (defvar kkc-keymap |
23032 | 81 (let ((map (make-sparse-keymap)) |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
82 (len (length kkc-show-conversion-list-index-chars)) |
17052 | 83 (i 0)) |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
84 (while (< i len) |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
85 (define-key map |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
86 (char-to-string (aref kkc-show-conversion-list-index-chars i)) |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
87 'kkc-select-from-list) |
17052 | 88 (setq i (1+ i))) |
89 (define-key map " " 'kkc-next) | |
90 (define-key map "\r" 'kkc-terminate) | |
91 (define-key map "\C-@" 'kkc-first-char-only) | |
92 (define-key map "\C-n" 'kkc-next) | |
93 (define-key map "\C-p" 'kkc-prev) | |
94 (define-key map "\C-i" 'kkc-shorter) | |
95 (define-key map "\C-o" 'kkc-longer) | |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
96 (define-key map "I" 'kkc-shorter-conversion) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
97 (define-key map "O" 'kkc-longer-phrase) |
17052 | 98 (define-key map "\C-c" 'kkc-cancel) |
99 (define-key map "\C-?" 'kkc-cancel) | |
100 (define-key map "\C-f" 'kkc-next-phrase) | |
101 (define-key map "K" 'kkc-katakana) | |
102 (define-key map "H" 'kkc-hiragana) | |
103 (define-key map "l" 'kkc-show-conversion-list-or-next-group) | |
104 (define-key map "L" 'kkc-show-conversion-list-or-prev-group) | |
20638
c3360a392ae4
Change "?\C-\ " to "?\C- " because "\ " is changed
Kenichi Handa <handa@m17n.org>
parents:
19931
diff
changeset
|
105 (define-key map [?\C- ] 'kkc-first-char-only) |
17052 | 106 (define-key map [delete] 'kkc-cancel) |
107 (define-key map [return] 'kkc-terminate) | |
23032 | 108 (define-key map "\C-h" 'kkc-help) |
19869
3c4025f3be8f
(kkc-mode-map): Bind meta-prefix-char to a
Kenichi Handa <handa@m17n.org>
parents:
19406
diff
changeset
|
109 map) |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
110 "Keymap for KKC (Kana Kanji Converter).") |
17052 | 111 |
112 ;;; Internal variables used in KKC. | |
113 | |
114 ;; The current Kana string to be converted. | |
115 (defvar kkc-original-kana nil) | |
116 | |
117 ;; The current key sequence (vector of Kana characters) generated from | |
118 ;; `kkc-original-kana'. | |
119 (defvar kkc-current-key nil) | |
120 | |
121 ;; List of the current conversions for `kkc-current-key'. | |
122 (defvar kkc-current-conversions nil) | |
123 | |
124 ;; Vector of the same length as `kkc-current-conversion'. The first | |
125 ;; element is a vector of: | |
126 ;; o index number of the first conversion shown previously, | |
127 ;; o index number of a conversion next of the last one shown previously, | |
128 ;; o the shown string itself. | |
129 ;; The remaining elements are widths (including columns for index | |
130 ;; numbers) of conversions stored in the same order as in | |
131 ;; `kkc-current-conversion'. | |
132 (defvar kkc-current-conversions-width nil) | |
133 | |
30251
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
134 (defcustom kkc-show-conversion-list-count 4 |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
135 "*Count of successive `kkc-next' or `kkc-prev' to show conversion list. |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
136 When you type SPC or C-p successively this count while using the input |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
137 method `japanese', the conversion candidates are shown in the echo |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
138 area while indicating the current selection by `<N>'." |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
139 :group 'mule |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
140 :type 'integer) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
141 |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
142 ;; Count of successive invocations of `kkc-next'. |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
143 (defvar kkc-next-count nil) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
144 |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
145 ;; Count of successive invocations of `kkc-prev'. |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
146 (defvar kkc-prev-count nil) |
17052 | 147 |
148 ;; Provided that `kkc-current-key' is [A B C D E F G H I], the current | |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
149 ;; conversion target is [A B C D E F], and the sequence of which |
17052 | 150 ;; conversion is found is [A B C D]: |
151 ;; | |
152 ;; A B C D E F G H I | |
153 ;; kkc-overlay-head (black): |<--------->| | |
154 ;; kkc-overlay-tail (underline): |<------->| | |
155 ;; kkc-length-head: |<--------->| | |
156 ;; kkc-length-converted: |<----->| | |
157 ;; | |
158 (defvar kkc-overlay-head nil) | |
159 (defvar kkc-overlay-tail nil) | |
160 (defvar kkc-length-head nil) | |
161 (defvar kkc-length-converted nil) | |
162 | |
163 ;; Cursor type (`box' or `bar') of the current frame. | |
164 (defvar kkc-cursor-type nil) | |
165 | |
166 ;; Lookup SKK dictionary to set list of conversions in | |
167 ;; kkc-current-conversions for key sequence kkc-current-key of length | |
168 ;; LEN. If no conversion is found in the dictionary, don't change | |
169 ;; kkc-current-conversions and return nil. | |
170 ;; 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
|
171 (defun kkc-lookup-key (len &optional postfix prefer-noun) |
17052 | 172 ;; At first, prepare cache data if any. |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
173 (unless kkc-init-file-flag |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
174 (setq kkc-init-file-flag t |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
175 kkc-lookup-cache nil) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
176 (add-hook 'kill-emacs-hook 'kkc-save-init-file) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
177 (if (file-readable-p kkc-init-file-name) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
178 (condition-case nil |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
179 (load-file kkc-init-file-name) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
180 (kkc-error "Invalid data in %s" kkc-init-file-name)))) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
181 (or (and (nested-alist-p kkc-lookup-cache) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
182 (eq (car kkc-lookup-cache) kkc-lookup-cache-tag)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
183 (setq kkc-lookup-cache (list kkc-lookup-cache-tag) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
184 kkc-init-file-flag 'kkc-lookup-cache)) |
17052 | 185 (let ((entry (lookup-nested-alist kkc-current-key kkc-lookup-cache len 0 t))) |
186 (if (consp (car entry)) | |
187 (setq kkc-length-converted len | |
188 kkc-current-conversions-width nil | |
189 kkc-current-conversions (car entry)) | |
18644
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
190 (setq entry (skkdic-lookup-key kkc-current-key len postfix prefer-noun)) |
17052 | 191 (if entry |
192 (progn | |
193 (setq kkc-length-converted len | |
194 kkc-current-conversions-width nil | |
195 kkc-current-conversions (cons 1 entry)) | |
196 (if postfix | |
197 ;; Store this conversions in the cache. | |
198 (progn | |
199 (set-nested-alist kkc-current-key kkc-current-conversions | |
200 kkc-lookup-cache kkc-length-converted) | |
201 (setq kkc-init-file-flag 'kkc-lookup-cache))) | |
202 t) | |
203 (if (= len 1) | |
204 (setq kkc-length-converted 1 | |
205 kkc-current-conversions-width nil | |
206 kkc-current-conversions (cons 0 nil))))))) | |
207 | |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
208 (put 'kkc-error 'error-conditions '(kkc-error error)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
209 (defun kkc-error (&rest args) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
210 (signal 'kkc-error (apply 'format args))) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
211 |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
212 (defvar kkc-converting nil) |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
213 |
17052 | 214 ;;;###autoload |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
215 (defun kkc-region (from to) |
17052 | 216 "Convert Kana string in the current region to Kanji-Kana mixed string. |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
217 Users can select a desirable conversion interactively. |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
218 When called from a program, expects two arguments, |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
219 positions FROM and TO (integers or markers) specifying the target region. |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
220 When it returns, the point is at the tail of the selected conversion, |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
221 and the return value is the length of the conversion." |
17052 | 222 (interactive "r") |
223 (setq kkc-original-kana (buffer-substring from to)) | |
224 (goto-char from) | |
225 | |
226 ;; Setup overlays. | |
227 (if (overlayp kkc-overlay-head) | |
228 (move-overlay kkc-overlay-head from to) | |
229 (setq kkc-overlay-head (make-overlay from to nil nil t)) | |
230 (overlay-put kkc-overlay-head 'face 'highlight)) | |
231 (if (overlayp kkc-overlay-tail) | |
232 (move-overlay kkc-overlay-tail to to) | |
233 (setq kkc-overlay-tail (make-overlay to to nil nil t)) | |
234 (overlay-put kkc-overlay-tail 'face 'underline)) | |
235 | |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
236 (setq kkc-current-key (string-to-vector kkc-original-kana)) |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
237 (setq kkc-length-head (length kkc-current-key)) |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
238 (setq kkc-length-converted 0) |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
239 |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
240 (unwind-protect |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
241 ;; At first convert the region to the first candidate. |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
242 (let ((current-input-method-title kkc-input-method-title) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
243 (input-method-function nil) |
29146
ded7fa3de6db
(kkc-region): Don't change modified-p of
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
244 (modified-p (buffer-modified-p)) |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
245 (first t)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
246 (while (not (kkc-lookup-key kkc-length-head nil first)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
247 (setq kkc-length-head (1- kkc-length-head) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
248 first nil)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
249 (goto-char to) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
250 (kkc-update-conversion 'all) |
30251
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
251 (setq kkc-next-count 1 kkc-prev-count 0) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
252 (if (and (>= kkc-next-count kkc-show-conversion-list-count) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
253 (>= (length kkc-current-conversions) 3)) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
254 (kkc-show-conversion-list-or-next-group)) |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
255 |
23196 | 256 ;; Then, ask users to select a desirable conversion. |
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
257 (force-mode-line-update) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
258 (setq kkc-converting t) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
259 (while kkc-converting |
29146
ded7fa3de6db
(kkc-region): Don't change modified-p of
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
260 (set-buffer-modified-p modified-p) |
22919
95d147bbdce0
(kkc-region): Don't bind echo-keystrokes.
Kenichi Handa <handa@m17n.org>
parents:
22888
diff
changeset
|
261 (let* ((overriding-terminal-local-map kkc-keymap) |
23032 | 262 (help-char nil) |
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
263 (keyseq (read-key-sequence nil)) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
264 (cmd (lookup-key kkc-keymap keyseq))) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
265 (if (commandp cmd) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
266 (condition-case err |
30251
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
267 (progn |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
268 (cond ((eq cmd 'kkc-next) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
269 (setq kkc-next-count (1+ kkc-next-count) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
270 kkc-prev-count 0)) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
271 ((eq cmd 'kkc-prev) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
272 (setq kkc-prev-count (1+ kkc-prev-count) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
273 kkc-next-count 0)) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
274 (t |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
275 (setq kkc-next-count 0 kkc-prev-count 0))) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
276 (call-interactively cmd)) |
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
277 (kkc-error (message "%s" (cdr err)) (beep))) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
278 ;; KEYSEQ is not defined in KKC keymap. |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
279 ;; Let's put the event back. |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
280 (setq unread-input-method-events |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
281 (append (string-to-list keyseq) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
282 unread-input-method-events)) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
283 (kkc-terminate)))) |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
284 |
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
285 (force-mode-line-update) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
286 (goto-char (overlay-end kkc-overlay-tail)) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
287 (- (overlay-start kkc-overlay-head) from)) |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
288 (delete-overlay kkc-overlay-head) |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
289 (delete-overlay kkc-overlay-tail))) |
17052 | 290 |
291 (defun kkc-terminate () | |
292 "Exit from KKC mode by fixing the current conversion." | |
293 (interactive) | |
22794
9ace35333789
(kkc-region): Handled the case that
Kenichi Handa <handa@m17n.org>
parents:
22779
diff
changeset
|
294 (goto-char (overlay-end kkc-overlay-tail)) |
9ace35333789
(kkc-region): Handled the case that
Kenichi Handa <handa@m17n.org>
parents:
22779
diff
changeset
|
295 (move-overlay kkc-overlay-head (point) (point)) |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
296 (setq kkc-converting nil)) |
17052 | 297 |
298 (defun kkc-cancel () | |
299 "Exit from KKC mode by canceling any conversions." | |
300 (interactive) | |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
301 (goto-char (overlay-start kkc-overlay-head)) |
17052 | 302 (delete-region (overlay-start kkc-overlay-head) |
303 (overlay-end kkc-overlay-tail)) | |
304 (insert kkc-original-kana) | |
22794
9ace35333789
(kkc-region): Handled the case that
Kenichi Handa <handa@m17n.org>
parents:
22779
diff
changeset
|
305 (setq kkc-converting nil)) |
17052 | 306 |
307 (defun kkc-first-char-only () | |
308 "Select only the first character currently converted." | |
309 (interactive) | |
310 (goto-char (overlay-start kkc-overlay-head)) | |
311 (forward-char 1) | |
312 (delete-region (point) (overlay-end kkc-overlay-tail)) | |
313 (kkc-terminate)) | |
314 | |
315 (defun kkc-next () | |
316 "Select the next candidate of conversion." | |
317 (interactive) | |
318 (let ((idx (1+ (car kkc-current-conversions)))) | |
319 (if (< idx 0) | |
320 (setq idx 1)) | |
321 (if (>= idx (length kkc-current-conversions)) | |
322 (setq idx 0)) | |
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-next-count kkc-show-conversion-list-count)) | |
331 (kkc-show-conversion-list-update)) | |
332 (kkc-update-conversion))) | |
333 | |
334 (defun kkc-prev () | |
335 "Select the previous candidate of conversion." | |
336 (interactive) | |
337 (let ((idx (1- (car kkc-current-conversions)))) | |
338 (if (< idx 0) | |
339 (setq idx (1- (length kkc-current-conversions)))) | |
340 (setcar kkc-current-conversions idx) | |
341 (if (> idx 1) | |
342 (progn | |
343 (set-nested-alist kkc-current-key kkc-current-conversions | |
344 kkc-lookup-cache kkc-length-converted) | |
345 (setq kkc-init-file-flag 'kkc-lookup-cache))) | |
346 (if (or kkc-current-conversions-width | |
347 (>= kkc-prev-count kkc-show-conversion-list-count)) | |
348 (kkc-show-conversion-list-update)) | |
349 (kkc-update-conversion))) | |
350 | |
351 (defun kkc-select-from-list () | |
352 "Select one candidate from the list currently shown in echo area." | |
353 (interactive) | |
354 (let (idx) | |
355 (if kkc-current-conversions-width | |
356 (let ((len (length kkc-show-conversion-list-index-chars)) | |
357 (maxlen (- (aref (aref kkc-current-conversions-width 0) 1) | |
358 (aref (aref kkc-current-conversions-width 0) 0))) | |
359 (i 0)) | |
360 (if (> len maxlen) | |
361 (setq len maxlen)) | |
362 (while (< i len) | |
363 (if (= (aref kkc-show-conversion-list-index-chars i) | |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
364 last-input-event) |
17052 | 365 (setq idx i i len) |
366 (setq i (1+ i)))))) | |
367 (if idx | |
368 (progn | |
369 (setcar kkc-current-conversions | |
370 (+ (aref (aref kkc-current-conversions-width 0) 0) idx)) | |
371 (kkc-show-conversion-list-update) | |
372 (kkc-update-conversion)) | |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
373 (setq unread-input-method-events |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
374 (cons last-input-event unread-input-method-events)) |
17052 | 375 (kkc-terminate)))) |
376 | |
377 (defun kkc-katakana () | |
378 "Convert to Katakana." | |
379 (interactive) | |
380 (setcar kkc-current-conversions -1) | |
381 (kkc-update-conversion 'all)) | |
382 | |
383 (defun kkc-hiragana () | |
384 "Convert to hiragana." | |
385 (interactive) | |
386 (setcar kkc-current-conversions 0) | |
387 (kkc-update-conversion)) | |
388 | |
389 (defun kkc-shorter () | |
390 "Make the Kana string to be converted shorter." | |
391 (interactive) | |
392 (if (<= kkc-length-head 1) | |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
393 (kkc-error "Can't be shorter")) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
394 (setq kkc-length-head (1- kkc-length-head)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
395 (if (> kkc-length-converted kkc-length-head) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
396 (let ((len kkc-length-head)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
397 (setq kkc-length-converted 0) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
398 (while (not (kkc-lookup-key len)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
399 (setq len (1- len))))) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
400 (kkc-update-conversion 'all)) |
17052 | 401 |
402 (defun kkc-longer () | |
403 "Make the Kana string to be converted longer." | |
404 (interactive) | |
405 (if (>= kkc-length-head (length kkc-current-key)) | |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
406 (kkc-error "Can't be longer")) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
407 (setq kkc-length-head (1+ kkc-length-head)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
408 ;; This time, try also entries with postfixes. |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
409 (kkc-lookup-key kkc-length-head 'postfix) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
410 (kkc-update-conversion 'all)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
411 |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
412 (defun kkc-shorter-conversion () |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
413 "Make the Kana string to be converted shorter." |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
414 (interactive) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
415 (if (<= kkc-length-converted 1) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
416 (kkc-error "Can't be shorter")) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
417 (let ((len (1- kkc-length-converted))) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
418 (setq kkc-length-converted 0) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
419 (while (not (kkc-lookup-key len)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
420 (setq len (1- len)))) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
421 (kkc-update-conversion 'all)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
422 |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
423 (defun kkc-longer-phrase () |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
424 "Make the current phrase (BUNSETSU) longer without looking up dictionary." |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
425 (interactive) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
426 (if (>= kkc-length-head (length kkc-current-key)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
427 (kkc-error "Can't be longer")) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
428 (setq kkc-length-head (1+ kkc-length-head)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
429 (kkc-update-conversion 'all)) |
17052 | 430 |
431 (defun kkc-next-phrase () | |
432 "Fix the currently converted string and try to convert the remaining string." | |
433 (interactive) | |
434 (if (>= kkc-length-head (length kkc-current-key)) | |
435 (kkc-terminate) | |
436 (setq kkc-length-head (- (length kkc-current-key) kkc-length-head)) | |
437 (goto-char (overlay-end kkc-overlay-head)) | |
438 (while (and (< (point) (overlay-end kkc-overlay-tail)) | |
439 (looking-at "\\CH")) | |
440 (goto-char (match-end 0)) | |
441 (setq kkc-length-head (1- kkc-length-head))) | |
442 (if (= kkc-length-head 0) | |
443 (kkc-terminate) | |
444 (let ((newkey (make-vector kkc-length-head 0)) | |
445 (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
|
446 (len kkc-length-head) |
17052 | 447 (i 0)) |
448 ;; For the moment, (setq kkc-original-kana (concat newkey)) | |
449 ;; doesn't work. | |
450 (setq kkc-original-kana "") | |
451 (while (< i kkc-length-head) | |
452 (aset newkey i (aref kkc-current-key (+ idx i))) | |
453 (setq kkc-original-kana | |
454 (concat kkc-original-kana (char-to-string (aref newkey i)))) | |
455 (setq i (1+ i))) | |
456 (setq kkc-current-key newkey) | |
457 (setq kkc-length-converted 0) | |
18644
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
458 (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
|
459 (< kkc-length-head len))) |
17052 | 460 (> kkc-length-head 1)) |
461 (setq kkc-length-head (1- kkc-length-head))) | |
462 (let ((pos (point)) | |
463 (tail (overlay-end kkc-overlay-tail))) | |
464 (move-overlay kkc-overlay-head pos tail) | |
465 (move-overlay kkc-overlay-tail tail tail)) | |
466 (kkc-update-conversion 'all))))) | |
467 | |
468 ;; We'll show users a list of available conversions in echo area with | |
469 ;; index numbers so that users can select one conversion with the | |
470 ;; number. | |
471 | |
472 ;; Set `kkc-current-conversions-width'. | |
473 (defun kkc-setup-current-conversions-width () | |
474 (let ((convs (cdr kkc-current-conversions)) | |
475 (len (length kkc-current-conversions)) | |
476 (idx 1)) | |
477 (setq kkc-current-conversions-width (make-vector len nil)) | |
478 ;; To tell `kkc-show-conversion-list-update' to generate | |
479 ;; message from scratch. | |
480 (aset kkc-current-conversions-width 0 (vector len -2 nil)) | |
481 ;; Fill the remaining slots. | |
482 (while convs | |
483 (aset kkc-current-conversions-width idx | |
484 (+ (string-width (car convs)) 4)) | |
485 (setq convs (cdr convs) | |
486 idx (1+ idx))))) | |
487 | |
488 (defun kkc-show-conversion-list-or-next-group () | |
489 "Show list of available conversions in echo area with index numbers. | |
490 If the list is already shown, show the next group of conversions, | |
491 and change the current conversion to the first one in the group." | |
492 (interactive) | |
493 (if (< (length kkc-current-conversions) 3) | |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
494 (kkc-error "No alternative")) |
17052 | 495 (if kkc-current-conversions-width |
496 (let ((next-idx (aref (aref kkc-current-conversions-width 0) 1))) | |
497 (if (< next-idx (length kkc-current-conversions-width)) | |
498 (setcar kkc-current-conversions next-idx) | |
499 (setcar kkc-current-conversions 1)) | |
500 (kkc-show-conversion-list-update) | |
501 (kkc-update-conversion)) | |
502 (kkc-setup-current-conversions-width) | |
503 (kkc-show-conversion-list-update))) | |
504 | |
505 (defun kkc-show-conversion-list-or-prev-group () | |
506 "Show list of available conversions in echo area with index numbers. | |
507 If the list is already shown, show the previous group of conversions, | |
508 and change the current conversion to the last one in the group." | |
509 (interactive) | |
510 (if (< (length kkc-current-conversions) 3) | |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
511 (kkc-error "No alternative")) |
17052 | 512 (if kkc-current-conversions-width |
513 (let ((this-idx (aref (aref kkc-current-conversions-width 0) 0))) | |
514 (if (> this-idx 1) | |
515 (setcar kkc-current-conversions (1- this-idx)) | |
516 (setcar kkc-current-conversions | |
517 (1- (length kkc-current-conversions-width)))) | |
518 (kkc-show-conversion-list-update) | |
519 (kkc-update-conversion)) | |
520 (kkc-setup-current-conversions-width) | |
521 (kkc-show-conversion-list-update))) | |
522 | |
523 ;; Update the conversion list shown in echo area. | |
524 (defun kkc-show-conversion-list-update () | |
525 (or kkc-current-conversions-width | |
526 (kkc-setup-current-conversions-width)) | |
527 (let* ((current-idx (car kkc-current-conversions)) | |
528 (first-slot (aref kkc-current-conversions-width 0)) | |
529 (this-idx (aref first-slot 0)) | |
530 (next-idx (aref first-slot 1)) | |
531 (msg (aref first-slot 2))) | |
532 (if (< current-idx this-idx) | |
533 ;; The currently selected conversion is before the list shown | |
534 ;; previously. We must start calculation of message width | |
535 ;; from the start again. | |
536 (setq this-idx 1 msg nil) | |
537 (if (>= current-idx next-idx) | |
538 ;; The currently selected conversion is after the list shown | |
539 ;; previously. We start calculation of message width from | |
540 ;; the conversion next of TO. | |
541 (setq this-idx next-idx msg nil) | |
542 ;; The current conversion is in MSG. Just clear brackets | |
543 ;; around index number. | |
544 (if (string-match "<.>" msg) | |
545 (progn | |
546 (aset msg (match-beginning 0) ?\ ) | |
547 (aset msg (1- (match-end 0)) ?\ ))))) | |
548 (if (not msg) | |
549 (let ((len (length kkc-current-conversions)) | |
550 (max-width (window-width (minibuffer-window))) | |
551 (width-table kkc-current-conversions-width) | |
552 (width 0) | |
553 (idx this-idx) | |
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
554 (max-items (length kkc-show-conversion-list-index-chars)) |
17052 | 555 l) |
30251
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
556 ;; Set THIS-IDX to the first index of conversion to be shown |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
557 ;; in MSG, and reflect it in kkc-current-conversions-width. |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
558 (while (<= idx current-idx) |
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
559 (if (and (<= (+ width (aref width-table idx)) max-width) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
560 (< (- idx this-idx) max-items)) |
17052 | 561 (setq width (+ width (aref width-table idx))) |
562 (setq this-idx idx width (aref width-table idx))) | |
563 (setq idx (1+ idx) | |
564 l (cdr l))) | |
565 (aset first-slot 0 this-idx) | |
30251
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
566 ;; Set NEXT-IDX to the next index of the last conversion |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
567 ;; shown in MSG, and reflect it in |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
568 ;; kkc-current-conversions-width. |
17052 | 569 (while (and (< idx len) |
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
570 (<= (+ width (aref width-table idx)) max-width) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
571 (< (- idx this-idx) max-items)) |
17052 | 572 (setq width (+ width (aref width-table idx)) |
573 idx (1+ idx) | |
574 l (cdr l))) | |
575 (aset first-slot 1 (setq next-idx idx)) | |
576 (setq l (nthcdr this-idx kkc-current-conversions)) | |
30251
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
577 (setq msg (format " %c %s" |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
578 (aref kkc-show-conversion-list-index-chars 0) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
579 (car l)) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
580 idx (1+ this-idx) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
581 l (cdr l)) |
17052 | 582 (while (< idx next-idx) |
30251
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
583 (setq msg (format "%s %c %s" |
17052 | 584 msg |
585 (aref kkc-show-conversion-list-index-chars | |
586 (- idx this-idx)) | |
587 (car l))) | |
588 (setq idx (1+ idx) | |
589 l (cdr l))) | |
590 (aset first-slot 2 msg))) | |
591 (if (> current-idx 0) | |
592 (progn | |
593 ;; Highlight the current conversion by brackets. | |
594 (string-match (format " \\(%c\\) " | |
595 (aref kkc-show-conversion-list-index-chars | |
596 (- current-idx this-idx))) | |
597 msg) | |
598 (aset msg (match-beginning 0) ?<) | |
599 (aset msg (1- (match-end 0)) ?>))) | |
600 (message "%s" msg))) | |
601 | |
602 ;; Update the conversion area with the latest conversion selected. | |
603 ;; ALL if non nil means to update the whole area, else update only | |
604 ;; inside quail-overlay-head. | |
605 | |
606 (defun kkc-update-conversion (&optional all) | |
607 (goto-char (overlay-start kkc-overlay-head)) | |
608 (cond ((= (car kkc-current-conversions) 0) ; Hiragana | |
609 (let ((i 0)) | |
610 (while (< i kkc-length-converted) | |
611 (insert (aref kkc-current-key i)) | |
612 (setq i (1+ i))))) | |
613 ((= (car kkc-current-conversions) -1) ; Katakana | |
614 (let ((i 0)) | |
615 (while (< i kkc-length-converted) | |
616 (insert (japanese-katakana (aref kkc-current-key i))) | |
617 (setq i (1+ i))))) | |
618 (t | |
619 (insert (nth (car kkc-current-conversions) kkc-current-conversions)))) | |
620 (delete-region (point) (overlay-start kkc-overlay-tail)) | |
621 (if all | |
622 (let ((len (length kkc-current-key)) | |
623 (i kkc-length-converted)) | |
624 (delete-region (overlay-start kkc-overlay-tail) | |
625 (overlay-end kkc-overlay-head)) | |
626 (while (< i kkc-length-head) | |
627 (if (= (car kkc-current-conversions) -1) | |
628 (insert (japanese-katakana (aref kkc-current-key i))) | |
629 (insert (aref kkc-current-key i))) | |
630 (setq i (1+ i))) | |
631 (let ((pos (point))) | |
632 (while (< i len) | |
633 (insert (aref kkc-current-key i)) | |
634 (setq i (1+ i))) | |
635 (move-overlay kkc-overlay-head | |
636 (overlay-start kkc-overlay-head) pos) | |
637 (delete-region (point) (overlay-end kkc-overlay-tail))))) | |
638 (goto-char (overlay-end kkc-overlay-tail))) | |
639 | |
640 ;; | |
641 (provide 'kkc) | |
642 | |
643 ;; kkc.el ends here |