Mercurial > emacs
annotate lisp/international/kkc.el @ 30152:f6270e5282da
(direct_output_forward_char): Give up if currently
displaying a message instead of the minibuffer contents.
(row_equal_p): Add parameter MOUSE_FACE_P. If set,
compare the mouse_face_p flags of both rows.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Tue, 11 Jul 2000 19:57:54 +0000 |
parents | ded7fa3de6db |
children | 9a4962f4ea62 |
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 | |
134 (defvar kkc-show-conversion-list-count 4 | |
135 "Count of successive `kkc-next' or `kkc-prev' to show conversion list.") | |
136 | |
137 ;; 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
|
138 ;; conversion target is [A B C D E F], and the sequence of which |
17052 | 139 ;; conversion is found is [A B C D]: |
140 ;; | |
141 ;; A B C D E F G H I | |
142 ;; kkc-overlay-head (black): |<--------->| | |
143 ;; kkc-overlay-tail (underline): |<------->| | |
144 ;; kkc-length-head: |<--------->| | |
145 ;; kkc-length-converted: |<----->| | |
146 ;; | |
147 (defvar kkc-overlay-head nil) | |
148 (defvar kkc-overlay-tail nil) | |
149 (defvar kkc-length-head nil) | |
150 (defvar kkc-length-converted nil) | |
151 | |
152 ;; Cursor type (`box' or `bar') of the current frame. | |
153 (defvar kkc-cursor-type nil) | |
154 | |
155 ;; Lookup SKK dictionary to set list of conversions in | |
156 ;; kkc-current-conversions for key sequence kkc-current-key of length | |
157 ;; LEN. If no conversion is found in the dictionary, don't change | |
158 ;; kkc-current-conversions and return nil. | |
159 ;; 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
|
160 (defun kkc-lookup-key (len &optional postfix prefer-noun) |
17052 | 161 ;; 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
|
162 (unless kkc-init-file-flag |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
163 (setq kkc-init-file-flag t |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
164 kkc-lookup-cache nil) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
165 (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
|
166 (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
|
167 (condition-case nil |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
168 (load-file kkc-init-file-name) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
169 (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
|
170 (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
|
171 (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
|
172 (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
|
173 kkc-init-file-flag 'kkc-lookup-cache)) |
17052 | 174 (let ((entry (lookup-nested-alist kkc-current-key kkc-lookup-cache len 0 t))) |
175 (if (consp (car entry)) | |
176 (setq kkc-length-converted len | |
177 kkc-current-conversions-width nil | |
178 kkc-current-conversions (car entry)) | |
18644
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
179 (setq entry (skkdic-lookup-key kkc-current-key len postfix prefer-noun)) |
17052 | 180 (if entry |
181 (progn | |
182 (setq kkc-length-converted len | |
183 kkc-current-conversions-width nil | |
184 kkc-current-conversions (cons 1 entry)) | |
185 (if postfix | |
186 ;; Store this conversions in the cache. | |
187 (progn | |
188 (set-nested-alist kkc-current-key kkc-current-conversions | |
189 kkc-lookup-cache kkc-length-converted) | |
190 (setq kkc-init-file-flag 'kkc-lookup-cache))) | |
191 t) | |
192 (if (= len 1) | |
193 (setq kkc-length-converted 1 | |
194 kkc-current-conversions-width nil | |
195 kkc-current-conversions (cons 0 nil))))))) | |
196 | |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
197 (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
|
198 (defun kkc-error (&rest args) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
199 (signal 'kkc-error (apply 'format args))) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
200 |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
201 (defvar kkc-converting nil) |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
202 |
17052 | 203 ;;;###autoload |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
204 (defun kkc-region (from to) |
17052 | 205 "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
|
206 Users can select a desirable conversion interactively. |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
207 When called from a program, expects two arguments, |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
208 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
|
209 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
|
210 and the return value is the length of the conversion." |
17052 | 211 (interactive "r") |
212 (setq kkc-original-kana (buffer-substring from to)) | |
213 (goto-char from) | |
214 | |
215 ;; Setup overlays. | |
216 (if (overlayp kkc-overlay-head) | |
217 (move-overlay kkc-overlay-head from to) | |
218 (setq kkc-overlay-head (make-overlay from to nil nil t)) | |
219 (overlay-put kkc-overlay-head 'face 'highlight)) | |
220 (if (overlayp kkc-overlay-tail) | |
221 (move-overlay kkc-overlay-tail to to) | |
222 (setq kkc-overlay-tail (make-overlay to to nil nil t)) | |
223 (overlay-put kkc-overlay-tail 'face 'underline)) | |
224 | |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
225 (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
|
226 (setq kkc-length-head (length kkc-current-key)) |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
227 (setq kkc-length-converted 0) |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
228 |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
229 (unwind-protect |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
230 ;; 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
|
231 (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
|
232 (input-method-function nil) |
29146
ded7fa3de6db
(kkc-region): Don't change modified-p of
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
233 (modified-p (buffer-modified-p)) |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
234 (first t)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
235 (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
|
236 (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
|
237 first nil)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
238 (goto-char to) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
239 (kkc-update-conversion 'all) |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
240 |
23196 | 241 ;; 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
|
242 (force-mode-line-update) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
243 (setq kkc-converting t) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
244 (while kkc-converting |
29146
ded7fa3de6db
(kkc-region): Don't change modified-p of
Kenichi Handa <handa@m17n.org>
parents:
23196
diff
changeset
|
245 (set-buffer-modified-p modified-p) |
22919
95d147bbdce0
(kkc-region): Don't bind echo-keystrokes.
Kenichi Handa <handa@m17n.org>
parents:
22888
diff
changeset
|
246 (let* ((overriding-terminal-local-map kkc-keymap) |
23032 | 247 (help-char nil) |
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
248 (keyseq (read-key-sequence nil)) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
249 (cmd (lookup-key kkc-keymap keyseq))) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
250 (if (commandp cmd) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
251 (condition-case err |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
252 (call-interactively cmd) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
253 (kkc-error (message "%s" (cdr err)) (beep))) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
254 ;; KEYSEQ is not defined in KKC keymap. |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
255 ;; Let's put the event back. |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
256 (setq unread-input-method-events |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
257 (append (string-to-list keyseq) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
258 unread-input-method-events)) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
259 (kkc-terminate)))) |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
260 |
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
261 (force-mode-line-update) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
262 (goto-char (overlay-end kkc-overlay-tail)) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
263 (- (overlay-start kkc-overlay-head) from)) |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
264 (delete-overlay kkc-overlay-head) |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
265 (delete-overlay kkc-overlay-tail))) |
17052 | 266 |
267 (defun kkc-terminate () | |
268 "Exit from KKC mode by fixing the current conversion." | |
269 (interactive) | |
22794
9ace35333789
(kkc-region): Handled the case that
Kenichi Handa <handa@m17n.org>
parents:
22779
diff
changeset
|
270 (goto-char (overlay-end kkc-overlay-tail)) |
9ace35333789
(kkc-region): Handled the case that
Kenichi Handa <handa@m17n.org>
parents:
22779
diff
changeset
|
271 (move-overlay kkc-overlay-head (point) (point)) |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
272 (setq kkc-converting nil)) |
17052 | 273 |
274 (defun kkc-cancel () | |
275 "Exit from KKC mode by canceling any conversions." | |
276 (interactive) | |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
277 (goto-char (overlay-start kkc-overlay-head)) |
17052 | 278 (delete-region (overlay-start kkc-overlay-head) |
279 (overlay-end kkc-overlay-tail)) | |
280 (insert kkc-original-kana) | |
22794
9ace35333789
(kkc-region): Handled the case that
Kenichi Handa <handa@m17n.org>
parents:
22779
diff
changeset
|
281 (setq kkc-converting nil)) |
17052 | 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) | |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
352 last-input-event) |
17052 | 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)) | |
22766
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
361 (setq unread-input-method-events |
a83818674920
(kkc-show-conversion-list-index-chars):
Kenichi Handa <handa@m17n.org>
parents:
20638
diff
changeset
|
362 (cons last-input-event unread-input-method-events)) |
17052 | 363 (kkc-terminate)))) |
364 | |
365 (defun kkc-katakana () | |
366 "Convert to Katakana." | |
367 (interactive) | |
368 (setcar kkc-current-conversions -1) | |
369 (kkc-update-conversion 'all)) | |
370 | |
371 (defun kkc-hiragana () | |
372 "Convert to hiragana." | |
373 (interactive) | |
374 (setcar kkc-current-conversions 0) | |
375 (kkc-update-conversion)) | |
376 | |
377 (defun kkc-shorter () | |
378 "Make the Kana string to be converted shorter." | |
379 (interactive) | |
380 (if (<= kkc-length-head 1) | |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
381 (kkc-error "Can't be shorter")) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
382 (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
|
383 (if (> kkc-length-converted kkc-length-head) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
384 (let ((len kkc-length-head)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
385 (setq kkc-length-converted 0) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
386 (while (not (kkc-lookup-key len)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
387 (setq len (1- len))))) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
388 (kkc-update-conversion 'all)) |
17052 | 389 |
390 (defun kkc-longer () | |
391 "Make the Kana string to be converted longer." | |
392 (interactive) | |
393 (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
|
394 (kkc-error "Can't be longer")) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
395 (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
|
396 ;; This time, try also entries with postfixes. |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
397 (kkc-lookup-key kkc-length-head 'postfix) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
398 (kkc-update-conversion 'all)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
399 |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
400 (defun kkc-shorter-conversion () |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
401 "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
|
402 (interactive) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
403 (if (<= kkc-length-converted 1) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
404 (kkc-error "Can't be shorter")) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
405 (let ((len (1- kkc-length-converted))) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
406 (setq kkc-length-converted 0) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
407 (while (not (kkc-lookup-key len)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
408 (setq len (1- len)))) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
409 (kkc-update-conversion 'all)) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
410 |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
411 (defun kkc-longer-phrase () |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
412 "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
|
413 (interactive) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
414 (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
|
415 (kkc-error "Can't be longer")) |
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
416 (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
|
417 (kkc-update-conversion 'all)) |
17052 | 418 |
419 (defun kkc-next-phrase () | |
420 "Fix the currently converted string and try to convert the remaining string." | |
421 (interactive) | |
422 (if (>= kkc-length-head (length kkc-current-key)) | |
423 (kkc-terminate) | |
424 (setq kkc-length-head (- (length kkc-current-key) kkc-length-head)) | |
425 (goto-char (overlay-end kkc-overlay-head)) | |
426 (while (and (< (point) (overlay-end kkc-overlay-tail)) | |
427 (looking-at "\\CH")) | |
428 (goto-char (match-end 0)) | |
429 (setq kkc-length-head (1- kkc-length-head))) | |
430 (if (= kkc-length-head 0) | |
431 (kkc-terminate) | |
432 (let ((newkey (make-vector kkc-length-head 0)) | |
433 (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
|
434 (len kkc-length-head) |
17052 | 435 (i 0)) |
436 ;; For the moment, (setq kkc-original-kana (concat newkey)) | |
437 ;; doesn't work. | |
438 (setq kkc-original-kana "") | |
439 (while (< i kkc-length-head) | |
440 (aset newkey i (aref kkc-current-key (+ idx i))) | |
441 (setq kkc-original-kana | |
442 (concat kkc-original-kana (char-to-string (aref newkey i)))) | |
443 (setq i (1+ i))) | |
444 (setq kkc-current-key newkey) | |
445 (setq kkc-length-converted 0) | |
18644
69c91eee7ba1
(kkc-region): Call skkdic-lookup-key with
Kenichi Handa <handa@m17n.org>
parents:
18377
diff
changeset
|
446 (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
|
447 (< kkc-length-head len))) |
17052 | 448 (> kkc-length-head 1)) |
449 (setq kkc-length-head (1- kkc-length-head))) | |
450 (let ((pos (point)) | |
451 (tail (overlay-end kkc-overlay-tail))) | |
452 (move-overlay kkc-overlay-head pos tail) | |
453 (move-overlay kkc-overlay-tail tail tail)) | |
454 (kkc-update-conversion 'all))))) | |
455 | |
456 ;; We'll show users a list of available conversions in echo area with | |
457 ;; index numbers so that users can select one conversion with the | |
458 ;; number. | |
459 | |
460 ;; Set `kkc-current-conversions-width'. | |
461 (defun kkc-setup-current-conversions-width () | |
462 (let ((convs (cdr kkc-current-conversions)) | |
463 (len (length kkc-current-conversions)) | |
464 (idx 1)) | |
465 (setq kkc-current-conversions-width (make-vector len nil)) | |
466 ;; To tell `kkc-show-conversion-list-update' to generate | |
467 ;; message from scratch. | |
468 (aset kkc-current-conversions-width 0 (vector len -2 nil)) | |
469 ;; Fill the remaining slots. | |
470 (while convs | |
471 (aset kkc-current-conversions-width idx | |
472 (+ (string-width (car convs)) 4)) | |
473 (setq convs (cdr convs) | |
474 idx (1+ idx))))) | |
475 | |
476 (defun kkc-show-conversion-list-or-next-group () | |
477 "Show list of available conversions in echo area with index numbers. | |
478 If the list is already shown, show the next group of conversions, | |
479 and change the current conversion to the first one in the group." | |
480 (interactive) | |
481 (if (< (length kkc-current-conversions) 3) | |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
482 (kkc-error "No alternative")) |
17052 | 483 (if kkc-current-conversions-width |
484 (let ((next-idx (aref (aref kkc-current-conversions-width 0) 1))) | |
485 (if (< next-idx (length kkc-current-conversions-width)) | |
486 (setcar kkc-current-conversions next-idx) | |
487 (setcar kkc-current-conversions 1)) | |
488 (kkc-show-conversion-list-update) | |
489 (kkc-update-conversion)) | |
490 (kkc-setup-current-conversions-width) | |
491 (kkc-show-conversion-list-update))) | |
492 | |
493 (defun kkc-show-conversion-list-or-prev-group () | |
494 "Show list of available conversions in echo area with index numbers. | |
495 If the list is already shown, show the previous group of conversions, | |
496 and change the current conversion to the last one in the group." | |
497 (interactive) | |
498 (if (< (length kkc-current-conversions) 3) | |
22888
5bfe86125303
(kkc-lookup-cache): Initialize it to nil.
Kenichi Handa <handa@m17n.org>
parents:
22816
diff
changeset
|
499 (kkc-error "No alternative")) |
17052 | 500 (if kkc-current-conversions-width |
501 (let ((this-idx (aref (aref kkc-current-conversions-width 0) 0))) | |
502 (if (> this-idx 1) | |
503 (setcar kkc-current-conversions (1- this-idx)) | |
504 (setcar kkc-current-conversions | |
505 (1- (length kkc-current-conversions-width)))) | |
506 (kkc-show-conversion-list-update) | |
507 (kkc-update-conversion)) | |
508 (kkc-setup-current-conversions-width) | |
509 (kkc-show-conversion-list-update))) | |
510 | |
511 ;; Update the conversion list shown in echo area. | |
512 (defun kkc-show-conversion-list-update () | |
513 (or kkc-current-conversions-width | |
514 (kkc-setup-current-conversions-width)) | |
515 (let* ((current-idx (car kkc-current-conversions)) | |
516 (first-slot (aref kkc-current-conversions-width 0)) | |
517 (this-idx (aref first-slot 0)) | |
518 (next-idx (aref first-slot 1)) | |
519 (msg (aref first-slot 2))) | |
520 (if (< current-idx this-idx) | |
521 ;; The currently selected conversion is before the list shown | |
522 ;; previously. We must start calculation of message width | |
523 ;; from the start again. | |
524 (setq this-idx 1 msg nil) | |
525 (if (>= current-idx next-idx) | |
526 ;; The currently selected conversion is after the list shown | |
527 ;; previously. We start calculation of message width from | |
528 ;; the conversion next of TO. | |
529 (setq this-idx next-idx msg nil) | |
530 ;; The current conversion is in MSG. Just clear brackets | |
531 ;; around index number. | |
532 (if (string-match "<.>" msg) | |
533 (progn | |
534 (aset msg (match-beginning 0) ?\ ) | |
535 (aset msg (1- (match-end 0)) ?\ ))))) | |
536 (if (not msg) | |
537 (let ((len (length kkc-current-conversions)) | |
538 (max-width (window-width (minibuffer-window))) | |
539 (width-table kkc-current-conversions-width) | |
540 (width 0) | |
541 (idx this-idx) | |
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
542 (max-items (length kkc-show-conversion-list-index-chars)) |
17052 | 543 l) |
544 (while (< idx current-idx) | |
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
545 (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
|
546 (< (- idx this-idx) max-items)) |
17052 | 547 (setq width (+ width (aref width-table idx))) |
548 (setq this-idx idx width (aref width-table idx))) | |
549 (setq idx (1+ idx) | |
550 l (cdr l))) | |
551 (aset first-slot 0 this-idx) | |
552 (while (and (< idx len) | |
22816
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
553 (<= (+ width (aref width-table idx)) max-width) |
8f9d4edebbdd
(kkc-region): Unwind-protect the conversion
Kenichi Handa <handa@m17n.org>
parents:
22794
diff
changeset
|
554 (< (- idx this-idx) max-items)) |
17052 | 555 (setq width (+ width (aref width-table idx)) |
556 idx (1+ idx) | |
557 l (cdr l))) | |
558 (aset first-slot 1 (setq next-idx idx)) | |
559 (setq l (nthcdr this-idx kkc-current-conversions)) | |
560 (setq msg "") | |
561 (setq idx this-idx) | |
562 (while (< idx next-idx) | |
563 (setq msg (format "%s %c %s " | |
564 msg | |
565 (aref kkc-show-conversion-list-index-chars | |
566 (- idx this-idx)) | |
567 (car l))) | |
568 (setq idx (1+ idx) | |
569 l (cdr l))) | |
570 (aset first-slot 2 msg))) | |
571 (if (> current-idx 0) | |
572 (progn | |
573 ;; Highlight the current conversion by brackets. | |
574 (string-match (format " \\(%c\\) " | |
575 (aref kkc-show-conversion-list-index-chars | |
576 (- current-idx this-idx))) | |
577 msg) | |
578 (aset msg (match-beginning 0) ?<) | |
579 (aset msg (1- (match-end 0)) ?>))) | |
580 (message "%s" msg))) | |
581 | |
582 ;; Update the conversion area with the latest conversion selected. | |
583 ;; ALL if non nil means to update the whole area, else update only | |
584 ;; inside quail-overlay-head. | |
585 | |
586 (defun kkc-update-conversion (&optional all) | |
587 (goto-char (overlay-start kkc-overlay-head)) | |
588 (cond ((= (car kkc-current-conversions) 0) ; Hiragana | |
589 (let ((i 0)) | |
590 (while (< i kkc-length-converted) | |
591 (insert (aref kkc-current-key i)) | |
592 (setq i (1+ i))))) | |
593 ((= (car kkc-current-conversions) -1) ; Katakana | |
594 (let ((i 0)) | |
595 (while (< i kkc-length-converted) | |
596 (insert (japanese-katakana (aref kkc-current-key i))) | |
597 (setq i (1+ i))))) | |
598 (t | |
599 (insert (nth (car kkc-current-conversions) kkc-current-conversions)))) | |
600 (delete-region (point) (overlay-start kkc-overlay-tail)) | |
601 (if all | |
602 (let ((len (length kkc-current-key)) | |
603 (i kkc-length-converted)) | |
604 (delete-region (overlay-start kkc-overlay-tail) | |
605 (overlay-end kkc-overlay-head)) | |
606 (while (< i kkc-length-head) | |
607 (if (= (car kkc-current-conversions) -1) | |
608 (insert (japanese-katakana (aref kkc-current-key i))) | |
609 (insert (aref kkc-current-key i))) | |
610 (setq i (1+ i))) | |
611 (let ((pos (point))) | |
612 (while (< i len) | |
613 (insert (aref kkc-current-key i)) | |
614 (setq i (1+ i))) | |
615 (move-overlay kkc-overlay-head | |
616 (overlay-start kkc-overlay-head) pos) | |
617 (delete-region (point) (overlay-end kkc-overlay-tail))))) | |
618 (goto-char (overlay-end kkc-overlay-tail))) | |
619 | |
620 ;; | |
621 (provide 'kkc) | |
622 | |
623 ;; kkc.el ends here |