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