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