Mercurial > emacs
annotate lisp/international/kkc.el @ 35329:ae7ded32b733
*** empty log message ***
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Tue, 16 Jan 2001 11:17:38 +0000 |
parents | 6828c3827297 |
children | b82a6fbaae16 |
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 |
31165
6c51a4e8bf88
Remove SKK from Keywords. Require ja-dic-utl instead of skkdic-utl.
Kenichi Handa <handa@m17n.org>
parents:
30256
diff
changeset
|
6 ;; Keywords: mule, multilingual, Japanese |
17052 | 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 | |
31165
6c51a4e8bf88
Remove SKK from Keywords. Require ja-dic-utl instead of skkdic-utl.
Kenichi Handa <handa@m17n.org>
parents:
30256
diff
changeset
|
36 (require 'ja-dic-utl) |
17052 | 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 | |
31165
6c51a4e8bf88
Remove SKK from Keywords. Require ja-dic-utl instead of skkdic-utl.
Kenichi Handa <handa@m17n.org>
parents:
30256
diff
changeset
|
166 ;; Lookup Japanese dictionary to set list of conversions in |
17052 | 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 |
30256
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
215 (defvar kkc-after-update-conversion-functions nil |
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
216 "Functions to run after a conversion is selected in `japanese' input method. |
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
217 With this input method, a user can select a proper conversion from |
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
218 candidate list. Each time he changes the selection, functions in this |
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
219 list are called with two arguments; starting and ending buffer |
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
220 positions that contains the current selection.") |
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
221 |
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
222 ;;;###autoload |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
223 (defun kkc-region (from to) |
17052 | 224 "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
|
225 Users can select a desirable conversion interactively. |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
226 When called from a program, expects two arguments, |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
227 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
|
228 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
|
229 and the return value is the length of the conversion." |
17052 | 230 (interactive "r") |
231 (setq kkc-original-kana (buffer-substring from to)) | |
232 (goto-char from) | |
233 | |
234 ;; Setup overlays. | |
235 (if (overlayp kkc-overlay-head) | |
236 (move-overlay kkc-overlay-head from to) | |
237 (setq kkc-overlay-head (make-overlay from to nil nil t)) | |
238 (overlay-put kkc-overlay-head 'face 'highlight)) | |
239 (if (overlayp kkc-overlay-tail) | |
240 (move-overlay kkc-overlay-tail to to) | |
241 (setq kkc-overlay-tail (make-overlay to to nil nil t)) | |
242 (overlay-put kkc-overlay-tail 'face 'underline)) | |
243 | |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
244 (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
|
245 (setq kkc-length-head (length kkc-current-key)) |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
246 (setq kkc-length-converted 0) |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
247 |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
248 (unwind-protect |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
249 ;; 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
|
250 (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
|
251 (input-method-function nil) |
29146
ded7fa3de6db
(kkc-region): Don't change modified-p of
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
252 (modified-p (buffer-modified-p)) |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
253 (first t)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
254 (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
|
255 (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
|
256 first nil)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
257 (goto-char to) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
258 (kkc-update-conversion 'all) |
30251
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
259 (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
|
260 (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
|
261 (>= (length kkc-current-conversions) 3)) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
262 (kkc-show-conversion-list-or-next-group)) |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
263 |
23196 | 264 ;; 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
|
265 (force-mode-line-update) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
266 (setq kkc-converting t) |
31218
6828c3827297
(kkc-region): Hide "... loaded" message.
Kenichi Handa <handa@m17n.org>
parents:
31165
diff
changeset
|
267 ;; Hide "... loaded" message. |
6828c3827297
(kkc-region): Hide "... loaded" message.
Kenichi Handa <handa@m17n.org>
parents:
31165
diff
changeset
|
268 (message nil) |
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
269 (while kkc-converting |
29146
ded7fa3de6db
(kkc-region): Don't change modified-p of
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
270 (set-buffer-modified-p modified-p) |
22919
95d147bbdce0
(kkc-region): Don't bind echo-keystrokes.
Kenichi Handa <handa@m17n.org>
parents:
22888
diff
changeset
|
271 (let* ((overriding-terminal-local-map kkc-keymap) |
23032 | 272 (help-char nil) |
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
273 (keyseq (read-key-sequence nil)) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
274 (cmd (lookup-key kkc-keymap keyseq))) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
275 (if (commandp cmd) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
276 (condition-case err |
30251
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
277 (progn |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
278 (cond ((eq cmd 'kkc-next) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
279 (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
|
280 kkc-prev-count 0)) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
281 ((eq cmd 'kkc-prev) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
282 (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
|
283 kkc-next-count 0)) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
284 (t |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
285 (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
|
286 (call-interactively cmd)) |
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
287 (kkc-error (message "%s" (cdr err)) (beep))) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
288 ;; KEYSEQ is not defined in KKC keymap. |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
289 ;; Let's put the event back. |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
290 (setq unread-input-method-events |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
291 (append (string-to-list keyseq) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
292 unread-input-method-events)) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
293 (kkc-terminate)))) |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
294 |
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
295 (force-mode-line-update) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
296 (goto-char (overlay-end kkc-overlay-tail)) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
297 (- (overlay-start kkc-overlay-head) from)) |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
298 (delete-overlay kkc-overlay-head) |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
299 (delete-overlay kkc-overlay-tail))) |
17052 | 300 |
301 (defun kkc-terminate () | |
302 "Exit from KKC mode by fixing the current conversion." | |
303 (interactive) | |
22794
9ace35333789
(kkc-region): Handled the case that
Kenichi Handa <handa@m17n.org>
parents:
22779
diff
changeset
|
304 (goto-char (overlay-end kkc-overlay-tail)) |
9ace35333789
(kkc-region): Handled the case that
Kenichi Handa <handa@m17n.org>
parents:
22779
diff
changeset
|
305 (move-overlay kkc-overlay-head (point) (point)) |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
306 (setq kkc-converting nil)) |
17052 | 307 |
308 (defun kkc-cancel () | |
309 "Exit from KKC mode by canceling any conversions." | |
310 (interactive) | |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
311 (goto-char (overlay-start kkc-overlay-head)) |
17052 | 312 (delete-region (overlay-start kkc-overlay-head) |
313 (overlay-end kkc-overlay-tail)) | |
314 (insert kkc-original-kana) | |
22794
9ace35333789
(kkc-region): Handled the case that
Kenichi Handa <handa@m17n.org>
parents:
22779
diff
changeset
|
315 (setq kkc-converting nil)) |
17052 | 316 |
317 (defun kkc-first-char-only () | |
318 "Select only the first character currently converted." | |
319 (interactive) | |
320 (goto-char (overlay-start kkc-overlay-head)) | |
321 (forward-char 1) | |
322 (delete-region (point) (overlay-end kkc-overlay-tail)) | |
323 (kkc-terminate)) | |
324 | |
325 (defun kkc-next () | |
326 "Select the next candidate of conversion." | |
327 (interactive) | |
328 (let ((idx (1+ (car kkc-current-conversions)))) | |
329 (if (< idx 0) | |
330 (setq idx 1)) | |
331 (if (>= idx (length kkc-current-conversions)) | |
332 (setq idx 0)) | |
333 (setcar kkc-current-conversions idx) | |
334 (if (> idx 1) | |
335 (progn | |
336 (set-nested-alist kkc-current-key kkc-current-conversions | |
337 kkc-lookup-cache kkc-length-converted) | |
338 (setq kkc-init-file-flag 'kkc-lookup-cache))) | |
339 (if (or kkc-current-conversions-width | |
340 (>= kkc-next-count kkc-show-conversion-list-count)) | |
341 (kkc-show-conversion-list-update)) | |
342 (kkc-update-conversion))) | |
343 | |
344 (defun kkc-prev () | |
345 "Select the previous candidate of conversion." | |
346 (interactive) | |
347 (let ((idx (1- (car kkc-current-conversions)))) | |
348 (if (< idx 0) | |
349 (setq idx (1- (length kkc-current-conversions)))) | |
350 (setcar kkc-current-conversions idx) | |
351 (if (> idx 1) | |
352 (progn | |
353 (set-nested-alist kkc-current-key kkc-current-conversions | |
354 kkc-lookup-cache kkc-length-converted) | |
355 (setq kkc-init-file-flag 'kkc-lookup-cache))) | |
356 (if (or kkc-current-conversions-width | |
357 (>= kkc-prev-count kkc-show-conversion-list-count)) | |
358 (kkc-show-conversion-list-update)) | |
359 (kkc-update-conversion))) | |
360 | |
361 (defun kkc-select-from-list () | |
362 "Select one candidate from the list currently shown in echo area." | |
363 (interactive) | |
364 (let (idx) | |
365 (if kkc-current-conversions-width | |
366 (let ((len (length kkc-show-conversion-list-index-chars)) | |
367 (maxlen (- (aref (aref kkc-current-conversions-width 0) 1) | |
368 (aref (aref kkc-current-conversions-width 0) 0))) | |
369 (i 0)) | |
370 (if (> len maxlen) | |
371 (setq len maxlen)) | |
372 (while (< i len) | |
373 (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
|
374 last-input-event) |
17052 | 375 (setq idx i i len) |
376 (setq i (1+ i)))))) | |
377 (if idx | |
378 (progn | |
379 (setcar kkc-current-conversions | |
380 (+ (aref (aref kkc-current-conversions-width 0) 0) idx)) | |
381 (kkc-show-conversion-list-update) | |
382 (kkc-update-conversion)) | |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
383 (setq unread-input-method-events |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
384 (cons last-input-event unread-input-method-events)) |
17052 | 385 (kkc-terminate)))) |
386 | |
387 (defun kkc-katakana () | |
388 "Convert to Katakana." | |
389 (interactive) | |
390 (setcar kkc-current-conversions -1) | |
391 (kkc-update-conversion 'all)) | |
392 | |
393 (defun kkc-hiragana () | |
394 "Convert to hiragana." | |
395 (interactive) | |
396 (setcar kkc-current-conversions 0) | |
397 (kkc-update-conversion)) | |
398 | |
399 (defun kkc-shorter () | |
400 "Make the Kana string to be converted shorter." | |
401 (interactive) | |
402 (if (<= kkc-length-head 1) | |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
403 (kkc-error "Can't be shorter")) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
404 (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
|
405 (if (> kkc-length-converted kkc-length-head) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
406 (let ((len kkc-length-head)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
407 (setq kkc-length-converted 0) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
408 (while (not (kkc-lookup-key len)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
409 (setq len (1- len))))) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
410 (kkc-update-conversion 'all)) |
17052 | 411 |
412 (defun kkc-longer () | |
413 "Make the Kana string to be converted longer." | |
414 (interactive) | |
415 (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
|
416 (kkc-error "Can't be longer")) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
417 (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
|
418 ;; This time, try also entries with postfixes. |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
419 (kkc-lookup-key kkc-length-head 'postfix) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
420 (kkc-update-conversion 'all)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
421 |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
422 (defun kkc-shorter-conversion () |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
423 "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
|
424 (interactive) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
425 (if (<= kkc-length-converted 1) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
426 (kkc-error "Can't be shorter")) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
427 (let ((len (1- kkc-length-converted))) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
428 (setq kkc-length-converted 0) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
429 (while (not (kkc-lookup-key len)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
430 (setq len (1- len)))) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
431 (kkc-update-conversion 'all)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
432 |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
433 (defun kkc-longer-phrase () |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
434 "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
|
435 (interactive) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
436 (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
|
437 (kkc-error "Can't be longer")) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
438 (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
|
439 (kkc-update-conversion 'all)) |
17052 | 440 |
441 (defun kkc-next-phrase () | |
442 "Fix the currently converted string and try to convert the remaining string." | |
443 (interactive) | |
444 (if (>= kkc-length-head (length kkc-current-key)) | |
445 (kkc-terminate) | |
446 (setq kkc-length-head (- (length kkc-current-key) kkc-length-head)) | |
447 (goto-char (overlay-end kkc-overlay-head)) | |
448 (while (and (< (point) (overlay-end kkc-overlay-tail)) | |
449 (looking-at "\\CH")) | |
450 (goto-char (match-end 0)) | |
451 (setq kkc-length-head (1- kkc-length-head))) | |
452 (if (= kkc-length-head 0) | |
453 (kkc-terminate) | |
454 (let ((newkey (make-vector kkc-length-head 0)) | |
455 (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
|
456 (len kkc-length-head) |
17052 | 457 (i 0)) |
458 ;; For the moment, (setq kkc-original-kana (concat newkey)) | |
459 ;; doesn't work. | |
460 (setq kkc-original-kana "") | |
461 (while (< i kkc-length-head) | |
462 (aset newkey i (aref kkc-current-key (+ idx i))) | |
463 (setq kkc-original-kana | |
464 (concat kkc-original-kana (char-to-string (aref newkey i)))) | |
465 (setq i (1+ i))) | |
466 (setq kkc-current-key newkey) | |
467 (setq kkc-length-converted 0) | |
18644
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
468 (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
|
469 (< kkc-length-head len))) |
17052 | 470 (> kkc-length-head 1)) |
471 (setq kkc-length-head (1- kkc-length-head))) | |
472 (let ((pos (point)) | |
473 (tail (overlay-end kkc-overlay-tail))) | |
474 (move-overlay kkc-overlay-head pos tail) | |
475 (move-overlay kkc-overlay-tail tail tail)) | |
476 (kkc-update-conversion 'all))))) | |
477 | |
478 ;; We'll show users a list of available conversions in echo area with | |
479 ;; index numbers so that users can select one conversion with the | |
480 ;; number. | |
481 | |
482 ;; Set `kkc-current-conversions-width'. | |
483 (defun kkc-setup-current-conversions-width () | |
484 (let ((convs (cdr kkc-current-conversions)) | |
485 (len (length kkc-current-conversions)) | |
486 (idx 1)) | |
487 (setq kkc-current-conversions-width (make-vector len nil)) | |
488 ;; To tell `kkc-show-conversion-list-update' to generate | |
489 ;; message from scratch. | |
490 (aset kkc-current-conversions-width 0 (vector len -2 nil)) | |
491 ;; Fill the remaining slots. | |
492 (while convs | |
493 (aset kkc-current-conversions-width idx | |
494 (+ (string-width (car convs)) 4)) | |
495 (setq convs (cdr convs) | |
496 idx (1+ idx))))) | |
497 | |
498 (defun kkc-show-conversion-list-or-next-group () | |
499 "Show list of available conversions in echo area with index numbers. | |
500 If the list is already shown, show the next group of conversions, | |
501 and change the current conversion to the first one in the group." | |
502 (interactive) | |
503 (if (< (length kkc-current-conversions) 3) | |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
504 (kkc-error "No alternative")) |
17052 | 505 (if kkc-current-conversions-width |
506 (let ((next-idx (aref (aref kkc-current-conversions-width 0) 1))) | |
507 (if (< next-idx (length kkc-current-conversions-width)) | |
508 (setcar kkc-current-conversions next-idx) | |
509 (setcar kkc-current-conversions 1)) | |
510 (kkc-show-conversion-list-update) | |
511 (kkc-update-conversion)) | |
512 (kkc-setup-current-conversions-width) | |
513 (kkc-show-conversion-list-update))) | |
514 | |
515 (defun kkc-show-conversion-list-or-prev-group () | |
516 "Show list of available conversions in echo area with index numbers. | |
517 If the list is already shown, show the previous group of conversions, | |
518 and change the current conversion to the last one in the group." | |
519 (interactive) | |
520 (if (< (length kkc-current-conversions) 3) | |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
521 (kkc-error "No alternative")) |
17052 | 522 (if kkc-current-conversions-width |
523 (let ((this-idx (aref (aref kkc-current-conversions-width 0) 0))) | |
524 (if (> this-idx 1) | |
525 (setcar kkc-current-conversions (1- this-idx)) | |
526 (setcar kkc-current-conversions | |
527 (1- (length kkc-current-conversions-width)))) | |
528 (kkc-show-conversion-list-update) | |
529 (kkc-update-conversion)) | |
530 (kkc-setup-current-conversions-width) | |
531 (kkc-show-conversion-list-update))) | |
532 | |
533 ;; Update the conversion list shown in echo area. | |
534 (defun kkc-show-conversion-list-update () | |
535 (or kkc-current-conversions-width | |
536 (kkc-setup-current-conversions-width)) | |
537 (let* ((current-idx (car kkc-current-conversions)) | |
538 (first-slot (aref kkc-current-conversions-width 0)) | |
539 (this-idx (aref first-slot 0)) | |
540 (next-idx (aref first-slot 1)) | |
541 (msg (aref first-slot 2))) | |
542 (if (< current-idx this-idx) | |
543 ;; The currently selected conversion is before the list shown | |
544 ;; previously. We must start calculation of message width | |
545 ;; from the start again. | |
546 (setq this-idx 1 msg nil) | |
547 (if (>= current-idx next-idx) | |
548 ;; The currently selected conversion is after the list shown | |
549 ;; previously. We start calculation of message width from | |
550 ;; the conversion next of TO. | |
551 (setq this-idx next-idx msg nil) | |
552 ;; The current conversion is in MSG. Just clear brackets | |
553 ;; around index number. | |
554 (if (string-match "<.>" msg) | |
555 (progn | |
556 (aset msg (match-beginning 0) ?\ ) | |
557 (aset msg (1- (match-end 0)) ?\ ))))) | |
558 (if (not msg) | |
559 (let ((len (length kkc-current-conversions)) | |
560 (max-width (window-width (minibuffer-window))) | |
561 (width-table kkc-current-conversions-width) | |
562 (width 0) | |
563 (idx this-idx) | |
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
564 (max-items (length kkc-show-conversion-list-index-chars)) |
17052 | 565 l) |
30251
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
566 ;; 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
|
567 ;; 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
|
568 (while (<= idx current-idx) |
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
569 (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
|
570 (< (- idx this-idx) max-items)) |
17052 | 571 (setq width (+ width (aref width-table idx))) |
572 (setq this-idx idx width (aref width-table idx))) | |
573 (setq idx (1+ idx) | |
574 l (cdr l))) | |
575 (aset first-slot 0 this-idx) | |
30251
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
576 ;; 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
|
577 ;; shown in MSG, and reflect it in |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
578 ;; kkc-current-conversions-width. |
17052 | 579 (while (and (< idx len) |
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
580 (<= (+ width (aref width-table idx)) max-width) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
581 (< (- idx this-idx) max-items)) |
17052 | 582 (setq width (+ width (aref width-table idx)) |
583 idx (1+ idx) | |
584 l (cdr l))) | |
585 (aset first-slot 1 (setq next-idx idx)) | |
586 (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
|
587 (setq msg (format " %c %s" |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
588 (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
|
589 (car l)) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
590 idx (1+ this-idx) |
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
591 l (cdr l)) |
17052 | 592 (while (< idx next-idx) |
30251
9a4962f4ea62
(kkc-show-conversion-list-count): Customize it.
Kenichi Handa <handa@m17n.org>
parents:
29146
diff
changeset
|
593 (setq msg (format "%s %c %s" |
17052 | 594 msg |
595 (aref kkc-show-conversion-list-index-chars | |
596 (- idx this-idx)) | |
597 (car l))) | |
598 (setq idx (1+ idx) | |
599 l (cdr l))) | |
600 (aset first-slot 2 msg))) | |
601 (if (> current-idx 0) | |
602 (progn | |
603 ;; Highlight the current conversion by brackets. | |
604 (string-match (format " \\(%c\\) " | |
605 (aref kkc-show-conversion-list-index-chars | |
606 (- current-idx this-idx))) | |
607 msg) | |
608 (aset msg (match-beginning 0) ?<) | |
609 (aset msg (1- (match-end 0)) ?>))) | |
610 (message "%s" msg))) | |
611 | |
612 ;; Update the conversion area with the latest conversion selected. | |
613 ;; ALL if non nil means to update the whole area, else update only | |
614 ;; inside quail-overlay-head. | |
615 | |
616 (defun kkc-update-conversion (&optional all) | |
617 (goto-char (overlay-start kkc-overlay-head)) | |
618 (cond ((= (car kkc-current-conversions) 0) ; Hiragana | |
619 (let ((i 0)) | |
620 (while (< i kkc-length-converted) | |
621 (insert (aref kkc-current-key i)) | |
622 (setq i (1+ i))))) | |
623 ((= (car kkc-current-conversions) -1) ; Katakana | |
624 (let ((i 0)) | |
625 (while (< i kkc-length-converted) | |
626 (insert (japanese-katakana (aref kkc-current-key i))) | |
627 (setq i (1+ i))))) | |
628 (t | |
629 (insert (nth (car kkc-current-conversions) kkc-current-conversions)))) | |
630 (delete-region (point) (overlay-start kkc-overlay-tail)) | |
631 (if all | |
632 (let ((len (length kkc-current-key)) | |
633 (i kkc-length-converted)) | |
634 (delete-region (overlay-start kkc-overlay-tail) | |
635 (overlay-end kkc-overlay-head)) | |
636 (while (< i kkc-length-head) | |
637 (if (= (car kkc-current-conversions) -1) | |
638 (insert (japanese-katakana (aref kkc-current-key i))) | |
639 (insert (aref kkc-current-key i))) | |
640 (setq i (1+ i))) | |
641 (let ((pos (point))) | |
642 (while (< i len) | |
643 (insert (aref kkc-current-key i)) | |
644 (setq i (1+ i))) | |
645 (move-overlay kkc-overlay-head | |
646 (overlay-start kkc-overlay-head) pos) | |
647 (delete-region (point) (overlay-end kkc-overlay-tail))))) | |
30256
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
648 (unwind-protect |
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
649 (run-hook-with-args 'kkc-after-update-conversion-functions |
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
650 (overlay-start kkc-overlay-head) |
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
651 (overlay-end kkc-overlay-head)) |
e4b4bca5087a
(kkc-after-update-conversion-functions): New variable.
Kenichi Handa <handa@m17n.org>
parents:
30251
diff
changeset
|
652 (goto-char (overlay-end kkc-overlay-tail)))) |
17052 | 653 |
654 ;; | |
655 (provide 'kkc) | |
656 | |
657 ;; kkc.el ends here |